summaryrefslogtreecommitdiff
path: root/libbb/xreadlink.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-16 18:50:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-16 18:50:56 +0000
commite755e827f7c8ecb21787a4369d7afdeda54d112b (patch)
tree007b1506e69ffcc25bc6ba3b0e6686d806a34264 /libbb/xreadlink.c
parented6ac53104d811ee88c71aff45c7cad666aaee46 (diff)
downloadbusybox-w32-1_7_1.tar.gz
busybox-w32-1_7_1.tar.bz2
busybox-w32-1_7_1.zip
apply post 1.7.0 patches, set version to 1.7.11_7_1
Diffstat (limited to '')
-rw-r--r--libbb/xreadlink.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 18a8b9467..4d87b944d 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -10,8 +10,7 @@
10 * NOTE: This function returns a malloced char* that you will have to free 10 * NOTE: This function returns a malloced char* that you will have to free
11 * yourself. You have been warned. 11 * yourself. You have been warned.
12 */ 12 */
13 13char *xmalloc_readlink(const char *path)
14char *xmalloc_readlink_or_warn(const char *path)
15{ 14{
16 enum { GROWBY = 80 }; /* how large we will grow strings by */ 15 enum { GROWBY = 80 }; /* how large we will grow strings by */
17 16
@@ -20,20 +19,30 @@ char *xmalloc_readlink_or_warn(const char *path)
20 19
21 do { 20 do {
22 buf = xrealloc(buf, bufsize += GROWBY); 21 buf = xrealloc(buf, bufsize += GROWBY);
23 readsize = readlink(path, buf, bufsize); /* 1st try */ 22 readsize = readlink(path, buf, bufsize);
24 if (readsize == -1) { 23 if (readsize == -1) {
25 bb_perror_msg("%s", path);
26 free(buf); 24 free(buf);
27 return NULL; 25 return NULL;
28 } 26 }
29 } 27 } while (bufsize < readsize + 1);
30 while (bufsize < readsize + 1);
31 28
32 buf[readsize] = '\0'; 29 buf[readsize] = '\0';
33 30
34 return buf; 31 return buf;
35} 32}
36 33
34char *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
37char *xmalloc_realpath(const char *path) 46char *xmalloc_realpath(const char *path)
38{ 47{
39#if defined(__GLIBC__) && !defined(__UCLIBC__) 48#if defined(__GLIBC__) && !defined(__UCLIBC__)
@@ -46,3 +55,4 @@ char *xmalloc_realpath(const char *path)
46 return xstrdup(realpath(path, buf)); 55 return xstrdup(realpath(path, buf));
47#endif 56#endif
48} 57}
58#endif