aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2019-11-25 18:46:45 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-06-26 11:40:51 +0100
commitd57fbe48390a49a1bb780e2d63533b378ded6831 (patch)
tree772e456bc022467b5dfb48bc5b9847b086bbea9d
parent7709d9e9a1dd5f2397c0715317e377506e8a3fcd (diff)
downloadpseudo-d57fbe48390a49a1bb780e2d63533b378ded6831.tar.gz
pseudo-d57fbe48390a49a1bb780e2d63533b378ded6831.tar.bz2
pseudo-d57fbe48390a49a1bb780e2d63533b378ded6831.zip
realpath.c: Remove trailing slashes
Linux system's realpath() remove trailing slashes, but pseudo's doesn't, need make them identical. E.g., the following code (rel.c) prints '/tmp' with system's realpath, but pseudo's realpath prints '/tmp/': #include <stdio.h> #include <limits.h> #include <stdlib.h> int main() { char out[PATH_MAX]; printf("%s\n", realpath("/tmp/", out)); return 0; } $ bitbake base-passwd -cdevshell # For pseudo env $ gcc rel.c $ ./a.out /tmp/ (but should be /tmp) This patch fixes the problem. Upstream-Status: Submitted [https://lists.yoctoproject.org/g/poky/message/11879] Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--ports/unix/guts/realpath.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ports/unix/guts/realpath.c b/ports/unix/guts/realpath.c
index 085d2cb..8d8118b 100644
--- a/ports/unix/guts/realpath.c
+++ b/ports/unix/guts/realpath.c
@@ -14,7 +14,14 @@
errno = ENAMETOOLONG;
return NULL;
}
- if ((len = strlen(rname)) >= pseudo_sys_path_max()) {
+ len = strlen(rname);
+ char *ep = rname + len - 1;
+ while (ep > rname && *ep == '/') {
+ --len;
+ *(ep--) = '\0';
+ }
+
+ if (len >= pseudo_sys_path_max()) {
errno = ENAMETOOLONG;
return NULL;
}