20 |
#include <config.h> |
#include <config.h> |
21 |
#include "error.h" |
#include "error.h" |
22 |
#include "filename.h" |
#include "filename.h" |
23 |
|
#include <stdio.h> |
24 |
#include <stdlib.h> |
#include <stdlib.h> |
25 |
#include <ctype.h> |
#include <ctype.h> |
26 |
#include <errno.h> |
#include <errno.h> |
29 |
#include "settings.h" |
#include "settings.h" |
30 |
#include "str.h" |
#include "str.h" |
31 |
#include "version.h" |
#include "version.h" |
32 |
|
#include "xreadlink.h" |
33 |
|
|
34 |
|
#include "gettext.h" |
35 |
|
#define _(msgid) gettext (msgid) |
36 |
|
|
37 |
#include "debug-print.h" |
#include "debug-print.h" |
38 |
|
|
43 |
#if HAVE_UNISTD_H |
#if HAVE_UNISTD_H |
44 |
#include <unistd.h> |
#include <unistd.h> |
45 |
#endif |
#endif |
46 |
#include "stat.h" |
#include <sys/stat.h> |
47 |
|
#include "stat-macros.h" |
48 |
#endif |
#endif |
49 |
|
|
50 |
#ifdef __WIN32__ |
#ifdef __WIN32__ |
625 |
#endif |
#endif |
626 |
} |
} |
627 |
|
|
628 |
#ifdef unix |
/* Returns the symbolic link value for FILENAME as a dynamically |
629 |
/* Stolen from libc.info but heavily modified, this is a wrapper |
allocated buffer, or a null pointer on failure. */ |
|
around readlink() that allows for arbitrary filename length. */ |
|
|
char * |
|
|
fn_readlink (const char *filename) |
|
|
{ |
|
|
int size = 128; |
|
|
|
|
|
for (;;) |
|
|
{ |
|
|
char *buffer = xmalloc (size); |
|
|
int nchars = readlink (filename, buffer, size); |
|
|
if (nchars == -1) |
|
|
{ |
|
|
free (buffer); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
if (nchars < size - 1) |
|
|
{ |
|
|
buffer[nchars] = 0; |
|
|
return buffer; |
|
|
} |
|
|
free (buffer); |
|
|
size *= 2; |
|
|
} |
|
|
} |
|
|
#else /* Not UNIX. */ |
|
630 |
char * |
char * |
631 |
fn_readlink (const char *filename) |
fn_readlink (const char *filename) |
632 |
{ |
{ |
633 |
return NULL; |
return xreadlink (filename, 32); |
634 |
} |
} |
|
#endif /* Not UNIX. */ |
|
635 |
|
|
636 |
/* Environment variables. */ |
/* Environment variables. */ |
637 |
|
|