Mercurial > hg > xemacs-beta
comparison src/fileio.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 | 3a7e78e1142d |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
54 #endif /* HPUX_PRE_8_0 */ | 54 #endif /* HPUX_PRE_8_0 */ |
55 #endif /* HPUX */ | 55 #endif /* HPUX */ |
56 | 56 |
57 #ifdef WINDOWSNT | 57 #ifdef WINDOWSNT |
58 #define NOMINMAX 1 | 58 #define NOMINMAX 1 |
59 #include <windows.h> | |
60 #include <direct.h> | 59 #include <direct.h> |
61 #include <fcntl.h> | 60 #include <fcntl.h> |
62 #include <stdlib.h> | 61 #include <stdlib.h> |
63 #endif /* not WINDOWSNT */ | 62 #endif /* not WINDOWSNT */ |
64 | 63 |
238 The string needs to be converted since it may be localized. | 237 The string needs to be converted since it may be localized. |
239 Perhaps this should use strerror-coding-system instead? */ | 238 Perhaps this should use strerror-coding-system instead? */ |
240 Lisp_Object | 239 Lisp_Object |
241 lisp_strerror (int errnum) | 240 lisp_strerror (int errnum) |
242 { | 241 { |
243 return build_ext_string (strerror (errnum), FORMAT_NATIVE); | 242 return build_ext_string (strerror (errnum), Qnative); |
244 } | 243 } |
245 | 244 |
246 static Lisp_Object | 245 static Lisp_Object |
247 close_file_unwind (Lisp_Object fd) | 246 close_file_unwind (Lisp_Object fd) |
248 { | 247 { |
582 */ | 581 */ |
583 | 582 |
584 static int | 583 static int |
585 directory_file_name (CONST char *src, char *dst) | 584 directory_file_name (CONST char *src, char *dst) |
586 { | 585 { |
587 long slen; | 586 long slen = strlen (src); |
588 | |
589 slen = strlen (src); | |
590 /* Process as Unix format: just remove any final slash. | 587 /* Process as Unix format: just remove any final slash. |
591 But leave "/" unchanged; do not change it to "". */ | 588 But leave "/" unchanged; do not change it to "". */ |
592 strcpy (dst, src); | 589 strcpy (dst, src); |
593 #ifdef APOLLO | |
594 /* Handle // as root for apollo's. */ | |
595 if ((slen > 2 && dst[slen - 1] == '/') | |
596 || (slen > 1 && dst[0] != '/' && dst[slen - 1] == '/')) | |
597 dst[slen - 1] = 0; | |
598 #else | |
599 if (slen > 1 | 590 if (slen > 1 |
600 && IS_DIRECTORY_SEP (dst[slen - 1]) | 591 && IS_DIRECTORY_SEP (dst[slen - 1]) |
601 #ifdef WINDOWSNT | 592 #ifdef WINDOWSNT |
602 && !IS_ANY_SEP (dst[slen - 2]) | 593 && !IS_ANY_SEP (dst[slen - 2]) |
603 #endif /* WINDOWSNT */ | 594 #endif /* WINDOWSNT */ |
604 ) | 595 ) |
605 dst[slen - 1] = 0; | 596 dst[slen - 1] = 0; |
606 #endif /* APOLLO */ | |
607 return 1; | 597 return 1; |
608 } | 598 } |
609 | 599 |
610 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /* | 600 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /* |
611 Return the file name of the directory named DIR. | 601 Return the file name of the directory named DIR. |
975 if (nm[0] == '~') /* prefix ~ */ | 965 if (nm[0] == '~') /* prefix ~ */ |
976 { | 966 { |
977 if (IS_DIRECTORY_SEP (nm[1]) | 967 if (IS_DIRECTORY_SEP (nm[1]) |
978 || nm[1] == 0) /* ~ by itself */ | 968 || nm[1] == 0) /* ~ by itself */ |
979 { | 969 { |
980 char * newdir_external = get_home_directory (); | 970 Extbyte *newdir_external = get_home_directory (); |
981 | 971 |
982 if (newdir_external == NULL) | 972 if (newdir_external == NULL) |
983 newdir = (Bufbyte *) ""; | 973 newdir = (Bufbyte *) ""; |
984 else | 974 else |
985 GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA (newdir_external, newdir); | 975 TO_INTERNAL_FORMAT (C_STRING, newdir_external, |
976 C_STRING_ALLOCA, (* ((char **) &newdir)), | |
977 Qfile_name); | |
986 | 978 |
987 nm++; | 979 nm++; |
988 #ifdef WINDOWSNT | 980 #ifdef WINDOWSNT |
989 collapse_newdir = 0; | 981 collapse_newdir = 0; |
990 #endif | 982 #endif |
1299 | 1291 |
1300 { | 1292 { |
1301 char resolved_path[MAXPATHLEN]; | 1293 char resolved_path[MAXPATHLEN]; |
1302 Extbyte *path; | 1294 Extbyte *path; |
1303 Extbyte *p; | 1295 Extbyte *p; |
1304 Extcount elen = XSTRING_LENGTH (expanded_name); | 1296 Extcount elen; |
1305 | 1297 |
1306 GET_STRING_FILENAME_DATA_ALLOCA (expanded_name,path,elen); | 1298 TO_EXTERNAL_FORMAT (LISP_STRING, expanded_name, |
1299 ALLOCA, (path, elen), | |
1300 Qfile_name); | |
1307 p = path; | 1301 p = path; |
1308 if (elen > MAXPATHLEN) | 1302 if (elen > MAXPATHLEN) |
1309 goto toolong; | 1303 goto toolong; |
1310 | 1304 |
1311 /* Try doing it all at once. */ | 1305 /* Try doing it all at once. */ |
1372 goto toolong; | 1366 goto toolong; |
1373 resolved_path[rlen] = '/'; | 1367 resolved_path[rlen] = '/'; |
1374 resolved_path[rlen + 1] = 0; | 1368 resolved_path[rlen + 1] = 0; |
1375 rlen = rlen + 1; | 1369 rlen = rlen + 1; |
1376 } | 1370 } |
1377 return make_ext_string ((Bufbyte *) resolved_path, rlen, FORMAT_BINARY); | 1371 return make_ext_string ((Bufbyte *) resolved_path, rlen, Qbinary); |
1378 } | 1372 } |
1379 | 1373 |
1380 toolong: | 1374 toolong: |
1381 errno = ENAMETOOLONG; | 1375 errno = ENAMETOOLONG; |
1382 goto lose; | 1376 goto lose; |
1423 /* If /~ or // appears, discard everything through first slash. */ | 1417 /* If /~ or // appears, discard everything through first slash. */ |
1424 | 1418 |
1425 for (p = nm; p != endp; p++) | 1419 for (p = nm; p != endp; p++) |
1426 { | 1420 { |
1427 if ((p[0] == '~' | 1421 if ((p[0] == '~' |
1428 #if defined (APOLLO) || defined (WINDOWSNT) || defined (__CYGWIN32__) | 1422 #if defined (WINDOWSNT) || defined (__CYGWIN32__) |
1429 /* // at start of file name is meaningful in Apollo and | 1423 /* // at start of file name is meaningful in WindowsNT systems */ |
1430 WindowsNT systems */ | |
1431 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm) | 1424 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm) |
1432 #else /* not (APOLLO || WINDOWSNT || __CYGWIN32__) */ | 1425 #else /* not (WINDOWSNT || __CYGWIN32__) */ |
1433 || IS_DIRECTORY_SEP (p[0]) | 1426 || IS_DIRECTORY_SEP (p[0]) |
1434 #endif /* not (APOLLO || WINDOWSNT || __CYGWIN32__) */ | 1427 #endif /* not (WINDOWSNT || __CYGWIN32__) */ |
1435 ) | 1428 ) |
1436 && p != nm | 1429 && p != nm |
1437 && (IS_DIRECTORY_SEP (p[-1]))) | 1430 && (IS_DIRECTORY_SEP (p[-1]))) |
1438 { | 1431 { |
1439 nm = p; | 1432 nm = p; |
1555 | 1548 |
1556 /* If /~ or // appears, discard everything through first slash. */ | 1549 /* If /~ or // appears, discard everything through first slash. */ |
1557 | 1550 |
1558 for (p = xnm; p != x; p++) | 1551 for (p = xnm; p != x; p++) |
1559 if ((p[0] == '~' | 1552 if ((p[0] == '~' |
1560 #if defined (APOLLO) || defined (WINDOWSNT) | 1553 #if defined (WINDOWSNT) |
1561 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm) | 1554 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm) |
1562 #else /* not (APOLLO || WINDOWSNT) */ | 1555 #else /* not WINDOWSNT */ |
1563 || IS_DIRECTORY_SEP (p[0]) | 1556 || IS_DIRECTORY_SEP (p[0]) |
1564 #endif /* APOLLO || WINDOWSNT */ | 1557 #endif /* not WINDOWSNT */ |
1565 ) | 1558 ) |
1566 /* don't do p[-1] if that would go off the beginning --jwz */ | 1559 /* don't do p[-1] if that would go off the beginning --jwz */ |
1567 && p != nm && p > xnm && IS_DIRECTORY_SEP (p[-1])) | 1560 && p != nm && p > xnm && IS_DIRECTORY_SEP (p[-1])) |
1568 xnm = p; | 1561 xnm = p; |
1569 #ifdef WINDOWSNT | 1562 #ifdef WINDOWSNT |
2130 Open a network connection to PATH using LOGIN as the login string. | 2123 Open a network connection to PATH using LOGIN as the login string. |
2131 */ | 2124 */ |
2132 (path, login)) | 2125 (path, login)) |
2133 { | 2126 { |
2134 int netresult; | 2127 int netresult; |
2128 const char *path_ext; | |
2129 const char *login_ext; | |
2135 | 2130 |
2136 CHECK_STRING (path); | 2131 CHECK_STRING (path); |
2137 CHECK_STRING (login); | 2132 CHECK_STRING (login); |
2138 | 2133 |
2139 /* netunam, being a strange-o system call only used once, is not | 2134 /* netunam, being a strange-o system call only used once, is not |
2140 encapsulated. */ | 2135 encapsulated. */ |
2141 { | 2136 |
2142 char *path_ext; | 2137 TO_EXTERNAL_FORMAT (LISP_STRING, path, C_STRING_ALLOCA, path_ext, Qfile_name); |
2143 char *login_ext; | 2138 TO_EXTERNAL_FORMAT (LISP_STRING, login, C_STRING_ALLOCA, login_ext, Qnative); |
2144 | 2139 |
2145 GET_C_STRING_FILENAME_DATA_ALLOCA (path, path_ext); | 2140 netresult = netunam (path_ext, login_ext); |
2146 GET_C_STRING_EXT_DATA_ALLOCA (login, FORMAT_OS, login_ext); | 2141 |
2147 | 2142 return netresult == -1 ? Qnil : Qt; |
2148 netresult = netunam (path_ext, login_ext); | |
2149 } | |
2150 | |
2151 if (netresult == -1) | |
2152 return Qnil; | |
2153 else | |
2154 return Qt; | |
2155 } | 2143 } |
2156 #endif /* HPUX_NET */ | 2144 #endif /* HPUX_NET */ |
2157 | 2145 |
2158 DEFUN ("file-name-absolute-p", Ffile_name_absolute_p, 1, 1, 0, /* | 2146 DEFUN ("file-name-absolute-p", Ffile_name_absolute_p, 1, 1, 0, /* |
2159 Return t if file FILENAME specifies an absolute path name. | 2147 Return t if file FILENAME specifies an absolute path name. |
2735 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) | 2723 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) |
2736 error ("Attempt to visit less than an entire file"); | 2724 error ("Attempt to visit less than an entire file"); |
2737 | 2725 |
2738 fd = -1; | 2726 fd = -1; |
2739 | 2727 |
2740 if ( | 2728 if (stat ((char *) XSTRING_DATA (filename), &st) < 0) |
2741 #ifndef APOLLO | |
2742 (stat ((char *) XSTRING_DATA (filename), &st) < 0) | |
2743 #else /* APOLLO */ | |
2744 /* Don't even bother with interruptible_open. APOLLO sucks. */ | |
2745 ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY | OPEN_BINARY, 0)) < 0 | |
2746 || fstat (fd, &st) < 0) | |
2747 #endif /* APOLLO */ | |
2748 ) | |
2749 { | 2729 { |
2750 if (fd >= 0) close (fd); | 2730 if (fd >= 0) close (fd); |
2751 badopen: | 2731 badopen: |
2752 if (NILP (visit)) | 2732 if (NILP (visit)) |
2753 report_file_error ("Opening input file", list1 (filename)); | 2733 report_file_error ("Opening input file", list1 (filename)); |
3027 | 3007 |
3028 if (!NILP (visit)) | 3008 if (!NILP (visit)) |
3029 { | 3009 { |
3030 if (!EQ (buf->undo_list, Qt)) | 3010 if (!EQ (buf->undo_list, Qt)) |
3031 buf->undo_list = Qnil; | 3011 buf->undo_list = Qnil; |
3032 #ifdef APOLLO | |
3033 stat ((char *) XSTRING_DATA (filename), &st); | |
3034 #endif | |
3035 if (NILP (handler)) | 3012 if (NILP (handler)) |
3036 { | 3013 { |
3037 buf->modtime = st.st_mtime; | 3014 buf->modtime = st.st_mtime; |
3038 buf->filename = filename; | 3015 buf->filename = filename; |
3039 /* XEmacs addition: */ | 3016 /* XEmacs addition: */ |
3335 failure = 1; | 3312 failure = 1; |
3336 save_errno = errno; | 3313 save_errno = errno; |
3337 } | 3314 } |
3338 #endif /* HAVE_FSYNC */ | 3315 #endif /* HAVE_FSYNC */ |
3339 | 3316 |
3340 /* Spurious "file has changed on disk" warnings have been | 3317 /* Spurious "file has changed on disk" warnings used to be seen on |
3341 observed on Suns as well. | 3318 systems where close() can change the modtime. This is known to |
3342 It seems that `close' can change the modtime, under nfs. | 3319 happen on various NFS file systems, on Windows, and on Linux. |
3343 | 3320 Rather than handling this on a per-system basis, we |
3344 (This has supposedly been fixed in Sunos 4, | 3321 unconditionally do the stat() after the close(). */ |
3345 but who knows about all the other machines with NFS?) */ | |
3346 /* On VMS and APOLLO, must do the stat after the close | |
3347 since closing changes the modtime. */ | |
3348 /* As it does on Windows too - kkm */ | |
3349 /* The spurious warnings appear on Linux too. Rather than handling | |
3350 this on a per-system basis, unconditionally do the stat after the close - cgw */ | |
3351 | |
3352 #if 0 /* !defined (WINDOWSNT) */ /* !defined (VMS) && !defined (APOLLO) */ | |
3353 fstat (desc, &st); | |
3354 #endif | |
3355 | 3322 |
3356 /* NFS can report a write failure now. */ | 3323 /* NFS can report a write failure now. */ |
3357 if (close (desc) < 0) | 3324 if (close (desc) < 0) |
3358 { | 3325 { |
3359 failure = 1; | 3326 failure = 1; |
3365 as necessary). */ | 3332 as necessary). */ |
3366 XCAR (desc_locative) = Qnil; | 3333 XCAR (desc_locative) = Qnil; |
3367 unbind_to (speccount, Qnil); | 3334 unbind_to (speccount, Qnil); |
3368 } | 3335 } |
3369 | 3336 |
3370 /* # if defined (WINDOWSNT) */ /* defined (VMS) || defined (APOLLO) */ | |
3371 stat ((char *) XSTRING_DATA (fn), &st); | 3337 stat ((char *) XSTRING_DATA (fn), &st); |
3372 /* #endif */ | |
3373 | 3338 |
3374 #ifdef CLASH_DETECTION | 3339 #ifdef CLASH_DETECTION |
3375 if (!auto_saving) | 3340 if (!auto_saving) |
3376 unlock_file (lockname); | 3341 unlock_file (lockname); |
3377 #endif /* CLASH_DETECTION */ | 3342 #endif /* CLASH_DETECTION */ |
4019 if (listdesc >= 0) | 3984 if (listdesc >= 0) |
4020 { | 3985 { |
4021 CONST Extbyte *auto_save_file_name_ext; | 3986 CONST Extbyte *auto_save_file_name_ext; |
4022 Extcount auto_save_file_name_ext_len; | 3987 Extcount auto_save_file_name_ext_len; |
4023 | 3988 |
4024 GET_STRING_FILENAME_DATA_ALLOCA | 3989 TO_EXTERNAL_FORMAT (LISP_STRING, b->auto_save_file_name, |
4025 (b->auto_save_file_name, | 3990 ALLOCA, (auto_save_file_name_ext, |
4026 auto_save_file_name_ext, | 3991 auto_save_file_name_ext_len), |
4027 auto_save_file_name_ext_len); | 3992 Qfile_name); |
4028 if (!NILP (b->filename)) | 3993 if (!NILP (b->filename)) |
4029 { | 3994 { |
4030 CONST Extbyte *filename_ext; | 3995 CONST Extbyte *filename_ext; |
4031 Extcount filename_ext_len; | 3996 Extcount filename_ext_len; |
4032 | 3997 |
4033 GET_STRING_FILENAME_DATA_ALLOCA (b->filename, | 3998 TO_EXTERNAL_FORMAT (LISP_STRING, b->filename, |
4034 filename_ext, | 3999 ALLOCA, (filename_ext, |
4035 filename_ext_len); | 4000 filename_ext_len), |
4001 Qfile_name); | |
4036 write (listdesc, filename_ext, filename_ext_len); | 4002 write (listdesc, filename_ext, filename_ext_len); |
4037 } | 4003 } |
4038 write (listdesc, "\n", 1); | 4004 write (listdesc, "\n", 1); |
4039 write (listdesc, auto_save_file_name_ext, | 4005 write (listdesc, auto_save_file_name_ext, |
4040 auto_save_file_name_ext_len); | 4006 auto_save_file_name_ext_len); |