Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-3]: src/lib/libc/gen Pull up revisions 1.37-1.40 (requested by el...
details: https://anonhg.NetBSD.org/src/rev/6c189829077b
branches: netbsd-3
changeset: 576936:6c189829077b
user: riz <riz%NetBSD.org@localhost>
date: Sun Aug 14 22:08:44 2005 +0000
description:
Pull up revisions 1.37-1.40 (requested by elad in ticket #648):
1.37:
Make realpath(3) work correctly.
The current code resolves paths like `/foo/bar/', `/foo/bar/./', and
`/foo/bar/../', even if `bar' is a regular file and not a directory.
Reviewed by cube@.
1.38:
Fixes to previous:
- Don't handle single and multiple slashes differently.
- A symlink to a directory can be appear in the middle of path. Don't
reject it.
1.39:
Don't allow last path element to be nonexistant.
1.40:
Make this compile again (remove unused serrno).
Noted by uwe@.
diffstat:
lib/libc/gen/getcwd.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diffs (50 lines):
diff -r 85c970b42137 -r 6c189829077b lib/libc/gen/getcwd.c
--- a/lib/libc/gen/getcwd.c Sun Aug 14 22:08:43 2005 +0000
+++ b/lib/libc/gen/getcwd.c Sun Aug 14 22:08:44 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getcwd.c,v 1.36 2005/01/30 22:37:32 enami Exp $ */
+/* $NetBSD: getcwd.c,v 1.36.2.1 2005/08/14 22:08:44 riz Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1995
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95";
#else
-__RCSID("$NetBSD: getcwd.c,v 1.36 2005/01/30 22:37:32 enami Exp $");
+__RCSID("$NetBSD: getcwd.c,v 1.36.2.1 2005/08/14 22:08:44 riz Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -69,7 +69,7 @@
realpath(const char *path, char *resolved)
{
struct stat sb;
- int idx = 0, n, nlnk = 0, serrno = errno;
+ int idx = 0, n, nlnk = 0;
const char *q;
char *p, wbuf[2][MAXPATHLEN];
size_t len;
@@ -159,11 +159,6 @@
* target to unresolved path.
*/
if (lstat(resolved, &sb) == -1) {
- /* Allow nonexistent component if this is the last one. */
- if (*q == 0 && errno == ENOENT) {
- errno = serrno;
- return (resolved);
- }
return (NULL);
}
if (S_ISLNK(sb.st_mode)) {
@@ -193,6 +188,10 @@
p = resolved;
goto loop;
}
+ if (*q == '/' && !S_ISDIR(sb.st_mode)) {
+ errno = ENOTDIR;
+ return (NULL);
+ }
/* Advance both resolved and unresolved path. */
p += 1 + q - path;
Home |
Main Index |
Thread Index |
Old Index