aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-05-24 17:29:14 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-05-24 17:31:00 +0200
commit747162109fb1c891baf6aafa1ca0410bd08d04a4 (patch)
tree7215b1a5b94212e207b9c3d7c1426e65c2ce0553 /libbb
parent3f91e662f21083d4febf74fa89ccc50e406cbf6c (diff)
downloadbusybox-w32-747162109fb1c891baf6aafa1ca0410bd08d04a4.tar.gz
busybox-w32-747162109fb1c891baf6aafa1ca0410bd08d04a4.tar.bz2
busybox-w32-747162109fb1c891baf6aafa1ca0410bd08d04a4.zip
realpath,readlink -f: coreutils compat, closes 11021
function old new delta xmalloc_realpath_coreutils - 121 +121 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xreadlink.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 9b62bcc43..6315033bb 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
126char* 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}