diff options
-rw-r--r-- | libbb/xreadlink.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index ead30e499..a4e402b84 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 *link = xmalloc_readlink(path); | ||
152 | if (link) { | ||
153 | char *cwd; | ||
154 | if (link[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(link); | ||
163 | free(link); | ||
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, link); | ||
175 | free(cwd); | ||
176 | free(link); | ||
177 | return buf; | ||
178 | } | ||
150 | } | 179 | } |
151 | } | 180 | } |
152 | 181 | ||