svn commit: branches/uClibc_0_9_28/libc/stdlib

andersen at uclibc.org andersen at uclibc.org
Thu Feb 8 18:35:44 UTC 2007


Author: andersen
Date: 2007-02-08 10:35:43 -0800 (Thu, 08 Feb 2007)
New Revision: 17819

Log:
backport fixes from trunk


Modified:
   branches/uClibc_0_9_28/libc/stdlib/realpath.c


Changeset:
Modified: branches/uClibc_0_9_28/libc/stdlib/realpath.c
===================================================================
--- branches/uClibc_0_9_28/libc/stdlib/realpath.c	2007-02-08 18:25:57 UTC (rev 17818)
+++ branches/uClibc_0_9_28/libc/stdlib/realpath.c	2007-02-08 18:35:43 UTC (rev 17819)
@@ -1,16 +1,9 @@
 /*
  * realpath.c -- canonicalize pathname by removing symlinks
  * Copyright (C) 1993 Rick Sladkey <jrs at world.std.com>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen at uclibc.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Library Public License for more details.
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -25,6 +18,7 @@
 #include <limits.h>				/* for PATH_MAX */
 #include <sys/param.h>			/* for MAXPATHLEN */
 #include <errno.h>
+#include <stdlib.h>
 
 #include <sys/stat.h>			/* for S_IFLNK */
 
@@ -58,6 +52,14 @@
 	int readlinks = 0;
 	int n;
 
+	if (path == NULL) {
+		__set_errno(EINVAL);
+		return NULL;
+	}
+	if (*path == '\0') {
+		__set_errno(ENOENT);
+		return NULL;
+	}
 	/* Make a copy of the source path since we may need to modify it. */
 	if (strlen(path) >= PATH_MAX - 2) {
 		__set_errno(ENAMETOOLONG);
@@ -66,15 +68,10 @@
 	strcpy(copy_path, path);
 	path = copy_path;
 	max_path = copy_path + PATH_MAX - 2;
-	/* If it's a relative pathname use getwd for starters. */
+	/* If it's a relative pathname use getcwd for starters. */
 	if (*path != '/') {
 		/* Ohoo... */
-#define HAVE_GETCWD
-#ifdef HAVE_GETCWD
 		getcwd(new_path, PATH_MAX - 1);
-#else
-		getwd(new_path);
-#endif
 		new_path += strlen(new_path);
 		if (new_path[-1] != '/')
 			*new_path++ = '/';
@@ -130,7 +127,7 @@
 				/* Make sure it's null terminated. */
 				*new_path = '\0';
 				strcpy(resolved_path, got_path);
-				return NULL;
+				return resolved_path;
 			}
 		} else {
 			/* Note: readlink doesn't add the null byte. */




More information about the uClibc-cvs mailing list