realpath.c: Remove trailing slashes
PATCH 1/1 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 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("out %s\n", realpath("/tmp////", out));
return 0;
}This patch fixes the problem.
--- ports/unix/guts/realpath.c | 7 +++++++ 1 file changed, 7 insertions(+)
ports/unix/guts/realpath.c +7 -0
@@ -25,6 +25,13 @@ rc =strdup (rname); } +if (rc) { +char *ep = rc; + ep +=strlen (rc) -1 ; +while (ep > rc && ep[0 ] =='/' ) + *(ep--) ='\0' ; + } +/* return rc; * } */
Signature · 1 line
2.7.4
A message that is not in the archive (sent off-list or not yet received): 20191126110922.630c44e7@seebsdell
Hi Peter,
Quoted 6 lines · Seebs
Quoted 3 lines · On Tue, 26 Nov 2019 10:35:45 +0800 Robert Yang <[email protected]>…
Linux system's
realpath()remove trailing slashes, but pseudo's doesn't, need make them identical.
Quoted 8 lines
Quoted 2 lines
E.g., the following code prints '/tmp' with system's realpath, but pseudo's realpath prints '
/tmp/':I'm a bit concerned about this mostly because I think we have existing code closely related to this already, somewhere in pseudo, that had to do with path canonicalization. It might be that we're supposed to keep the slash in *other* contexts, but need to drop it for realpath *specifically*, though?
Long time no see, the slash is still be kept for other parts, this patch only affects realpath(), kernel's Makefile relies on realpath removes the trailing slash, which checks whether build dir = source dir, it checks whether "$(realpath build/) = $(realpath build)", this should be true, but unfortunately, it is false when pseudo is enabled, which leads to a very puzzled problem. We need make pseudo's syscalls identical to system's.
// Robert
Quoted 3 lines
-s