Mercurial > hg > xemacs-beta
comparison src/realpath.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
26 | 26 |
27 #include <sys/types.h> | 27 #include <sys/types.h> |
28 #include <stdio.h> | 28 #include <stdio.h> |
29 #include <string.h> | 29 #include <string.h> |
30 #include <errno.h> | 30 #include <errno.h> |
31 #include <limits.h> | |
32 | |
31 #ifdef HAVE_UNISTD_H | 33 #ifdef HAVE_UNISTD_H |
32 #include <unistd.h> | 34 #include <unistd.h> |
33 #endif | 35 #endif |
34 #ifdef _POSIX_VERSION | 36 |
35 #include <limits.h> /* for PATH_MAX */ | 37 #if defined (HAVE_SYS_PARAM_H) |
36 #else | 38 #include <sys/param.h> |
37 #include <sys/param.h> /* for MAXPATHLEN */ | 39 #endif |
38 #endif | 40 |
39 | 41 #ifdef WIN32_NATIVE |
40 #ifdef WINDOWSNT | |
41 #include <direct.h> | 42 #include <direct.h> |
42 #endif | 43 #endif |
43 | 44 |
44 #include <sys/stat.h> /* for S_IFLNK */ | 45 #include <sys/stat.h> /* for S_IFLNK */ |
45 | 46 |
72 char link_path[PATH_MAX]; | 73 char link_path[PATH_MAX]; |
73 int n; | 74 int n; |
74 #endif | 75 #endif |
75 | 76 |
76 /* Make a copy of the source path since we may need to modify it. */ | 77 /* Make a copy of the source path since we may need to modify it. */ |
77 strcpy(copy_path, path); | 78 strcpy (copy_path, path); |
78 path = copy_path; | 79 path = copy_path; |
79 max_path = copy_path + PATH_MAX - 2; | 80 max_path = copy_path + PATH_MAX - 2; |
80 #ifdef WINDOWSNT | 81 #ifdef WIN32_NATIVE |
81 /* | 82 /* |
82 ** In NT we have two different cases: (1) the path name begins | 83 ** In NT we have two different cases: (1) the path name begins |
83 ** with a drive letter, e.g., "C:"; and (2) the path name begins | 84 ** with a drive letter, e.g., "C:"; and (2) the path name begins |
84 ** with just a slash, which roots to the current drive. In the | 85 ** with just a slash, which roots to the current drive. In the |
85 ** first case we are going to leave things alone, in the second | 86 ** first case we are going to leave things alone, in the second |
151 { | 152 { |
152 path++; | 153 path++; |
153 continue; | 154 continue; |
154 } | 155 } |
155 | 156 |
156 if (path[1] == '.') | 157 /* Handle ".." */ |
157 { | 158 if (path[1] == '.' && |
158 if (path[2] == '\0' || path[2] == '/') | 159 (path[2] == '\0' || path[2] == '/')) |
159 { | 160 { |
160 path += 2; | 161 path += 2; |
161 | 162 |
162 /* Ignore ".." at root. */ | 163 /* Ignore ".." at root. */ |
163 if (new_path == resolved_path + 1) | 164 if (new_path == resolved_path + 1) |
164 continue; | 165 continue; |
165 | 166 |
166 /* Handle ".." by backing up. */ | 167 /* Handle ".." by backing up. */ |
167 while ((--new_path)[-1] != '/') | 168 while ((--new_path)[-1] != '/') |
168 ; | 169 ; |
169 continue; | 170 continue; |
170 } | |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 /* Safely copy the next pathname component. */ | 174 /* Safely copy the next pathname component. */ |
175 while (*path != '\0' && *path != '/') | 175 while (*path != '\0' && *path != '/') |
183 } | 183 } |
184 | 184 |
185 #ifdef S_IFLNK | 185 #ifdef S_IFLNK |
186 /* See if latest pathname component is a symlink. */ | 186 /* See if latest pathname component is a symlink. */ |
187 *new_path = '\0'; | 187 *new_path = '\0'; |
188 n = readlink(resolved_path, link_path, PATH_MAX - 1); | 188 n = readlink (resolved_path, link_path, PATH_MAX - 1); |
189 | 189 |
190 if (n < 0) | 190 if (n < 0) |
191 { | 191 { |
192 /* EINVAL means the file exists but isn't a symlink. */ | 192 /* EINVAL means the file exists but isn't a symlink. */ |
193 if (errno != EINVAL) | 193 if (errno != EINVAL) |