X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Frealpath.c;h=08d32d7bf23f96af6d74dca2e304cc5d36812570;hb=4f29597e4f3696a59bb08ffece07183c1568c4a5;hp=3af9c9327f0cf1adc0219de0697ee198a72aaea5;hpb=6883ee56ec887c2c48abe5b06b5e66aa74031910;p=chise%2Fxemacs-chise.git- diff --git a/src/realpath.c b/src/realpath.c index 3af9c93..08d32d7 100644 --- a/src/realpath.c +++ b/src/realpath.c @@ -22,24 +22,20 @@ Boston, MA 02111-1307, USA. */ /* Synched up with: Not in FSF. */ -#ifdef HAVE_CONFIG_H #include -#endif #include -#if defined(HAVE_UNISTD_H) || defined(STDC_HEADERS) -#include -#endif #include #include -#ifdef _POSIX_VERSION -#include /* for PATH_MAX */ -#else -#include /* for MAXPATHLEN */ -#endif #include -#ifndef STDC_HEADERS -extern int errno; +#include + +#ifdef HAVE_UNISTD_H +#include +#endif + +#if defined (HAVE_SYS_PARAM_H) +#include #endif #ifdef WINDOWSNT @@ -48,50 +44,49 @@ extern int errno; #include /* for S_IFLNK */ -#ifndef PATH_MAX -#ifdef _POSIX_VERSION -#define PATH_MAX _POSIX_PATH_MAX -#else -#ifdef MAXPATHLEN -#define PATH_MAX MAXPATHLEN -#else -#define PATH_MAX 1024 -#endif +#if !defined (HAVE_GETCWD) && defined (HAVE_GETWD) +#undef getcwd +#define getcwd(buffer, len) getwd (buffer) #endif + +#ifndef PATH_MAX +# if defined (_POSIX_PATH_MAX) +# define PATH_MAX _POSIX_PATH_MAX +# elif defined (MAXPATHLEN) +# define PATH_MAX MAXPATHLEN +# else +# define PATH_MAX 1024 +# endif #endif #define MAX_READLINKS 32 -#ifdef __STDC__ -char *xrealpath(const char *path, char resolved_path []) -#else -char *xrealpath(path, resolved_path) -const char *path; -char resolved_path []; -#endif +char * xrealpath (const char *path, char resolved_path []); +char * +xrealpath (const char *path, char resolved_path []) { char copy_path[PATH_MAX]; char *new_path = resolved_path; char *max_path; - int readlinks = 0; #ifdef S_IFLNK + int readlinks = 0; char link_path[PATH_MAX]; int n; #endif /* Make a copy of the source path since we may need to modify it. */ - strcpy(copy_path, path); + strcpy (copy_path, path); path = copy_path; max_path = copy_path + PATH_MAX - 2; #ifdef WINDOWSNT /* ** In NT we have two different cases: (1) the path name begins ** with a drive letter, e.g., "C:"; and (2) the path name begins - ** with just a slash, which roots to the current drive. In the + ** with just a slash, which roots to the current drive. In the ** first case we are going to leave things alone, in the second ** case we will prepend the drive letter to the given path. ** Note: So far in testing, I'm only seeing case #1, even though - ** I've tried to get the other cases to happen. + ** I've tried to get the other cases to happen. ** August Hill, 31 Aug 1997. ** ** Check for a driver letter...C:/... @@ -109,7 +104,7 @@ char resolved_path []; */ else if (*path == '/') { - getcwd(new_path, PATH_MAX - 1); + getcwd (new_path, PATH_MAX - 1); new_path += 3; path++; } @@ -119,21 +114,17 @@ char resolved_path []; */ else { - getcwd(new_path, PATH_MAX - 1); + getcwd (new_path, PATH_MAX - 1); new_path += strlen(new_path); if (new_path[-1] != '/') *new_path++ = '/'; } #else - /* If it's a relative pathname use getwd for starters. */ + /* If it's a relative pathname use getcwd for starters. */ if (*path != '/') { -#ifdef HAVE_GETCWD - getcwd(new_path, PATH_MAX - 1); -#else - getwd(new_path); -#endif + getcwd (new_path, PATH_MAX - 1); new_path += strlen(new_path); if (new_path[-1] != '/') *new_path++ = '/'; @@ -163,21 +154,20 @@ char resolved_path []; continue; } - if (path[1] == '.') + /* Handle ".." */ + if (path[1] == '.' && + (path[2] == '\0' || path[2] == '/')) { - if (path[2] == '\0' || path[2] == '/') - { - path += 2; - - /* Ignore ".." at root. */ - if (new_path == resolved_path + 1) - continue; - - /* Handle ".." by backing up. */ - while ((--new_path)[-1] != '/') - ; - continue; - } + path += 2; + + /* Ignore ".." at root. */ + if (new_path == resolved_path + 1) + continue; + + /* Handle ".." by backing up. */ + while ((--new_path)[-1] != '/') + ; + continue; } } @@ -195,7 +185,7 @@ char resolved_path []; #ifdef S_IFLNK /* See if latest pathname component is a symlink. */ *new_path = '\0'; - n = readlink(resolved_path, link_path, PATH_MAX - 1); + n = readlink (resolved_path, link_path, PATH_MAX - 1); if (n < 0) {