comparison src/fileio.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents a4f53d9b3154
children 6240c7796c7a
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
452 { 452 {
453 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */ 453 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */
454 Bufbyte *res = alloca (MAXPATHLEN + 1); 454 Bufbyte *res = alloca (MAXPATHLEN + 1);
455 if (getdefdir (toupper (*beg) - 'A' + 1, res)) 455 if (getdefdir (toupper (*beg) - 'A' + 1, res))
456 { 456 {
457 char *c=((char *) res) + strlen ((char *) res); 457 if (!IS_DIRECTORY_SEP (res[strlen ((char *) res) - 1]))
458 if (!IS_DIRECTORY_SEP (*c)) 458 strcat ((char *) res, "/");
459 {
460 *c++ = DIRECTORY_SEP;
461 *c = '\0';
462 }
463 beg = res; 459 beg = res;
464 p = beg + strlen ((char *) beg); 460 p = beg + strlen ((char *) beg);
465 } 461 }
466 } 462 }
463 CORRECT_DIR_SEPS (beg);
467 #endif /* WINDOWSNT */ 464 #endif /* WINDOWSNT */
468 return make_string (beg, p - beg); 465 return make_string (beg, p - beg);
469 } 466 }
470 467
471 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /* 468 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /*
545 { 542 {
546 out[size] = DIRECTORY_SEP; 543 out[size] = DIRECTORY_SEP;
547 out[size + 1] = '\0'; 544 out[size + 1] = '\0';
548 } 545 }
549 } 546 }
547 #ifdef WINDOWSNT
548 CORRECT_DIR_SEPS (out);
549 #endif
550 return out; 550 return out;
551 } 551 }
552 552
553 DEFUN ("file-name-as-directory", Ffile_name_as_directory, 1, 1, 0, /* 553 DEFUN ("file-name-as-directory", Ffile_name_as_directory, 1, 1, 0, /*
554 Return a string representing file FILENAME interpreted as a directory. 554 Return a string representing file FILENAME interpreted as a directory.
606 && !IS_ANY_SEP (dst[slen - 2]) 606 && !IS_ANY_SEP (dst[slen - 2])
607 #endif /* WINDOWSNT */ 607 #endif /* WINDOWSNT */
608 ) 608 )
609 dst[slen - 1] = 0; 609 dst[slen - 1] = 0;
610 #endif /* APOLLO */ 610 #endif /* APOLLO */
611 #ifdef WINDOWSNT
612 CORRECT_DIR_SEPS (dst);
613 #endif /* WINDOWSNT */
611 return 1; 614 return 1;
612 } 615 }
613 616
614 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /* 617 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /*
615 Return the file name of the directory named DIR. 618 Return the file name of the directory named DIR.
770 An initial `~USER/' expands to USER's home directory. 773 An initial `~USER/' expands to USER's home directory.
771 See also the function `substitute-in-file-name'. 774 See also the function `substitute-in-file-name'.
772 */ 775 */
773 (name, default_directory)) 776 (name, default_directory))
774 { 777 {
775 /* This function can GC. GC-checked 7-11-00 ben */ 778 /* This function can GC */
776 Bufbyte *nm; 779 Bufbyte *nm;
777 780
778 Bufbyte *newdir, *p, *o; 781 Bufbyte *newdir, *p, *o;
779 int tlen; 782 int tlen;
780 Bufbyte *target; 783 Bufbyte *target;
787 int length; 790 int length;
788 Lisp_Object handler; 791 Lisp_Object handler;
789 #ifdef __CYGWIN32__ 792 #ifdef __CYGWIN32__
790 char *user; 793 char *user;
791 #endif 794 #endif
792 struct gcpro gcpro1, gcpro2;
793
794 /* both of these get set below */
795 GCPRO2 (name, default_directory);
796 795
797 CHECK_STRING (name); 796 CHECK_STRING (name);
798 797
799 /* If the file name has special constructs in it, 798 /* If the file name has special constructs in it,
800 call the corresponding file handler. */ 799 call the corresponding file handler. */
801 handler = Ffind_file_name_handler (name, Qexpand_file_name); 800 handler = Ffind_file_name_handler (name, Qexpand_file_name);
802 if (!NILP (handler)) 801 if (!NILP (handler))
803 { 802 return call3_check_string (handler, Qexpand_file_name, name,
804 UNGCPRO; 803 default_directory);
805 return call3_check_string (handler, Qexpand_file_name, name,
806 default_directory);
807 }
808 804
809 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */ 805 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */
810 if (NILP (default_directory)) 806 if (NILP (default_directory))
811 default_directory = current_buffer->directory; 807 default_directory = current_buffer->directory;
812 if (! STRINGP (default_directory)) 808 if (! STRINGP (default_directory))
814 810
815 if (!NILP (default_directory)) 811 if (!NILP (default_directory))
816 { 812 {
817 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name); 813 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name);
818 if (!NILP (handler)) 814 if (!NILP (handler))
819 { 815 return call3 (handler, Qexpand_file_name, name, default_directory);
820 UNGCPRO;
821 return call3 (handler, Qexpand_file_name, name, default_directory);
822 }
823 } 816 }
824 817
825 o = XSTRING_DATA (default_directory); 818 o = XSTRING_DATA (default_directory);
826 819
827 /* Make sure DEFAULT_DIRECTORY is properly expanded. 820 /* Make sure DEFAULT_DIRECTORY is properly expanded.
849 /* Detect Unix absolute file names (/... alone is not absolute on 842 /* Detect Unix absolute file names (/... alone is not absolute on
850 DOS or Windows). */ 843 DOS or Windows). */
851 && ! (IS_DIRECTORY_SEP (o[0])) 844 && ! (IS_DIRECTORY_SEP (o[0]))
852 #endif /* not WINDOWSNT */ 845 #endif /* not WINDOWSNT */
853 ) 846 )
854 847 {
855 default_directory = Fexpand_file_name (default_directory, Qnil); 848 struct gcpro gcpro1;
849
850 GCPRO1 (name);
851 default_directory = Fexpand_file_name (default_directory, Qnil);
852 UNGCPRO;
853 }
856 854
857 #ifdef FILE_SYSTEM_CASE 855 #ifdef FILE_SYSTEM_CASE
858 name = FILE_SYSTEM_CASE (name); 856 name = FILE_SYSTEM_CASE (name);
859 #endif 857 #endif
860 858
953 { 951 {
954 name = make_string (nm - 2, p - nm + 2); 952 name = make_string (nm - 2, p - nm + 2);
955 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive); 953 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive);
956 XSTRING_DATA (name)[1] = ':'; 954 XSTRING_DATA (name)[1] = ':';
957 } 955 }
958 RETURN_UNGCPRO (name); 956 return name;
959 #else /* not WINDOWSNT */ 957 #else /* not WINDOWSNT */
960 if (nm == XSTRING_DATA (name)) 958 if (nm == XSTRING_DATA (name))
961 RETURN_UNGCPRO (name); 959 return name;
962 RETURN_UNGCPRO (build_string ((char *) nm)); 960 return build_string ((char *) nm);
963 #endif /* not WINDOWSNT */ 961 #endif /* not WINDOWSNT */
964 } 962 }
965 } 963 }
966 964
967 /* At this point, nm might or might not be an absolute file name. We 965 /* At this point, nm might or might not be an absolute file name. We
1264 abort (); 1262 abort ();
1265 } 1263 }
1266 CORRECT_DIR_SEPS (target); 1264 CORRECT_DIR_SEPS (target);
1267 #endif /* WINDOWSNT */ 1265 #endif /* WINDOWSNT */
1268 1266
1269 RETURN_UNGCPRO (make_string (target, o - target)); 1267 return make_string (target, o - target);
1270 } 1268 }
1271 1269
1272 #if 0 /* FSFmacs */ 1270 #if 0 /* FSFmacs */
1273 /* another older version of expand-file-name; */ 1271 /* another older version of expand-file-name; */
1274 #endif 1272 #endif
1302 if (!NILP (handler)) 1300 if (!NILP (handler))
1303 return call2_check_string (handler, Qfile_truename, expanded_name); 1301 return call2_check_string (handler, Qfile_truename, expanded_name);
1304 1302
1305 { 1303 {
1306 char resolved_path[MAXPATHLEN]; 1304 char resolved_path[MAXPATHLEN];
1307 char *path; 1305 char path[MAXPATHLEN];
1308 char *p; 1306 char *p = path;
1309 int elen = XSTRING_LENGTH (expanded_name); 1307 int elen = XSTRING_LENGTH (expanded_name);
1310 1308
1311 GET_STRING_FILENAME_DATA_ALLOCA(expanded_name,path,elen); 1309 if (elen >= countof (path))
1312 p = path;
1313 if (elen > MAXPATHLEN)
1314 goto toolong; 1310 goto toolong;
1315 1311
1312 memcpy (path, XSTRING_DATA (expanded_name), elen + 1);
1313 /* memset (resolved_path, 0, sizeof (resolved_path)); */
1314
1316 /* Try doing it all at once. */ 1315 /* Try doing it all at once. */
1317 /* !! Does realpath() Mule-encapsulate? 1316 /* !!#### Does realpath() Mule-encapsulate? */
1318 Answer: Nope! So we do it above */
1319 if (!xrealpath (path, resolved_path)) 1317 if (!xrealpath (path, resolved_path))
1320 { 1318 {
1321 /* Didn't resolve it -- have to do it one component at a time. */ 1319 /* Didn't resolve it -- have to do it one component at a time. */
1322 /* "realpath" is a typically useless, stupid un*x piece of crap. 1320 /* "realpath" is a typically useless, stupid un*x piece of crap.
1323 It claims to return a useful value in the "error" case, but since 1321 It claims to return a useful value in the "error" case, but since
1377 goto toolong; 1375 goto toolong;
1378 resolved_path[rlen] = '/'; 1376 resolved_path[rlen] = '/';
1379 resolved_path[rlen + 1] = 0; 1377 resolved_path[rlen + 1] = 0;
1380 rlen = rlen + 1; 1378 rlen = rlen + 1;
1381 } 1379 }
1382 return make_ext_string ((Bufbyte *) resolved_path, rlen, FORMAT_FILENAME); 1380 return make_ext_string ((Bufbyte *) resolved_path, rlen, FORMAT_BINARY);
1383 } 1381 }
1384 1382
1385 toolong: 1383 toolong:
1386 errno = ENAMETOOLONG; 1384 errno = ENAMETOOLONG;
1387 goto lose; 1385 goto lose;
2052 INTP (ok_if_already_exists), 0); 2050 INTP (ok_if_already_exists), 0);
2053 /* Syncing with FSF 19.34.6 note: FSF does not report a file error 2051 /* Syncing with FSF 19.34.6 note: FSF does not report a file error
2054 on NT here. --marcpa */ 2052 on NT here. --marcpa */
2055 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do 2053 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do
2056 that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK. 2054 that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK.
2057 Reverted to previous behavior pending a working fix. (jhar) */ 2055 Reverted to previous behaviour pending a working fix. (jhar) */
2058 #if defined(WINDOWSNT) 2056 #if defined(WINDOWSNT)
2059 /* Windows does not support this operation. */ 2057 /* Windows does not support this operation. */
2060 report_file_error ("Adding new name", Flist (2, &filename)); 2058 report_file_error ("Adding new name", Flist (2, &filename));
2061 #else /* not defined(WINDOWSNT) */ 2059 #else /* not defined(WINDOWSNT) */
2062 2060
2071 2069
2072 UNGCPRO; 2070 UNGCPRO;
2073 return Qnil; 2071 return Qnil;
2074 } 2072 }
2075 2073
2074 #ifdef S_IFLNK
2076 DEFUN ("make-symbolic-link", Fmake_symbolic_link, 2, 3, 2075 DEFUN ("make-symbolic-link", Fmake_symbolic_link, 2, 3,
2077 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np", /* 2076 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np", /*
2078 Make a symbolic link to FILENAME, named LINKNAME. Both args strings. 2077 Make a symbolic link to FILENAME, named LINKNAME. Both args strings.
2079 Signals a `file-already-exists' error if a file LINKNAME already exists 2078 Signals a `file-already-exists' error if a file LINKNAME already exists
2080 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. 2079 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
2082 This happens for interactive use with M-x. 2081 This happens for interactive use with M-x.
2083 */ 2082 */
2084 (filename, linkname, ok_if_already_exists)) 2083 (filename, linkname, ok_if_already_exists))
2085 { 2084 {
2086 /* This function can GC. GC checked 1997.06.04. */ 2085 /* This function can GC. GC checked 1997.06.04. */
2087 /* XEmacs change: run handlers even if local machine doesn't have symlinks */
2088 Lisp_Object handler; 2086 Lisp_Object handler;
2089 struct gcpro gcpro1, gcpro2; 2087 struct gcpro gcpro1, gcpro2;
2090 2088
2091 GCPRO2 (filename, linkname); 2089 GCPRO2 (filename, linkname);
2092 CHECK_STRING (filename); 2090 CHECK_STRING (filename);
2110 handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link); 2108 handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link);
2111 if (!NILP (handler)) 2109 if (!NILP (handler))
2112 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, 2110 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename,
2113 linkname, ok_if_already_exists)); 2111 linkname, ok_if_already_exists));
2114 2112
2115 #ifdef S_IFLNK
2116 if (NILP (ok_if_already_exists) 2113 if (NILP (ok_if_already_exists)
2117 || INTP (ok_if_already_exists)) 2114 || INTP (ok_if_already_exists))
2118 barf_or_query_if_file_exists (linkname, "make it a link", 2115 barf_or_query_if_file_exists (linkname, "make it a link",
2119 INTP (ok_if_already_exists), 0); 2116 INTP (ok_if_already_exists), 0);
2120 2117
2123 (char *) XSTRING_DATA (linkname))) 2120 (char *) XSTRING_DATA (linkname)))
2124 { 2121 {
2125 report_file_error ("Making symbolic link", 2122 report_file_error ("Making symbolic link",
2126 list2 (filename, linkname)); 2123 list2 (filename, linkname));
2127 } 2124 }
2128 #endif /* S_IFLNK */
2129
2130 UNGCPRO; 2125 UNGCPRO;
2131 return Qnil; 2126 return Qnil;
2132 } 2127 }
2128 #endif /* S_IFLNK */
2133 2129
2134 #ifdef HPUX_NET 2130 #ifdef HPUX_NET
2135 2131
2136 DEFUN ("sysnetunam", Fsysnetunam, 2, 2, 0, /* 2132 DEFUN ("sysnetunam", Fsysnetunam, 2, 2, 0, /*
2137 Open a network connection to PATH using LOGIN as the login string. 2133 Open a network connection to PATH using LOGIN as the login string.
2223 Return t if file FILENAME exists. (This does not mean you can read it.) 2219 Return t if file FILENAME exists. (This does not mean you can read it.)
2224 See also `file-readable-p' and `file-attributes'. 2220 See also `file-readable-p' and `file-attributes'.
2225 */ 2221 */
2226 (filename)) 2222 (filename))
2227 { 2223 {
2228 /* This function can call lisp; GC checked 7-11-00 ben */ 2224 /* This function can call lisp */
2229 Lisp_Object abspath; 2225 Lisp_Object abspath;
2230 Lisp_Object handler; 2226 Lisp_Object handler;
2231 struct stat statbuf; 2227 struct stat statbuf;
2232 struct gcpro gcpro1; 2228 struct gcpro gcpro1;
2233 2229
2250 For a directory, this means you can access files in that directory. 2246 For a directory, this means you can access files in that directory.
2251 */ 2247 */
2252 (filename)) 2248 (filename))
2253 2249
2254 { 2250 {
2255 /* This function can GC. GC checked 07-11-2000 ben. */ 2251 /* This function can GC. GC checked 1997.04.10. */
2256 Lisp_Object abspath; 2252 Lisp_Object abspath;
2257 Lisp_Object handler; 2253 Lisp_Object handler;
2258 struct gcpro gcpro1; 2254 struct gcpro gcpro1;
2259 2255
2260 CHECK_STRING (filename); 2256 CHECK_STRING (filename);
2290 call the corresponding file handler. */ 2286 call the corresponding file handler. */
2291 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); 2287 handler = Ffind_file_name_handler (abspath, Qfile_readable_p);
2292 if (!NILP (handler)) 2288 if (!NILP (handler))
2293 RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath)); 2289 RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath));
2294 2290
2295 #if defined(WINDOWSNT) || defined(__CYGWIN32__) 2291 #ifdef WINDOWSNT
2296 /* Under MS-DOS and Windows, open does not work for directories. */ 2292 /* Under MS-DOS and Windows, open does not work for directories. */
2297 UNGCPRO; 2293 UNGCPRO;
2298 if (access (XSTRING_DATA (abspath), 0) == 0) 2294 if (access (XSTRING_DATA (abspath), 0) == 0)
2299 return Qt; 2295 return Qt;
2300 else 2296 else
2354 Otherwise returns nil. 2350 Otherwise returns nil.
2355 */ 2351 */
2356 (filename)) 2352 (filename))
2357 { 2353 {
2358 /* This function can GC. GC checked 1997.04.10. */ 2354 /* This function can GC. GC checked 1997.04.10. */
2359 /* XEmacs change: run handlers even if local machine doesn't have symlinks */
2360 #ifdef S_IFLNK 2355 #ifdef S_IFLNK
2361 char *buf; 2356 char *buf;
2362 int bufsize; 2357 int bufsize;
2363 int valsize; 2358 int valsize;
2364 Lisp_Object val; 2359 Lisp_Object val;
2365 #endif
2366 Lisp_Object handler; 2360 Lisp_Object handler;
2367 struct gcpro gcpro1; 2361 struct gcpro gcpro1;
2368 2362
2369 CHECK_STRING (filename); 2363 CHECK_STRING (filename);
2370 filename = Fexpand_file_name (filename, Qnil); 2364 filename = Fexpand_file_name (filename, Qnil);
2375 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); 2369 handler = Ffind_file_name_handler (filename, Qfile_symlink_p);
2376 UNGCPRO; 2370 UNGCPRO;
2377 if (!NILP (handler)) 2371 if (!NILP (handler))
2378 return call2 (handler, Qfile_symlink_p, filename); 2372 return call2 (handler, Qfile_symlink_p, filename);
2379 2373
2380 #ifdef S_IFLNK
2381 bufsize = 100; 2374 bufsize = 100;
2382 while (1) 2375 while (1)
2383 { 2376 {
2384 buf = xnew_array_and_zero (char, bufsize); 2377 buf = xnew_array_and_zero (char, bufsize);
2385 valsize = readlink ((char *) XSTRING_DATA (filename), 2378 valsize = readlink ((char *) XSTRING_DATA (filename),
2777 2770
2778 if (!NILP (replace) || !NILP (beg) || !NILP (end)) 2771 if (!NILP (replace) || !NILP (beg) || !NILP (end))
2779 { 2772 {
2780 end_multiple_change (buf, mc_count); 2773 end_multiple_change (buf, mc_count);
2781 2774
2782 RETURN_UNGCPRO (Fsignal (Qfile_error, 2775 return Fsignal (Qfile_error,
2783 list2 (build_translated_string("not a regular file"), 2776 list2 (build_translated_string("not a regular file"),
2784 filename))); 2777 filename));
2785 } 2778 }
2786 } 2779 }
2787 #endif /* S_IFREG */ 2780 #endif /* S_IFREG */
2788 2781
2789 if (!NILP (beg)) 2782 if (!NILP (beg))
3148 /* This function can call lisp */ 3141 /* This function can call lisp */
3149 int desc; 3142 int desc;
3150 int failure; 3143 int failure;
3151 int save_errno = 0; 3144 int save_errno = 0;
3152 struct stat st; 3145 struct stat st;
3153 Lisp_Object fn = Qnil; 3146 Lisp_Object fn;
3154 int speccount = specpdl_depth (); 3147 int speccount = specpdl_depth ();
3155 int visiting_other = STRINGP (visit); 3148 int visiting_other = STRINGP (visit);
3156 int visiting = (EQ (visit, Qt) || visiting_other); 3149 int visiting = (EQ (visit, Qt) || visiting_other);
3157 int quietly = (!visiting && !NILP (visit)); 3150 int quietly = (!visiting && !NILP (visit));
3158 Lisp_Object visit_file = Qnil; 3151 Lisp_Object visit_file = Qnil;
3159 Lisp_Object annotations = Qnil; 3152 Lisp_Object annotations = Qnil;
3160 struct buffer *given_buffer; 3153 struct buffer *given_buffer;
3161 Bufpos start1, end1; 3154 Bufpos start1, end1;
3162 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 3155
3163 struct gcpro ngcpro1, ngcpro2; 3156 /* #### dmoore - if Fexpand_file_name or handlers kill the buffer,
3164 Lisp_Object curbuf;
3165
3166 XSETBUFFER (curbuf, current_buffer);
3167
3168 /* start, end, visit, and append are never modified in this fun
3169 so we don't protect them. */
3170 GCPRO5 (visit_file, filename, codesys, lockname, annotations);
3171 NGCPRO2 (curbuf, fn);
3172
3173 /* [[ dmoore - if Fexpand_file_name or handlers kill the buffer,
3174 we should signal an error rather than blissfully continuing 3157 we should signal an error rather than blissfully continuing
3175 along. ARGH, this function is going to lose lose lose. We need 3158 along. ARGH, this function is going to lose lose lose. We need
3176 to protect the current_buffer from being destroyed, but the 3159 to protect the current_buffer from being destroyed, but the
3177 multiple return points make this a pain in the butt. ]] we do 3160 multiple return points make this a pain in the butt. */
3178 protect curbuf now. --ben */
3179 3161
3180 #ifdef FILE_CODING 3162 #ifdef FILE_CODING
3181 codesys = Fget_coding_system (codesys); 3163 codesys = Fget_coding_system (codesys);
3182 #endif /* FILE_CODING */ 3164 #endif /* FILE_CODING */
3183 3165
3187 if (!NILP (start) && !STRINGP (start)) 3169 if (!NILP (start) && !STRINGP (start))
3188 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); 3170 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0);
3189 3171
3190 { 3172 {
3191 Lisp_Object handler; 3173 Lisp_Object handler;
3174 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3175
3176 GCPRO5 (start, filename, visit, visit_file, lockname);
3192 3177
3193 if (visiting_other) 3178 if (visiting_other)
3194 visit_file = Fexpand_file_name (visit, Qnil); 3179 visit_file = Fexpand_file_name (visit, Qnil);
3195 else 3180 else
3196 visit_file = filename; 3181 visit_file = filename;
3197 filename = Fexpand_file_name (filename, Qnil); 3182 filename = Fexpand_file_name (filename, Qnil);
3198 3183
3184 UNGCPRO;
3185
3199 if (NILP (lockname)) 3186 if (NILP (lockname))
3200 lockname = visit_file; 3187 lockname = visit_file;
3201 3188
3202 /* We used to UNGCPRO here. BAD! visit_file is used below after
3203 more Lisp calling. */
3204 /* If the file name has special constructs in it, 3189 /* If the file name has special constructs in it,
3205 call the corresponding file handler. */ 3190 call the corresponding file handler. */
3206 handler = Ffind_file_name_handler (filename, Qwrite_region); 3191 handler = Ffind_file_name_handler (filename, Qwrite_region);
3207 /* If FILENAME has no handler, see if VISIT has one. */ 3192 /* If FILENAME has no handler, see if VISIT has one. */
3208 if (NILP (handler) && STRINGP (visit)) 3193 if (NILP (handler) && STRINGP (visit))
3217 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); 3202 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
3218 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer)); 3203 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer));
3219 current_buffer->filename = visit_file; 3204 current_buffer->filename = visit_file;
3220 MARK_MODELINE_CHANGED; 3205 MARK_MODELINE_CHANGED;
3221 } 3206 }
3222 NUNGCPRO;
3223 UNGCPRO;
3224 return val; 3207 return val;
3225 } 3208 }
3226 } 3209 }
3227 3210
3228 #ifdef CLASH_DETECTION 3211 #ifdef CLASH_DETECTION
3229 if (!auto_saving) 3212 if (!auto_saving)
3230 lock_file (lockname); 3213 {
3214 Lisp_Object curbuf;
3215 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3216
3217 XSETBUFFER (curbuf, current_buffer);
3218 GCPRO5 (start, filename, visit_file, lockname, curbuf);
3219 lock_file (lockname);
3220 UNGCPRO;
3221 }
3231 #endif /* CLASH_DETECTION */ 3222 #endif /* CLASH_DETECTION */
3232 3223
3233 /* Special kludge to simplify auto-saving. */ 3224 /* Special kludge to simplify auto-saving. */
3234 if (NILP (start)) 3225 if (NILP (start))
3235 { 3226 {
3271 } 3262 }
3272 3263
3273 { 3264 {
3274 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); 3265 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil);
3275 Lisp_Object instream = Qnil, outstream = Qnil; 3266 Lisp_Object instream = Qnil, outstream = Qnil;
3276 struct gcpro nngcpro1, nngcpro2; 3267 struct gcpro gcpro1, gcpro2;
3277 /* need to gcpro; QUIT could happen out of call to write() */ 3268 /* need to gcpro; QUIT could happen out of call to write() */
3278 NNGCPRO2 (instream, outstream); 3269 GCPRO2 (instream, outstream);
3279 3270
3280 record_unwind_protect (close_file_unwind, desc_locative); 3271 record_unwind_protect (close_file_unwind, desc_locative);
3281 3272
3282 if (!NILP (append)) 3273 if (!NILP (append))
3283 { 3274 {
3331 { 3322 {
3332 failure = 1; 3323 failure = 1;
3333 save_errno = errno; 3324 save_errno = errno;
3334 } 3325 }
3335 Lstream_close (XLSTREAM (instream)); 3326 Lstream_close (XLSTREAM (instream));
3327 UNGCPRO;
3336 3328
3337 #ifdef HAVE_FSYNC 3329 #ifdef HAVE_FSYNC
3338 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun). 3330 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun).
3339 Disk full in NFS may be reported here. */ 3331 Disk full in NFS may be reported here. */
3340 /* mib says that closing the file will try to write as fast as NFS can do 3332 /* mib says that closing the file will try to write as fast as NFS can do
3346 failure = 1; 3338 failure = 1;
3347 save_errno = errno; 3339 save_errno = errno;
3348 } 3340 }
3349 #endif /* HAVE_FSYNC */ 3341 #endif /* HAVE_FSYNC */
3350 3342
3351 /* 3343 /* Spurious "file has changed on disk" warnings have been
3352 * On VMS and APOLLO, must do the stat after the close 3344 observed on Suns as well.
3353 * since closing changes the modtime. 3345 It seems that `close' can change the modtime, under nfs.
3354 * 3346
3355 * Spurious "file has changed on disk" warnings have been 3347 (This has supposedly been fixed in Sunos 4,
3356 * observed on Suns as well. It seems that `close' can change 3348 but who knows about all the other machines with NFS?) */
3357 * the modtime, under nfs. (This has supposedly been fixed in 3349 /* On VMS and APOLLO, must do the stat after the close
3358 * Sunos 4, but who knows about all the other machines with 3350 since closing changes the modtime. */
3359 * NFS?) 3351 /* As it does on Windows too - kkm */
3360 * 3352 #if !defined (WINDOWSNT) /* !defined (VMS) && !defined (APOLLO) */
3361 * This is reported to happen under Windows also. 3353 fstat (desc, &st);
3362 * 3354 #endif
3363 * So we don't do the stat here. It is done after the
3364 * descriptor is closed.
3365 */
3366 3355
3367 /* NFS can report a write failure now. */ 3356 /* NFS can report a write failure now. */
3368 if (close (desc) < 0) 3357 if (close (desc) < 0)
3369 { 3358 {
3370 failure = 1; 3359 failure = 1;
3374 /* Discard the close unwind-protect. Execute the one for 3363 /* Discard the close unwind-protect. Execute the one for
3375 build_annotations (switches back to the original current buffer 3364 build_annotations (switches back to the original current buffer
3376 as necessary). */ 3365 as necessary). */
3377 XCAR (desc_locative) = Qnil; 3366 XCAR (desc_locative) = Qnil;
3378 unbind_to (speccount, Qnil); 3367 unbind_to (speccount, Qnil);
3379
3380 NNUNGCPRO;
3381 } 3368 }
3382 3369
3383 /* 3370 #if defined (WINDOWSNT) /* defined (VMS) || defined (APOLLO) */
3384 * stat the file after the file is closed to avoid having the
3385 * modtime change on us when the file is closed.
3386 */
3387 stat ((char *) XSTRING_DATA (fn), &st); 3371 stat ((char *) XSTRING_DATA (fn), &st);
3372 #endif
3388 3373
3389 #ifdef CLASH_DETECTION 3374 #ifdef CLASH_DETECTION
3390 if (!auto_saving) 3375 if (!auto_saving)
3391 unlock_file (lockname); 3376 unlock_file (lockname);
3392 #endif /* CLASH_DETECTION */ 3377 #endif /* CLASH_DETECTION */
3409 current_buffer->filename = visit_file; 3394 current_buffer->filename = visit_file;
3410 MARK_MODELINE_CHANGED; 3395 MARK_MODELINE_CHANGED;
3411 } 3396 }
3412 else if (quietly) 3397 else if (quietly)
3413 { 3398 {
3414 NUNGCPRO;
3415 UNGCPRO;
3416 return Qnil; 3399 return Qnil;
3417 } 3400 }
3418 3401
3419 if (!auto_saving) 3402 if (!auto_saving)
3420 { 3403 {
3421 if (visiting_other) 3404 if (visiting_other)
3422 message ("Wrote %s", XSTRING_DATA (visit_file)); 3405 message ("Wrote %s", XSTRING_DATA (visit_file));
3423 else 3406 else
3424 { 3407 {
3425 Lisp_Object fsp = Qnil; 3408 struct gcpro gcpro1;
3426 struct gcpro nngcpro1; 3409 Lisp_Object fsp;
3427 3410 GCPRO1 (fn);
3428 NNGCPRO1 (fsp); 3411
3429 fsp = Ffile_symlink_p (fn); 3412 fsp = Ffile_symlink_p (fn);
3430 if (NILP (fsp)) 3413 if (NILP (fsp))
3431 message ("Wrote %s", XSTRING_DATA (fn)); 3414 message ("Wrote %s", XSTRING_DATA (fn));
3432 else 3415 else
3433 message ("Wrote %s (symlink to %s)", 3416 message ("Wrote %s (symlink to %s)",
3434 XSTRING_DATA (fn), XSTRING_DATA (fsp)); 3417 XSTRING_DATA (fn), XSTRING_DATA (fsp));
3435 NNUNGCPRO; 3418 UNGCPRO;
3436 } 3419 }
3437 } 3420 }
3438 NUNGCPRO;
3439 UNGCPRO;
3440 return Qnil; 3421 return Qnil;
3441 } 3422 }
3442 3423
3443 /* #### This is such a load of shit!!!! There is no way we should define 3424 /* #### This is such a load of shit!!!! There is no way we should define
3444 something so stupid as a subr, just sort the fucking list more 3425 something so stupid as a subr, just sort the fucking list more
3680 Return t if last mod time of BUF's visited file matches what BUF records. 3661 Return t if last mod time of BUF's visited file matches what BUF records.
3681 This means that the file has not been changed since it was visited or saved. 3662 This means that the file has not been changed since it was visited or saved.
3682 */ 3663 */
3683 (buf)) 3664 (buf))
3684 { 3665 {
3685 /* This function can call lisp; GC checked 7-11-00 ben */ 3666 /* This function can call lisp */
3686 struct buffer *b; 3667 struct buffer *b;
3687 struct stat st; 3668 struct stat st;
3688 Lisp_Object handler; 3669 Lisp_Object handler;
3689 3670
3690 CHECK_BUFFER (buf); 3671 CHECK_BUFFER (buf);
3755 lisp_to_time (time_list, &the_time); 3736 lisp_to_time (time_list, &the_time);
3756 current_buffer->modtime = (int) the_time; 3737 current_buffer->modtime = (int) the_time;
3757 } 3738 }
3758 else 3739 else
3759 { 3740 {
3760 Lisp_Object filename = Qnil; 3741 Lisp_Object filename;
3761 struct stat st; 3742 struct stat st;
3762 Lisp_Object handler; 3743 Lisp_Object handler;
3763 struct gcpro gcpro1, gcpro2, gcpro3; 3744 struct gcpro gcpro1, gcpro2, gcpro3;
3764 3745
3765 GCPRO3 (filename, time_list, current_buffer->filename); 3746 GCPRO3 (filename, time_list, current_buffer->filename);
4217 DEFSUBR (Fmake_directory_internal); 4198 DEFSUBR (Fmake_directory_internal);
4218 DEFSUBR (Fdelete_directory); 4199 DEFSUBR (Fdelete_directory);
4219 DEFSUBR (Fdelete_file); 4200 DEFSUBR (Fdelete_file);
4220 DEFSUBR (Frename_file); 4201 DEFSUBR (Frename_file);
4221 DEFSUBR (Fadd_name_to_file); 4202 DEFSUBR (Fadd_name_to_file);
4203 #ifdef S_IFLNK
4222 DEFSUBR (Fmake_symbolic_link); 4204 DEFSUBR (Fmake_symbolic_link);
4205 #endif /* S_IFLNK */
4223 #ifdef HPUX_NET 4206 #ifdef HPUX_NET
4224 DEFSUBR (Fsysnetunam); 4207 DEFSUBR (Fsysnetunam);
4225 #endif /* HPUX_NET */ 4208 #endif /* HPUX_NET */
4226 DEFSUBR (Ffile_name_absolute_p); 4209 DEFSUBR (Ffile_name_absolute_p);
4227 DEFSUBR (Ffile_exists_p); 4210 DEFSUBR (Ffile_exists_p);
4343 The value should be either ?/ or ?\\ (any other value is treated as ?\\). 4326 The value should be either ?/ or ?\\ (any other value is treated as ?\\).
4344 This variable affects the built-in functions only on Windows, 4327 This variable affects the built-in functions only on Windows,
4345 on other platforms, it is initialized so that Lisp code can find out 4328 on other platforms, it is initialized so that Lisp code can find out
4346 what the normal separator is. 4329 what the normal separator is.
4347 */ ); 4330 */ );
4348 #ifdef WINDOWSNT
4349 Vdirectory_sep_char = make_char ('\\');
4350 #else
4351 Vdirectory_sep_char = make_char ('/'); 4331 Vdirectory_sep_char = make_char ('/');
4352 #endif 4332 }
4353 }