Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/xreadlink.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/xreadlink.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * xreadlink.c - safe implementation of readlink. … … 4 5 */ 5 6 6 #include <stdio.h>7 #include "libbb.h" 7 8 8 9 /* … … 10 11 * yourself. You have been warned. 11 12 */ 12 13 #include <unistd.h> 14 #include "libbb.h" 15 16 char *xreadlink(const char *path) 13 char *xmalloc_readlink(const char *path) 17 14 { 18 15 enum { GROWBY = 80 }; /* how large we will grow strings by */ … … 23 20 do { 24 21 buf = xrealloc(buf, bufsize += GROWBY); 25 readsize = readlink(path, buf, bufsize); /* 1st try */22 readsize = readlink(path, buf, bufsize); 26 23 if (readsize == -1) { 27 bb_perror_msg("%s", path);28 24 free(buf); 29 25 return NULL; 30 26 } 31 } 32 while (bufsize < readsize + 1); 27 } while (bufsize < readsize + 1); 33 28 34 29 buf[readsize] = '\0'; … … 36 31 return buf; 37 32 } 33 34 char *xmalloc_readlink_or_warn(const char *path) 35 { 36 char *buf = xmalloc_readlink(path); 37 if (!buf) { 38 /* EINVAL => "file: Invalid argument" => puzzled user */ 39 bb_error_msg("%s: cannot read link (not a symlink?)", path); 40 } 41 return buf; 42 } 43 44 /* UNUSED */ 45 #if 0 46 char *xmalloc_realpath(const char *path) 47 { 48 #if defined(__GLIBC__) && !defined(__UCLIBC__) 49 /* glibc provides a non-standard extension */ 50 return realpath(path, NULL); 51 #else 52 char buf[PATH_MAX+1]; 53 54 /* on error returns NULL (xstrdup(NULL) ==NULL) */ 55 return xstrdup(realpath(path, buf)); 56 #endif 57 } 58 #endif
Note:
See TracChangeset
for help on using the changeset viewer.