aboutsummaryrefslogtreecommitdiff
path: root/libbb/xreadlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/xreadlink.c')
-rw-r--r--libbb/xreadlink.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 024ee9047..e6cf90310 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -156,7 +156,11 @@ char* FAST_FUNC xmalloc_realpath_coreutils(char *path)
156 * $ realpath symlink 156 * $ realpath symlink
157 * /usr/bin/qwe 157 * /usr/bin/qwe
158 */ 158 */
159#if ENABLE_PLATFORM_MINGW32
160 if (is_relative_path(target)) {
161#else
159 if (target[0] != '/') { 162 if (target[0] != '/') {
163#endif
160 /* 164 /*
161 * $ ln -s target_does_not_exist symlink 165 * $ ln -s target_does_not_exist symlink
162 * $ readlink -f symlink 166 * $ readlink -f symlink
@@ -175,6 +179,35 @@ char* FAST_FUNC xmalloc_realpath_coreutils(char *path)
175 return buf; 179 return buf;
176 } 180 }
177 181
182#if ENABLE_PLATFORM_MINGW32
183 /* ignore leading and trailing slashes */
184 /* but keep leading slashes of UNC path */
185 if (!is_unc_path(path)) {
186 while (is_dir_sep(path[0]) && is_dir_sep(path[1]))
187 ++path;
188 }
189 i = strlen(path) - 1;
190 while (i > 0 && is_dir_sep(path[i]))
191 i--;
192 c = path[i + 1];
193 path[i + 1] = '\0';
194
195 last_slash = get_last_slash(path);
196 if (last_slash == path + root_len(path))
197 buf = xstrdup(path);
198 else if (last_slash) {
199 char c2 = *last_slash;
200 *last_slash = '\0';
201 buf = xmalloc_realpath(path);
202 *last_slash++ = c2;
203 if (buf) {
204 unsigned len = strlen(buf);
205 buf = xrealloc(buf, len + strlen(last_slash) + 2);
206 buf[len++] = c2;
207 strcpy(buf + len, last_slash);
208 }
209 }
210#else
178 /* ignore leading and trailing slashes */ 211 /* ignore leading and trailing slashes */
179 while (path[0] == '/' && path[1] == '/') 212 while (path[0] == '/' && path[1] == '/')
180 ++path; 213 ++path;
@@ -198,6 +231,7 @@ char* FAST_FUNC xmalloc_realpath_coreutils(char *path)
198 strcpy(buf + len, last_slash); 231 strcpy(buf + len, last_slash);
199 } 232 }
200 } 233 }
234#endif
201 path[i + 1] = c; 235 path[i + 1] = c;
202 } 236 }
203 237