comparison src/realpath.c @ 819:6504113e7c2d

[xemacs-hg @ 2002-04-25 18:03:23 by andyp] sync up windows branch from 21.4
author andyp
date Thu, 25 Apr 2002 18:04:24 +0000
parents 943eaba38521
children e7ee5f8bde58
comparison
equal deleted inserted replaced
818:accc481aef34 819:6504113e7c2d
32 #include "lisp.h" 32 #include "lisp.h"
33 33
34 #include "sysfile.h" 34 #include "sysfile.h"
35 35
36 #define MAX_READLINKS 32 36 #define MAX_READLINKS 32
37
38 #if defined (HAVE_SYS_PARAM_H) && !defined (WIN32_NATIVE)
39 #include <sys/param.h>
40 #endif
41
42 #ifdef WIN32_NATIVE
43 #include <direct.h>
44 #endif
45
46 #include <sys/stat.h> /* for S_IFLNK */
47
48 #if defined(WIN32_NATIVE) || defined(CYGWIN)
49 #define WIN32_FILENAMES
50 #endif
37 51
38 /* First char after start of absolute filename. */ 52 /* First char after start of absolute filename. */
39 #define ABS_START(name) (name + ABS_LENGTH (name)) 53 #define ABS_START(name) (name + ABS_LENGTH (name))
40 54
41 #if defined (WIN32_NATIVE) 55 #if defined (WIN32_NATIVE)
43 # define ABS_LENGTH(name) (mswindows_abs_start (name)) 57 # define ABS_LENGTH(name) (mswindows_abs_start (name))
44 static int mswindows_abs_start (const Intbyte *name); 58 static int mswindows_abs_start (const Intbyte *name);
45 # define readlink_and_correct_case mswindows_readlink_and_correct_case 59 # define readlink_and_correct_case mswindows_readlink_and_correct_case
46 #else 60 #else
47 # ifdef CYGWIN 61 # ifdef CYGWIN
48 # define ABS_LENGTH(name) (IS_DIRECTORY_SEP (*name) ? \ 62 # ifdef WIN32_FILENAMES
49 (IS_DIRECTORY_SEP (name[1]) ? 2 : 1) : 0) 63 # define ABS_LENGTH(name) (mswindows_abs_start (name))
64 static int mswindows_abs_start (const Intbyte * name);
65 # else
66 # define ABS_LENGTH(name) (IS_DIRECTORY_SEP (*name) ? \
67 (IS_DIRECTORY_SEP (name[1]) ? 2 : 1) : 0)
68 # endif
50 # define readlink_and_correct_case cygwin_readlink_and_correct_case 69 # define readlink_and_correct_case cygwin_readlink_and_correct_case
51 # else 70 # else
52 # define ABS_LENGTH(name) (IS_DIRECTORY_SEP (*name) ? 1 : 0) 71 # define ABS_LENGTH(name) (IS_DIRECTORY_SEP (*name) ? 1 : 0)
53 # define readlink_and_correct_case qxe_readlink 72 # define readlink_and_correct_case qxe_readlink
54 # endif /* CYGWIN */ 73 # endif /* CYGWIN */
152 } 171 }
153 return n; 172 return n;
154 } 173 }
155 #endif /* CYGWIN */ 174 #endif /* CYGWIN */
156 175
157 #ifdef WIN32_NATIVE 176 #ifdef WIN32_FILENAMES
158 #ifndef ELOOP 177 #ifndef ELOOP
159 #define ELOOP 10062 /* = WSAELOOP in winsock.h */ 178 #define ELOOP 10062 /* = WSAELOOP in winsock.h */
160 #endif 179 #endif
161 /* Length of start of absolute filename. */ 180 /* Length of start of absolute filename. */
162 static int 181 static int
191 /* Make a copy of the source path since we may need to modify it. */ 210 /* Make a copy of the source path since we may need to modify it. */
192 qxestrcpy (copy_path, path); 211 qxestrcpy (copy_path, path);
193 path = copy_path; 212 path = copy_path;
194 max_path = copy_path + PATH_MAX - 2; 213 max_path = copy_path + PATH_MAX - 2;
195 214
196 #ifdef WIN32_NATIVE 215 if (0)
216 ;
217 #ifdef WIN32_FILENAMES
197 /* Check for c:/... or //server/... */ 218 /* Check for c:/... or //server/... */
198 if (abslen == 2 || abslen == 3) 219 else if (abslen == 2 || abslen == 3)
199 { 220 {
200 qxestrncpy (new_path, path, abslen); 221 qxestrncpy (new_path, path, abslen);
201 /* Make sure drive letter is lowercased. */ 222 /* Make sure drive letter is lowercased. */
202 if (abslen == 3) 223 if (abslen == 3)
203 *new_path = tolower (*new_path); 224 *new_path = tolower (*new_path);
204 new_path += abslen; 225 new_path += abslen;
205 path += abslen; 226 path += abslen;
206 } 227 }
228 #endif
229 #ifdef WIN32_NATIVE
207 /* No drive letter, but a beginning slash? Prepend drive letter. */ 230 /* No drive letter, but a beginning slash? Prepend drive letter. */
208 else if (abslen == 1) 231 else if (abslen == 1)
209 { 232 {
210 get_initial_directory (new_path, PATH_MAX - 1); 233 get_initial_directory (new_path, PATH_MAX - 1);
211 new_path += 3; 234 new_path += 3;
212 path++; 235 path++;
213 } 236 }
214 /* Just a path name, prepend the current directory */ 237 /* Just a path name, prepend the current directory */
215 else 238 else if (1)
216 { 239 {
217 get_initial_directory (new_path, PATH_MAX - 1); 240 get_initial_directory (new_path, PATH_MAX - 1);
218 new_path += qxestrlen (new_path); 241 new_path += qxestrlen (new_path);
219 if (!IS_DIRECTORY_SEP (new_path[-1])) 242 if (!IS_DIRECTORY_SEP (new_path[-1]))
220 *new_path++ = DIRECTORY_SEP; 243 *new_path++ = DIRECTORY_SEP;
221 } 244 }
222 #else 245 #else
223 /* If it's a relative pathname use get_initial_directory for starters. */ 246 /* If it's a relative pathname use get_initial_directory for starters. */
224 if (abslen == 0) 247 else if (abslen == 0)
225 { 248 {
226 get_initial_directory (new_path, PATH_MAX - 1); 249 get_initial_directory (new_path, PATH_MAX - 1);
227 new_path += qxestrlen (new_path); 250 new_path += qxestrlen (new_path);
228 if (!IS_DIRECTORY_SEP (new_path[-1])) 251 if (!IS_DIRECTORY_SEP (new_path[-1]))
229 *new_path++ = DIRECTORY_SEP; 252 *new_path++ = DIRECTORY_SEP;