Mercurial > emacs
comparison src/sysdep.c @ 90227:10fe5fadaf89
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-81
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 532-541)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 112-115)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 11 Sep 2005 22:21:01 +0000 |
parents | 2d92f5c9d6ae 6de0727c40ae |
children | fa0da9b57058 |
comparison
equal
deleted
inserted
replaced
90226:df78f2fb8f6a | 90227:10fe5fadaf89 |
---|---|
45 extern void srandom P_ ((unsigned int)); | 45 extern void srandom P_ ((unsigned int)); |
46 #endif | 46 #endif |
47 #endif | 47 #endif |
48 | 48 |
49 #include "blockinput.h" | 49 #include "blockinput.h" |
50 #undef NULL | |
51 | 50 |
52 #ifdef MAC_OS8 | 51 #ifdef MAC_OS8 |
53 /* It is essential to include stdlib.h so that this file picks up | 52 /* It is essential to include stdlib.h so that this file picks up |
54 the correct definitions of rand, srand, and RAND_MAX. | 53 the correct definitions of rand, srand, and RAND_MAX. |
55 Otherwise random numbers will not work correctly. */ | 54 Otherwise random numbers will not work correctly. */ |
185 #include <direct.h> | 184 #include <direct.h> |
186 /* In process.h which conflicts with the local copy. */ | 185 /* In process.h which conflicts with the local copy. */ |
187 #define _P_WAIT 0 | 186 #define _P_WAIT 0 |
188 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...); | 187 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...); |
189 int _CRTAPI1 _getpid (void); | 188 int _CRTAPI1 _getpid (void); |
189 extern char *getwd (char *); | |
190 #endif | 190 #endif |
191 | 191 |
192 #ifdef NONSYSTEM_DIR_LIBRARY | 192 #ifdef NONSYSTEM_DIR_LIBRARY |
193 #include "ndir.h" | 193 #include "ndir.h" |
194 #endif /* NONSYSTEM_DIR_LIBRARY */ | 194 #endif /* NONSYSTEM_DIR_LIBRARY */ |
255 #endif | 255 #endif |
256 | 256 |
257 /* Temporary used by `sigblock' when defined in terms of signprocmask. */ | 257 /* Temporary used by `sigblock' when defined in terms of signprocmask. */ |
258 | 258 |
259 SIGMASKTYPE sigprocmask_set; | 259 SIGMASKTYPE sigprocmask_set; |
260 | |
261 | |
262 #ifndef HAVE_GET_CURRENT_DIR_NAME | |
263 | |
264 /* Return the current working directory. Returns NULL on errors. | |
265 Any other returned value must be freed with free. This is used | |
266 only when get_current_dir_name is not defined on the system. */ | |
267 char* | |
268 get_current_dir_name () | |
269 { | |
270 char *buf; | |
271 char *pwd; | |
272 struct stat dotstat, pwdstat; | |
273 /* If PWD is accurate, use it instead of calling getwd. PWD is | |
274 sometimes a nicer name, and using it may avoid a fatal error if a | |
275 parent directory is searchable but not readable. */ | |
276 if ((pwd = getenv ("PWD")) != 0 | |
277 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) | |
278 && stat (pwd, &pwdstat) == 0 | |
279 && stat (".", &dotstat) == 0 | |
280 && dotstat.st_ino == pwdstat.st_ino | |
281 && dotstat.st_dev == pwdstat.st_dev | |
282 #ifdef MAXPATHLEN | |
283 && strlen (pwd) < MAXPATHLEN | |
284 #endif | |
285 ) | |
286 { | |
287 buf = (char *) malloc (strlen (pwd) + 1); | |
288 if (!buf) | |
289 return NULL; | |
290 strcpy (buf, pwd); | |
291 } | |
292 #ifdef HAVE_GETCWD | |
293 else | |
294 { | |
295 size_t buf_size = 1024; | |
296 buf = (char *) malloc (buf_size); | |
297 if (!buf) | |
298 return NULL; | |
299 for (;;) | |
300 { | |
301 if (getcwd (buf, buf_size) == buf) | |
302 break; | |
303 if (errno != ERANGE) | |
304 { | |
305 int tmp_errno = errno; | |
306 free (buf); | |
307 errno = tmp_errno; | |
308 return NULL; | |
309 } | |
310 buf_size *= 2; | |
311 buf = (char *) realloc (buf, buf_size); | |
312 if (!buf) | |
313 return NULL; | |
314 } | |
315 } | |
316 #else | |
317 else | |
318 { | |
319 /* We need MAXPATHLEN here. */ | |
320 buf = (char *) malloc (MAXPATHLEN + 1); | |
321 if (!buf) | |
322 return NULL; | |
323 if (getwd (buf) == NULL) | |
324 { | |
325 int tmp_errno = errno; | |
326 free (buf); | |
327 errno = tmp_errno; | |
328 return NULL; | |
329 } | |
330 } | |
331 #endif | |
332 return buf; | |
333 } | |
334 #endif | |
260 | 335 |
261 | 336 |
262 /* Specify a different file descriptor for further input operations. */ | 337 /* Specify a different file descriptor for further input operations. */ |
263 | 338 |
264 void | 339 void |