diff options
author | Ron Yorston <rmy@pobox.com> | 2018-07-25 10:41:42 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-07-25 10:41:42 +0100 |
commit | 59873514f17cefd6ba3997dad5779f75433fd4e6 (patch) | |
tree | 1c9d0a3450ed95f0b820285b9f9fc217c902e652 /libbb/xreadlink.c | |
parent | 779fd5745ac11bf752f5f4b977a274a39c192f90 (diff) | |
parent | 81de30de05beebabfa72f2a01ec4f33e9a1923e3 (diff) | |
download | busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.tar.gz busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.tar.bz2 busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.zip |
Merge branch 'busybox'
Diffstat (limited to 'libbb/xreadlink.c')
-rw-r--r-- | libbb/xreadlink.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index b3118b433..9ae70de99 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c | |||
@@ -122,3 +122,33 @@ char* FAST_FUNC xmalloc_realpath(const char *path) | |||
122 | return xstrdup(realpath(path, buf)); | 122 | return xstrdup(realpath(path, buf)); |
123 | #endif | 123 | #endif |
124 | } | 124 | } |
125 | |||
126 | char* FAST_FUNC xmalloc_realpath_coreutils(const char *path) | ||
127 | { | ||
128 | char *buf; | ||
129 | |||
130 | errno = 0; | ||
131 | buf = xmalloc_realpath(path); | ||
132 | /* | ||
133 | * There is one case when "readlink -f" and | ||
134 | * "realpath" from coreutils succeed, | ||
135 | * even though file does not exist, such as: | ||
136 | * /tmp/file_does_not_exist | ||
137 | * (the directory must exist). | ||
138 | */ | ||
139 | if (!buf && errno == ENOENT) { | ||
140 | char *last_slash = strrchr(path, '/'); | ||
141 | if (last_slash) { | ||
142 | *last_slash++ = '\0'; | ||
143 | buf = xmalloc_realpath(path); | ||
144 | if (buf) { | ||
145 | unsigned len = strlen(buf); | ||
146 | buf = xrealloc(buf, len + strlen(last_slash) + 2); | ||
147 | buf[len++] = '/'; | ||
148 | strcpy(buf + len, last_slash); | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | return buf; | ||
154 | } | ||