1 /* vi: set sw=4 ts=4: */
3 * xreadlink.c - safe implementation of readlink.
4 * Returns a NULL on failure...
10 * NOTE: This function returns a malloced char* that you will have to free
11 * yourself. You have been warned.
14 char *xmalloc_readlink_or_warn(const char *path)
16 enum { GROWBY = 80 }; /* how large we will grow strings by */
19 int bufsize = 0, readsize = 0;
22 buf = xrealloc(buf, bufsize += GROWBY);
23 readsize = readlink(path, buf, bufsize); /* 1st try */
25 bb_perror_msg("%s", path);
30 while (bufsize < readsize + 1);
37 char *xmalloc_realpath(const char *path)
39 #if defined(__GLIBC__) && !defined(__UCLIBC__)
40 /* glibc provides a non-standard extension */
41 return realpath(path, NULL);
45 /* on error returns NULL (xstrdup(NULL) ==NULL) */
46 return xstrdup(realpath(path, buf));