Mercurial > hg > xemacs-beta
comparison src/realpath.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 8626e4521993 |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 Boston, MA 02111-1307, USA. */ | 21 Boston, MA 02111-1307, USA. */ |
22 | 22 |
23 /* Synched up with: Not in FSF. */ | 23 /* Synched up with: Not in FSF. */ |
24 | 24 |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | 25 #include <config.h> |
27 #endif | |
28 | 26 |
29 #include <sys/types.h> | 27 #include <sys/types.h> |
30 #if defined(HAVE_UNISTD_H) || defined(STDC_HEADERS) | |
31 #include <unistd.h> | |
32 #endif | |
33 #include <stdio.h> | 28 #include <stdio.h> |
34 #include <string.h> | 29 #include <string.h> |
30 #include <errno.h> | |
31 #ifdef HAVE_UNISTD_H | |
32 #include <unistd.h> | |
33 #endif | |
35 #ifdef _POSIX_VERSION | 34 #ifdef _POSIX_VERSION |
36 #include <limits.h> /* for PATH_MAX */ | 35 #include <limits.h> /* for PATH_MAX */ |
37 #else | 36 #else |
38 #include <sys/param.h> /* for MAXPATHLEN */ | 37 #include <sys/param.h> /* for MAXPATHLEN */ |
39 #endif | 38 #endif |
40 #include <errno.h> | |
41 #ifndef STDC_HEADERS | |
42 extern int errno; | |
43 #endif | |
44 | 39 |
45 #ifdef WINDOWSNT | 40 #ifdef WINDOWSNT |
46 #include <direct.h> | 41 #include <direct.h> |
47 #endif | 42 #endif |
48 | 43 |
49 #include <sys/stat.h> /* for S_IFLNK */ | 44 #include <sys/stat.h> /* for S_IFLNK */ |
50 | 45 |
46 #if !defined (HAVE_GETCWD) && defined (HAVE_GETWD) | |
47 #undef getcwd | |
48 #define getcwd(buffer, len) getwd (buffer) | |
49 #endif | |
50 | |
51 #ifndef PATH_MAX | 51 #ifndef PATH_MAX |
52 #ifdef _POSIX_VERSION | 52 # if defined (_POSIX_PATH_MAX) |
53 #define PATH_MAX _POSIX_PATH_MAX | 53 # define PATH_MAX _POSIX_PATH_MAX |
54 #else | 54 # elif defined (MAXPATHLEN) |
55 #ifdef MAXPATHLEN | 55 # define PATH_MAX MAXPATHLEN |
56 #define PATH_MAX MAXPATHLEN | 56 # else |
57 #else | 57 # define PATH_MAX 1024 |
58 #define PATH_MAX 1024 | 58 # endif |
59 #endif | |
60 #endif | |
61 #endif | 59 #endif |
62 | 60 |
63 #define MAX_READLINKS 32 | 61 #define MAX_READLINKS 32 |
64 | 62 |
65 #ifdef __STDC__ | 63 char * xrealpath (const char *path, char resolved_path []); |
66 char *xrealpath(const char *path, char resolved_path []) | 64 char * |
67 #else | 65 xrealpath (const char *path, char resolved_path []) |
68 char *xrealpath(path, resolved_path) | |
69 const char *path; | |
70 char resolved_path []; | |
71 #endif | |
72 { | 66 { |
73 char copy_path[PATH_MAX]; | 67 char copy_path[PATH_MAX]; |
74 char *new_path = resolved_path; | 68 char *new_path = resolved_path; |
75 char *max_path; | 69 char *max_path; |
70 #ifdef S_IFLNK | |
76 int readlinks = 0; | 71 int readlinks = 0; |
77 #ifdef S_IFLNK | |
78 char link_path[PATH_MAX]; | 72 char link_path[PATH_MAX]; |
79 int n; | 73 int n; |
80 #endif | 74 #endif |
81 | 75 |
82 /* Make a copy of the source path since we may need to modify it. */ | 76 /* Make a copy of the source path since we may need to modify it. */ |
107 ** No drive letter, but a beginning slash? Prepend the drive | 101 ** No drive letter, but a beginning slash? Prepend the drive |
108 ** letter... | 102 ** letter... |
109 */ | 103 */ |
110 else if (*path == '/') | 104 else if (*path == '/') |
111 { | 105 { |
112 getcwd(new_path, PATH_MAX - 1); | 106 getcwd (new_path, PATH_MAX - 1); |
113 new_path += 3; | 107 new_path += 3; |
114 path++; | 108 path++; |
115 } | 109 } |
116 | 110 |
117 /* | 111 /* |
118 ** Just a path name, prepend the current directory | 112 ** Just a path name, prepend the current directory |
119 */ | 113 */ |
120 else | 114 else |
121 { | 115 { |
122 getcwd(new_path, PATH_MAX - 1); | 116 getcwd (new_path, PATH_MAX - 1); |
123 new_path += strlen(new_path); | 117 new_path += strlen(new_path); |
124 if (new_path[-1] != '/') | 118 if (new_path[-1] != '/') |
125 *new_path++ = '/'; | 119 *new_path++ = '/'; |
126 } | 120 } |
127 | 121 |
128 #else | 122 #else |
129 /* If it's a relative pathname use getwd for starters. */ | 123 /* If it's a relative pathname use getcwd for starters. */ |
130 if (*path != '/') | 124 if (*path != '/') |
131 { | 125 { |
132 #ifdef HAVE_GETCWD | 126 getcwd (new_path, PATH_MAX - 1); |
133 getcwd(new_path, PATH_MAX - 1); | |
134 #else | |
135 getwd(new_path); | |
136 #endif | |
137 new_path += strlen(new_path); | 127 new_path += strlen(new_path); |
138 if (new_path[-1] != '/') | 128 if (new_path[-1] != '/') |
139 *new_path++ = '/'; | 129 *new_path++ = '/'; |
140 } | 130 } |
141 else | 131 else |