comparison src/realpath.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 3ecd8885ac67
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
41 #include <direct.h> 41 #include <direct.h>
42 #endif 42 #endif
43 43
44 #include <sys/stat.h> /* for S_IFLNK */ 44 #include <sys/stat.h> /* for S_IFLNK */
45 45
46 #if !defined (HAVE_GETCWD) && defined (HAVE_GETWD)
47 #undef getcwd
48 #define getcwd(buffer, len) getwd (buffer)
49 #endif
50
46 #ifndef PATH_MAX 51 #ifndef PATH_MAX
47 #ifdef _POSIX_VERSION 52 # if defined (_POSIX_PATH_MAX)
48 #define PATH_MAX _POSIX_PATH_MAX 53 # define PATH_MAX _POSIX_PATH_MAX
49 #else 54 # elif defined (MAXPATHLEN)
50 #ifdef MAXPATHLEN 55 # define PATH_MAX MAXPATHLEN
51 #define PATH_MAX MAXPATHLEN 56 # else
52 #else 57 # define PATH_MAX 1024
53 #define PATH_MAX 1024 58 # endif
54 #endif
55 #endif
56 #endif 59 #endif
57 60
58 #define MAX_READLINKS 32 61 #define MAX_READLINKS 32
59 62
63 char * xrealpath (const char *path, char resolved_path []);
60 char * 64 char *
61 xrealpath (const char *path, char resolved_path []) 65 xrealpath (const char *path, char resolved_path [])
62 { 66 {
63 char copy_path[PATH_MAX]; 67 char copy_path[PATH_MAX];
64 char *new_path = resolved_path; 68 char *new_path = resolved_path;
97 ** No drive letter, but a beginning slash? Prepend the drive 101 ** No drive letter, but a beginning slash? Prepend the drive
98 ** letter... 102 ** letter...
99 */ 103 */
100 else if (*path == '/') 104 else if (*path == '/')
101 { 105 {
102 getcwd(new_path, PATH_MAX - 1); 106 getcwd (new_path, PATH_MAX - 1);
103 new_path += 3; 107 new_path += 3;
104 path++; 108 path++;
105 } 109 }
106 110
107 /* 111 /*
108 ** Just a path name, prepend the current directory 112 ** Just a path name, prepend the current directory
109 */ 113 */
110 else 114 else
111 { 115 {
112 getcwd(new_path, PATH_MAX - 1); 116 getcwd (new_path, PATH_MAX - 1);
113 new_path += strlen(new_path); 117 new_path += strlen(new_path);
114 if (new_path[-1] != '/') 118 if (new_path[-1] != '/')
115 *new_path++ = '/'; 119 *new_path++ = '/';
116 } 120 }
117 121
118 #else 122 #else
119 /* If it's a relative pathname use getwd for starters. */ 123 /* If it's a relative pathname use getcwd for starters. */
120 if (*path != '/') 124 if (*path != '/')
121 { 125 {
122 #ifdef HAVE_GETCWD 126 getcwd (new_path, PATH_MAX - 1);
123 getcwd(new_path, PATH_MAX - 1);
124 #else
125 getwd(new_path);
126 #endif
127 new_path += strlen(new_path); 127 new_path += strlen(new_path);
128 if (new_path[-1] != '/') 128 if (new_path[-1] != '/')
129 *new_path++ = '/'; 129 *new_path++ = '/';
130 } 130 }
131 else 131 else