aboutsummaryrefslogtreecommitdiff
path: root/libbb/xreadlink.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-08-16 09:42:39 +0100
committerRon Yorston <rmy@pobox.com>2019-08-16 09:45:21 +0100
commit517cf74f6265ec4308b790b637b3f9778cbdc6e0 (patch)
treebe9337069b60ca1bb03565d8575bacfc71181003 /libbb/xreadlink.c
parentae65dc37bcc9b1d9cef0b111131c79dc4ba1bf51 (diff)
parentac78f2ac96b3efd6551a08e7dc609efa1fb69481 (diff)
downloadbusybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.gz
busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.bz2
busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/xreadlink.c')
-rw-r--r--libbb/xreadlink.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 9ae70de99..ca53e12d3 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -147,6 +147,35 @@ char* FAST_FUNC xmalloc_realpath_coreutils(const char *path)
147 buf[len++] = '/'; 147 buf[len++] = '/';
148 strcpy(buf + len, last_slash); 148 strcpy(buf + len, last_slash);
149 } 149 }
150 } else {
151 char *target = xmalloc_readlink(path);
152 if (target) {
153 char *cwd;
154 if (target[0] == '/') {
155 /*
156 * $ ln -s /bin/qwe symlink # note: /bin is a link to /usr/bin
157 * $ readlink -f symlink
158 * /usr/bin/qwe/target_does_not_exist
159 * $ realpath symlink
160 * /usr/bin/qwe/target_does_not_exist
161 */
162 buf = xmalloc_realpath_coreutils(target);
163 free(target);
164 return buf;
165 }
166 /*
167 * $ ln -s target_does_not_exist symlink
168 * $ readlink -f symlink
169 * /CURDIR/target_does_not_exist
170 * $ realpath symlink
171 * /CURDIR/target_does_not_exist
172 */
173 cwd = xrealloc_getcwd_or_warn(NULL);
174 buf = concat_path_file(cwd, target);
175 free(cwd);
176 free(target);
177 return buf;
178 }
150 } 179 }
151 } 180 }
152 181