comparison src/fileio.c @ 151:59463afc5666 r20-3b2

Import from CVS: tag r20-3b2
author cvs
date Mon, 13 Aug 2007 09:37:19 +0200
parents 538048ae2ab8
children 85ec50267440
comparison
equal deleted inserted replaced
150:8ebb1c0f0f6f 151:59463afc5666
57 57
58 /* Set by auto_save_1 to mode of original file so Fwrite_region_internal 58 /* Set by auto_save_1 to mode of original file so Fwrite_region_internal
59 will create a new file with the same mode as the original */ 59 will create a new file with the same mode as the original */
60 static int auto_save_mode_bits; 60 static int auto_save_mode_bits;
61 61
62 /* Alist of elements (REGEXP . HANDLER) for file names 62 /* Alist of elements (REGEXP . HANDLER) for file names
63 whose I/O is done with a special handler. */ 63 whose I/O is done with a special handler. */
64 Lisp_Object Vfile_name_handler_alist; 64 Lisp_Object Vfile_name_handler_alist;
65 65
66 /* Format for auto-save files */ 66 /* Format for auto-save files */
67 Lisp_Object Vauto_save_file_format; 67 Lisp_Object Vauto_save_file_format;
118 /* #### dmoore - This uses current_buffer, better make sure no one 118 /* #### dmoore - This uses current_buffer, better make sure no one
119 has GC'd the current buffer. File handlers are giving me a headache 119 has GC'd the current buffer. File handlers are giving me a headache
120 maybe I'll just always protect current_buffer around all of those 120 maybe I'll just always protect current_buffer around all of those
121 calls. */ 121 calls. */
122 122
123 /* mrb: #### Needs to be fixed at a lower level; errstring needs to
124 be MULEized. The following at least prevents a crash... */
125 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_NATIVE);
126
127 /* System error messages are capitalized. Downcase the initial
128 unless it is followed by a slash. */
129 if (string_char (XSTRING (errstring), 1) != '/')
130 set_string_char (XSTRING (errstring), 0,
131 DOWNCASE (current_buffer,
132 string_char (XSTRING (errstring), 0)));
133
134 signal_error (Qfile_error, 123 signal_error (Qfile_error,
135 Fcons (build_translated_string (string), 124 Fcons (build_translated_string (string),
136 Fcons (errstring, data))); 125 Fcons (lisp_strerror (errno), data)));
137 } 126 }
138 127
139 void 128 void
140 maybe_report_file_error (CONST char *string, Lisp_Object data, 129 maybe_report_file_error (CONST char *string, Lisp_Object data,
141 Lisp_Object class, Error_behavior errb) 130 Lisp_Object class, Error_behavior errb)
142 { 131 {
143 Lisp_Object errstring;
144
145 /* Optimization: */ 132 /* Optimization: */
146 if (ERRB_EQ (errb, ERROR_ME_NOT)) 133 if (ERRB_EQ (errb, ERROR_ME_NOT))
147 return; 134 return;
148 135
149 errstring = build_string (strerror (errno));
150
151 /* System error messages are capitalized. Downcase the initial
152 unless it is followed by a slash. */
153 if (string_char (XSTRING (errstring), 1) != '/')
154 set_string_char (XSTRING (errstring), 0,
155 DOWNCASE (current_buffer,
156 string_char (XSTRING (errstring), 0)));
157
158 maybe_signal_error (Qfile_error, 136 maybe_signal_error (Qfile_error,
159 Fcons (build_translated_string (string), 137 Fcons (build_translated_string (string),
160 Fcons (errstring, data)), 138 Fcons (lisp_strerror (errno), data)),
161 class, errb); 139 class, errb);
162 } 140 }
163 141
164 /* signal a file error when errno does not contain a meaningful value. */ 142 /* signal a file error when errno does not contain a meaningful value. */
165 143
210 DOESNT_RETURN 188 DOESNT_RETURN
211 signal_double_file_error_2 (CONST char *string1, CONST char *string2, 189 signal_double_file_error_2 (CONST char *string1, CONST char *string2,
212 Lisp_Object data1, Lisp_Object data2) 190 Lisp_Object data1, Lisp_Object data2)
213 { 191 {
214 signal_error (Qfile_error, 192 signal_error (Qfile_error,
215 list4 (build_translated_string (string1), 193 list4 (build_translated_string (string1),
216 build_translated_string (string2), 194 build_translated_string (string2),
217 data1, data2)); 195 data1, data2));
218 } 196 }
219 197
220 void 198 void
224 { 202 {
225 /* Optimization: */ 203 /* Optimization: */
226 if (ERRB_EQ (errb, ERROR_ME_NOT)) 204 if (ERRB_EQ (errb, ERROR_ME_NOT))
227 return; 205 return;
228 maybe_signal_error (Qfile_error, 206 maybe_signal_error (Qfile_error,
229 list4 (build_translated_string (string1), 207 list4 (build_translated_string (string1),
230 build_translated_string (string2), 208 build_translated_string (string2),
231 data1, data2), 209 data1, data2),
232 class, errb); 210 class, errb);
211 }
212
213
214 /* Just like strerror(3), except return a lisp string instead of char *.
215 The string needs to be converted since it may be localized.
216 Perhaps this should use strerror-coding-system instead? */
217 Lisp_Object
218 lisp_strerror (int errnum)
219 {
220 return build_ext_string (strerror (errnum), FORMAT_NATIVE);
233 } 221 }
234 222
235 static Lisp_Object 223 static Lisp_Object
236 close_file_unwind (Lisp_Object fd) 224 close_file_unwind (Lisp_Object fd)
237 { 225 {
392 CHECK_STRING (result); 380 CHECK_STRING (result);
393 return (result); 381 return (result);
394 } 382 }
395 383
396 static Lisp_Object 384 static Lisp_Object
397 call3_check_string (Lisp_Object fn, Lisp_Object arg0, 385 call3_check_string (Lisp_Object fn, Lisp_Object arg0,
398 Lisp_Object arg1, Lisp_Object arg2) 386 Lisp_Object arg1, Lisp_Object arg2)
399 { 387 {
400 /* This function can call lisp */ 388 /* This function can call lisp */
401 Lisp_Object result = call3 (fn, arg0, arg1, arg2); 389 Lisp_Object result = call3 (fn, arg0, arg1, arg2);
402 CHECK_STRING (result); 390 CHECK_STRING (result);
455 /* The NT version places the drive letter at the beginning already. */ 443 /* The NT version places the drive letter at the beginning already. */
456 #else /* not WINDOWSNT */ 444 #else /* not WINDOWSNT */
457 /* On MSDOG we must put the drive letter in by hand. */ 445 /* On MSDOG we must put the drive letter in by hand. */
458 res1 = res + 2; 446 res1 = res + 2;
459 #endif /* not WINDOWSNT */ 447 #endif /* not WINDOWSNT */
460 if (getdefdir (drive + 1, res)) 448 if (getdefdir (drive + 1, res))
461 { 449 {
462 #ifdef MSDOS 450 #ifdef MSDOS
463 res[0] = drive + 'a'; 451 res[0] = drive + 'a';
464 res[1] = ':'; 452 res[1] = ':';
465 #endif /* MSDOS */ 453 #endif /* MSDOS */
779 /* Handle // as root for apollo's. */ 767 /* Handle // as root for apollo's. */
780 if ((slen > 2 && dst[slen - 1] == '/') 768 if ((slen > 2 && dst[slen - 1] == '/')
781 || (slen > 1 && dst[0] != '/' && dst[slen - 1] == '/')) 769 || (slen > 1 && dst[0] != '/' && dst[slen - 1] == '/'))
782 dst[slen - 1] = 0; 770 dst[slen - 1] = 0;
783 #else 771 #else
784 if (slen > 1 772 if (slen > 1
785 && IS_DIRECTORY_SEP (dst[slen - 1]) 773 && IS_DIRECTORY_SEP (dst[slen - 1])
786 #ifdef DOS_NT 774 #ifdef DOS_NT
787 && !IS_ANY_SEP (dst[slen - 2]) 775 && !IS_ANY_SEP (dst[slen - 2])
788 #endif 776 #endif
789 ) 777 )
859 DEFUN ("expand-file-name", Fexpand_file_name, 1, 2, 0, /* 847 DEFUN ("expand-file-name", Fexpand_file_name, 1, 2, 0, /*
860 Convert FILENAME to absolute, and canonicalize it. 848 Convert FILENAME to absolute, and canonicalize it.
861 Second arg DEFAULT is directory to start with if FILENAME is relative 849 Second arg DEFAULT is directory to start with if FILENAME is relative
862 (does not start with slash); if DEFAULT is nil or missing, 850 (does not start with slash); if DEFAULT is nil or missing,
863 the current buffer's value of default-directory is used. 851 the current buffer's value of default-directory is used.
864 Path components that are `.' are removed, and 852 Path components that are `.' are removed, and
865 path components followed by `..' are removed, along with the `..' itself; 853 path components followed by `..' are removed, along with the `..' itself;
866 note that these simplifications are done without checking the resulting 854 note that these simplifications are done without checking the resulting
867 paths in the file system. 855 paths in the file system.
868 An initial `~/' expands to your home directory. 856 An initial `~/' expands to your home directory.
869 An initial `~USER/' expands to USER's home directory. 857 An initial `~USER/' expands to USER's home directory.
871 */ 859 */
872 (name, defalt)) 860 (name, defalt))
873 { 861 {
874 /* This function can GC. GC checked 1997.04.06. */ 862 /* This function can GC. GC checked 1997.04.06. */
875 Bufbyte *nm; 863 Bufbyte *nm;
876 864
877 Bufbyte *newdir, *p, *o; 865 Bufbyte *newdir, *p, *o;
878 int tlen; 866 int tlen;
879 Bufbyte *target; 867 Bufbyte *target;
880 struct passwd *pw; 868 struct passwd *pw;
881 #ifdef VMS 869 #ifdef VMS
891 int drive = -1; 879 int drive = -1;
892 int relpath = 0; 880 int relpath = 0;
893 Bufbyte *tmp, *defdir; 881 Bufbyte *tmp, *defdir;
894 #endif /* DOS_NT */ 882 #endif /* DOS_NT */
895 Lisp_Object handler; 883 Lisp_Object handler;
896 884
897 CHECK_STRING (name); 885 CHECK_STRING (name);
898 886
899 /* If the file name has special constructs in it, 887 /* If the file name has special constructs in it,
900 call the corresponding file handler. */ 888 call the corresponding file handler. */
901 handler = Ffind_file_name_handler (name, Qexpand_file_name); 889 handler = Ffind_file_name_handler (name, Qexpand_file_name);
962 #endif 950 #endif
963 951
964 /* #### dmoore - this is ugly, clean this up. Looks like nm 952 /* #### dmoore - this is ugly, clean this up. Looks like nm
965 pointing into name should be safe during all of this, though. */ 953 pointing into name should be safe during all of this, though. */
966 nm = XSTRING_DATA (name); 954 nm = XSTRING_DATA (name);
967 955
968 #ifdef MSDOS 956 #ifdef MSDOS
969 /* First map all backslashes to slashes. */ 957 /* First map all backslashes to slashes. */
970 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 958 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
971 #endif 959 #endif
972 960
984 if (!IS_DIRECTORY_SEP (*nm)) 972 if (!IS_DIRECTORY_SEP (*nm))
985 { 973 {
986 defdir = alloca (MAXPATHLEN + 1); 974 defdir = alloca (MAXPATHLEN + 1);
987 relpath = getdefdir (tolower (drive) - 'a' + 1, defdir); 975 relpath = getdefdir (tolower (drive) - 'a' + 1, defdir);
988 } 976 }
989 } 977 }
990 } 978 }
991 #endif /* DOS_NT */ 979 #endif /* DOS_NT */
992 980
993 /* Handle // and /~ in middle of file name 981 /* Handle // and /~ in middle of file name
994 by discarding everything through the first / of that sequence. */ 982 by discarding everything through the first / of that sequence. */
1000 988
1001 /* "//" anywhere isn't necessarily hairy; we just start afresh 989 /* "//" anywhere isn't necessarily hairy; we just start afresh
1002 with the second slash. */ 990 with the second slash. */
1003 if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1]) 991 if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])
1004 #if defined (APOLLO) || defined (WINDOWSNT) 992 #if defined (APOLLO) || defined (WINDOWSNT)
1005 /* // at start of filename is meaningful on Apollo 993 /* // at start of filename is meaningful on Apollo
1006 and WindowsNT systems */ 994 and WindowsNT systems */
1007 && nm != p 995 && nm != p
1008 #endif /* APOLLO || WINDOWSNT */ 996 #endif /* APOLLO || WINDOWSNT */
1009 ) 997 )
1010 nm = p + 1; 998 nm = p + 1;
1211 newdir = XSTRING_DATA (defalt); 1199 newdir = XSTRING_DATA (defalt);
1212 } 1200 }
1213 1201
1214 #ifdef DOS_NT 1202 #ifdef DOS_NT
1215 if (newdir == 0 && relpath) 1203 if (newdir == 0 && relpath)
1216 newdir = defdir; 1204 newdir = defdir;
1217 #endif /* DOS_NT */ 1205 #endif /* DOS_NT */
1218 if (newdir != 0) 1206 if (newdir != 0)
1219 { 1207 {
1220 /* Get rid of any slash at the end of newdir. */ 1208 /* Get rid of any slash at the end of newdir. */
1221 int length = strlen ((char *) newdir); 1209 int length = strlen ((char *) newdir);
1238 tlen = 0; 1226 tlen = 0;
1239 1227
1240 /* Now concatenate the directory and name to new space in the stack frame */ 1228 /* Now concatenate the directory and name to new space in the stack frame */
1241 tlen += strlen ((char *) nm) + 1; 1229 tlen += strlen ((char *) nm) + 1;
1242 #ifdef DOS_NT 1230 #ifdef DOS_NT
1243 /* Add reserved space for drive name. (The Microsoft x86 compiler 1231 /* Add reserved space for drive name. (The Microsoft x86 compiler
1244 produces incorrect code if the following two lines are combined.) */ 1232 produces incorrect code if the following two lines are combined.) */
1245 target = (Bufbyte *) alloca (tlen + 2); 1233 target = (Bufbyte *) alloca (tlen + 2);
1246 target += 2; 1234 target += 2;
1247 #else /* not DOS_NT */ 1235 #else /* not DOS_NT */
1248 target = (Bufbyte *) alloca (tlen); 1236 target = (Bufbyte *) alloca (tlen);
1318 { 1306 {
1319 *o++ = *p++; 1307 *o++ = *p++;
1320 } 1308 }
1321 else if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1]) 1309 else if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])
1322 #if defined (APOLLO) || defined (WINDOWSNT) 1310 #if defined (APOLLO) || defined (WINDOWSNT)
1323 /* // at start of filename is meaningful in Apollo 1311 /* // at start of filename is meaningful in Apollo
1324 and WindowsNT systems */ 1312 and WindowsNT systems */
1325 && o != target 1313 && o != target
1326 #endif /* APOLLO */ 1314 #endif /* APOLLO */
1327 ) 1315 )
1328 { 1316 {
1346 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0)) 1334 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0))
1347 { 1335 {
1348 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o)) 1336 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o))
1349 ; 1337 ;
1350 #if defined (APOLLO) || defined (WINDOWSNT) 1338 #if defined (APOLLO) || defined (WINDOWSNT)
1351 if (o == target + 1 1339 if (o == target + 1
1352 && IS_DIRECTORY_SEP (o[-1]) && IS_DIRECTORY_SEP (o[0])) 1340 && IS_DIRECTORY_SEP (o[-1]) && IS_DIRECTORY_SEP (o[0]))
1353 ++o; 1341 ++o;
1354 else 1342 else
1355 #endif /* APOLLO || WINDOWSNT */ 1343 #endif /* APOLLO || WINDOWSNT */
1356 if (o == target && IS_ANY_SEP (*o)) 1344 if (o == target && IS_ANY_SEP (*o))
1426 { 1414 {
1427 char resolved_path[MAXPATHLEN]; 1415 char resolved_path[MAXPATHLEN];
1428 char path[MAXPATHLEN]; 1416 char path[MAXPATHLEN];
1429 char *p = path; 1417 char *p = path;
1430 int elen = XSTRING_LENGTH (expanded_name); 1418 int elen = XSTRING_LENGTH (expanded_name);
1431 1419
1432 if (elen >= countof (path)) 1420 if (elen >= countof (path))
1433 goto toolong; 1421 goto toolong;
1434 1422
1435 memcpy (path, XSTRING_DATA (expanded_name), elen + 1); 1423 memcpy (path, XSTRING_DATA (expanded_name), elen + 1);
1436 /* memset (resolved_path, 0, sizeof (resolved_path)); */ 1424 /* memset (resolved_path, 0, sizeof (resolved_path)); */
1437 1425
1438 /* Try doing it all at once. */ 1426 /* Try doing it all at once. */
1439 /* !!#### Does realpath() Mule-encapsulate? */ 1427 /* !!#### Does realpath() Mule-encapsulate? */
1470 the error, and places in resolved_path the absolute pathname 1458 the error, and places in resolved_path the absolute pathname
1471 of the path component which could not be resolved." */ 1459 of the path component which could not be resolved." */
1472 if (p) 1460 if (p)
1473 { 1461 {
1474 int plen = elen - (p - path); 1462 int plen = elen - (p - path);
1475 1463
1476 if (rlen > 1 && resolved_path[rlen - 1] == '/') 1464 if (rlen > 1 && resolved_path[rlen - 1] == '/')
1477 rlen = rlen - 1; 1465 rlen = rlen - 1;
1478 1466
1479 if (plen + rlen + 1 > countof (resolved_path)) 1467 if (plen + rlen + 1 > countof (resolved_path))
1480 goto toolong; 1468 goto toolong;
1792 1780
1793 prompt = emacs_doprnt_string_c 1781 prompt = emacs_doprnt_string_c
1794 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "), 1782 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "),
1795 Qnil, -1, XSTRING_DATA (absname), 1783 Qnil, -1, XSTRING_DATA (absname),
1796 GETTEXT (querystring)); 1784 GETTEXT (querystring));
1797 1785
1798 GCPRO1 (prompt); 1786 GCPRO1 (prompt);
1799 tem = call1 (Qyes_or_no_p, prompt); 1787 tem = call1 (Qyes_or_no_p, prompt);
1800 UNGCPRO; 1788 UNGCPRO;
1801 } 1789 }
1802 else 1790 else
1866 { 1854 {
1867 Lisp_Object args[3]; 1855 Lisp_Object args[3];
1868 struct gcpro ngcpro1; 1856 struct gcpro ngcpro1;
1869 int i = 1; 1857 int i = 1;
1870 1858
1871 args[0] = newname; 1859 args[0] = newname;
1872 args[1] = Qnil; args[2] = Qnil; 1860 args[1] = Qnil; args[2] = Qnil;
1873 NGCPRO1 (*args); 1861 NGCPRO1 (*args);
1874 ngcpro1.nvars = 3; 1862 ngcpro1.nvars = 3;
1875 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/') 1863 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/')
1876 args[i++] = build_string ("/"); 1864 args[i++] = build_string ("/");
1877 args[i++] = Ffile_name_nondirectory (filename); 1865 args[i++] = Ffile_name_nondirectory (filename);
1878 newname = Fconcat (i, args); 1866 newname = Fconcat (i, args);
1998 { 1986 {
1999 /* This function can GC. GC checked 1997.04.06. */ 1987 /* This function can GC. GC checked 1997.04.06. */
2000 char dir [MAXPATHLEN]; 1988 char dir [MAXPATHLEN];
2001 Lisp_Object handler; 1989 Lisp_Object handler;
2002 struct gcpro gcpro1; 1990 struct gcpro gcpro1;
2003 1991
2004 CHECK_STRING (dirname); 1992 CHECK_STRING (dirname);
2005 dirname = Fexpand_file_name (dirname, Qnil); 1993 dirname = Fexpand_file_name (dirname, Qnil);
2006 1994
2007 GCPRO1 (dirname); 1995 GCPRO1 (dirname);
2008 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal); 1996 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal);
2009 UNGCPRO; 1997 UNGCPRO;
2010 if (!NILP (handler)) 1998 if (!NILP (handler))
2011 return (call2 (handler, Qmake_directory_internal, dirname)); 1999 return (call2 (handler, Qmake_directory_internal, dirname));
2012 2000
2013 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) 2001 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1))
2014 { 2002 {
2015 return Fsignal (Qfile_error, 2003 return Fsignal (Qfile_error,
2016 list3 (build_translated_string ("Creating directory"), 2004 list3 (build_translated_string ("Creating directory"),
2017 build_translated_string ("pathame too long"), 2005 build_translated_string ("pathame too long"),
2041 (dirname)) 2029 (dirname))
2042 { 2030 {
2043 /* This function can GC. GC checked 1997.04.06. */ 2031 /* This function can GC. GC checked 1997.04.06. */
2044 Lisp_Object handler; 2032 Lisp_Object handler;
2045 struct gcpro gcpro1; 2033 struct gcpro gcpro1;
2046 2034
2047 CHECK_STRING (dirname); 2035 CHECK_STRING (dirname);
2048 2036
2049 GCPRO1 (dirname); 2037 GCPRO1 (dirname);
2050 dirname = Fexpand_file_name (dirname, Qnil); 2038 dirname = Fexpand_file_name (dirname, Qnil);
2051 dirname = Fdirectory_file_name (dirname); 2039 dirname = Fdirectory_file_name (dirname);
2068 (filename)) 2056 (filename))
2069 { 2057 {
2070 /* This function can GC. GC checked 1997.04.06. */ 2058 /* This function can GC. GC checked 1997.04.06. */
2071 Lisp_Object handler; 2059 Lisp_Object handler;
2072 struct gcpro gcpro1; 2060 struct gcpro gcpro1;
2073 2061
2074 CHECK_STRING (filename); 2062 CHECK_STRING (filename);
2075 filename = Fexpand_file_name (filename, Qnil); 2063 filename = Fexpand_file_name (filename, Qnil);
2076 2064
2077 GCPRO1 (filename); 2065 GCPRO1 (filename);
2078 handler = Ffind_file_name_handler (filename, Qdelete_file); 2066 handler = Ffind_file_name_handler (filename, Qdelete_file);
2141 { 2129 {
2142 Lisp_Object args[3]; 2130 Lisp_Object args[3];
2143 struct gcpro ngcpro1; 2131 struct gcpro ngcpro1;
2144 int i = 1; 2132 int i = 1;
2145 2133
2146 args[0] = newname; 2134 args[0] = newname;
2147 args[1] = Qnil; args[2] = Qnil; 2135 args[1] = Qnil; args[2] = Qnil;
2148 NGCPRO1 (*args); 2136 NGCPRO1 (*args);
2149 ngcpro1.nvars = 3; 2137 ngcpro1.nvars = 3;
2150 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/') 2138 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/')
2151 args[i++] = build_string ("/"); 2139 args[i++] = build_string ("/");
2152 args[i++] = Ffile_name_nondirectory (filename); 2140 args[i++] = Ffile_name_nondirectory (filename);
2153 newname = Fconcat (i, args); 2141 newname = Fconcat (i, args);
2339 Open a network connection to PATH using LOGIN as the login string. 2327 Open a network connection to PATH using LOGIN as the login string.
2340 */ 2328 */
2341 (path, login)) 2329 (path, login))
2342 { 2330 {
2343 int netresult; 2331 int netresult;
2344 2332
2345 CHECK_STRING (path); 2333 CHECK_STRING (path);
2346 CHECK_STRING (login); 2334 CHECK_STRING (login);
2347 2335
2348 /* netunam, being a strange-o system call only used once, is not 2336 /* netunam, being a strange-o system call only used once, is not
2349 encapsulated. */ 2337 encapsulated. */
2350 { 2338 {
2351 char *path_ext; 2339 char *path_ext;
2352 char *login_ext; 2340 char *login_ext;
2353 2341
2354 GET_C_STRING_FILENAME_DATA_ALLOCA (path, path_ext); 2342 GET_C_STRING_FILENAME_DATA_ALLOCA (path, path_ext);
2355 GET_C_STRING_EXT_DATA_ALLOCA (login, FORMAT_OS, login_ext); 2343 GET_C_STRING_EXT_DATA_ALLOCA (login, FORMAT_OS, login_ext);
2356 2344
2357 netresult = netunam (path_ext, login_ext); 2345 netresult = netunam (path_ext, login_ext);
2358 } 2346 }
2359 2347
2360 if (netresult == -1) 2348 if (netresult == -1)
2361 return Qnil; 2349 return Qnil;
2453 /* This function can call lisp */ 2441 /* This function can call lisp */
2454 Lisp_Object abspath; 2442 Lisp_Object abspath;
2455 Lisp_Object handler; 2443 Lisp_Object handler;
2456 struct stat statbuf; 2444 struct stat statbuf;
2457 struct gcpro gcpro1; 2445 struct gcpro gcpro1;
2458 2446
2459 CHECK_STRING (filename); 2447 CHECK_STRING (filename);
2460 abspath = Fexpand_file_name (filename, Qnil); 2448 abspath = Fexpand_file_name (filename, Qnil);
2461 2449
2462 /* If the file name has special constructs in it, 2450 /* If the file name has special constructs in it,
2463 call the corresponding file handler. */ 2451 call the corresponding file handler. */
2482 { 2470 {
2483 /* This function can GC. GC checked 1997.04.10. */ 2471 /* This function can GC. GC checked 1997.04.10. */
2484 Lisp_Object abspath; 2472 Lisp_Object abspath;
2485 Lisp_Object handler; 2473 Lisp_Object handler;
2486 struct gcpro gcpro1; 2474 struct gcpro gcpro1;
2487 2475
2488 CHECK_STRING (filename); 2476 CHECK_STRING (filename);
2489 abspath = Fexpand_file_name (filename, Qnil); 2477 abspath = Fexpand_file_name (filename, Qnil);
2490 2478
2491 /* If the file name has special constructs in it, 2479 /* If the file name has special constructs in it,
2492 call the corresponding file handler. */ 2480 call the corresponding file handler. */
2509 /* This function can GC. GC checked 1997.04.10. */ 2497 /* This function can GC. GC checked 1997.04.10. */
2510 Lisp_Object abspath; 2498 Lisp_Object abspath;
2511 Lisp_Object handler; 2499 Lisp_Object handler;
2512 int desc; 2500 int desc;
2513 struct gcpro gcpro1; 2501 struct gcpro gcpro1;
2514 2502
2515 CHECK_STRING (filename); 2503 CHECK_STRING (filename);
2516 abspath = Fexpand_file_name (filename, Qnil); 2504 abspath = Fexpand_file_name (filename, Qnil);
2517 2505
2518 /* If the file name has special constructs in it, 2506 /* If the file name has special constructs in it,
2519 call the corresponding file handler. */ 2507 call the corresponding file handler. */
2540 /* This function can GC. GC checked 1997.04.10. */ 2528 /* This function can GC. GC checked 1997.04.10. */
2541 Lisp_Object abspath, dir; 2529 Lisp_Object abspath, dir;
2542 Lisp_Object handler; 2530 Lisp_Object handler;
2543 struct stat statbuf; 2531 struct stat statbuf;
2544 struct gcpro gcpro1; 2532 struct gcpro gcpro1;
2545 2533
2546 CHECK_STRING (filename); 2534 CHECK_STRING (filename);
2547 abspath = Fexpand_file_name (filename, Qnil); 2535 abspath = Fexpand_file_name (filename, Qnil);
2548 2536
2549 /* If the file name has special constructs in it, 2537 /* If the file name has special constructs in it,
2550 call the corresponding file handler. */ 2538 call the corresponding file handler. */
2588 int bufsize; 2576 int bufsize;
2589 int valsize; 2577 int valsize;
2590 Lisp_Object val; 2578 Lisp_Object val;
2591 Lisp_Object handler; 2579 Lisp_Object handler;
2592 struct gcpro gcpro1; 2580 struct gcpro gcpro1;
2593 2581
2594 CHECK_STRING (filename); 2582 CHECK_STRING (filename);
2595 filename = Fexpand_file_name (filename, Qnil); 2583 filename = Fexpand_file_name (filename, Qnil);
2596 2584
2597 /* If the file name has special constructs in it, 2585 /* If the file name has special constructs in it,
2598 call the corresponding file handler. */ 2586 call the corresponding file handler. */
2637 /* This function can GC. GC checked 1997.04.10. */ 2625 /* This function can GC. GC checked 1997.04.10. */
2638 Lisp_Object abspath; 2626 Lisp_Object abspath;
2639 struct stat st; 2627 struct stat st;
2640 Lisp_Object handler; 2628 Lisp_Object handler;
2641 struct gcpro gcpro1; 2629 struct gcpro gcpro1;
2642 2630
2643 GCPRO1 (current_buffer->directory); 2631 GCPRO1 (current_buffer->directory);
2644 abspath = expand_and_dir_to_file (filename, 2632 abspath = expand_and_dir_to_file (filename,
2645 current_buffer->directory); 2633 current_buffer->directory);
2646 UNGCPRO; 2634 UNGCPRO;
2647 2635
2721 /* This function can GC. GC checked 1997.04.10. */ 2709 /* This function can GC. GC checked 1997.04.10. */
2722 Lisp_Object abspath; 2710 Lisp_Object abspath;
2723 struct stat st; 2711 struct stat st;
2724 Lisp_Object handler; 2712 Lisp_Object handler;
2725 struct gcpro gcpro1; 2713 struct gcpro gcpro1;
2726 2714
2727 GCPRO1 (current_buffer->directory); 2715 GCPRO1 (current_buffer->directory);
2728 abspath = expand_and_dir_to_file (filename, 2716 abspath = expand_and_dir_to_file (filename,
2729 current_buffer->directory); 2717 current_buffer->directory);
2730 UNGCPRO; 2718 UNGCPRO;
2731 2719
2755 { 2743 {
2756 /* This function can GC. GC checked 1997.04.10. */ 2744 /* This function can GC. GC checked 1997.04.10. */
2757 Lisp_Object abspath; 2745 Lisp_Object abspath;
2758 Lisp_Object handler; 2746 Lisp_Object handler;
2759 struct gcpro gcpro1; 2747 struct gcpro gcpro1;
2760 2748
2761 GCPRO1 (current_buffer->directory); 2749 GCPRO1 (current_buffer->directory);
2762 abspath = Fexpand_file_name (filename, current_buffer->directory); 2750 abspath = Fexpand_file_name (filename, current_buffer->directory);
2763 UNGCPRO; 2751 UNGCPRO;
2764 2752
2765 CHECK_INT (mode); 2753 CHECK_INT (mode);
2786 This setting is inherited by subprocesses. 2774 This setting is inherited by subprocesses.
2787 */ 2775 */
2788 (mode)) 2776 (mode))
2789 { 2777 {
2790 CHECK_INT (mode); 2778 CHECK_INT (mode);
2791 2779
2792 umask ((~ XINT (mode)) & 0777); 2780 umask ((~ XINT (mode)) & 0777);
2793 2781
2794 return Qnil; 2782 return Qnil;
2795 } 2783 }
2796 2784
2925 curbuf was killed and if so signal an error? */ 2913 curbuf was killed and if so signal an error? */
2926 2914
2927 XSETBUFFER (curbuf, buf); 2915 XSETBUFFER (curbuf, buf);
2928 2916
2929 GCPRO5 (filename, val, visit, handler, curbuf); 2917 GCPRO5 (filename, val, visit, handler, curbuf);
2930 2918
2931 mc_count = (NILP (replace)) ? 2919 mc_count = (NILP (replace)) ?
2932 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) : 2920 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) :
2933 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf)); 2921 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf));
2934 2922
2935 speccount = specpdl_depth (); /* begin_multiple_change also adds 2923 speccount = specpdl_depth (); /* begin_multiple_change also adds
2952 CHECK_SYMBOL (used_codesys); 2940 CHECK_SYMBOL (used_codesys);
2953 #endif 2941 #endif
2954 2942
2955 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) 2943 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) )
2956 error ("Attempt to visit less than an entire file"); 2944 error ("Attempt to visit less than an entire file");
2957 2945
2958 if (!NILP (beg)) 2946 if (!NILP (beg))
2959 CHECK_INT (beg); 2947 CHECK_INT (beg);
2960 else 2948 else
2961 beg = Qzero; 2949 beg = Qzero;
2962 2950
3189 Charcount cc_inserted; 3177 Charcount cc_inserted;
3190 3178
3191 QUIT; 3179 QUIT;
3192 this_len = Lstream_read (XLSTREAM (stream), read_buf, 3180 this_len = Lstream_read (XLSTREAM (stream), read_buf,
3193 sizeof (read_buf)); 3181 sizeof (read_buf));
3194 3182
3195 if (this_len <= 0) 3183 if (this_len <= 0)
3196 { 3184 {
3197 if (this_len < 0) 3185 if (this_len < 0)
3198 saverrno = errno; 3186 saverrno = errno;
3199 break; 3187 break;
3291 } 3279 }
3292 3280
3293 /* Decode file format */ 3281 /* Decode file format */
3294 if (inserted > 0) 3282 if (inserted > 0)
3295 { 3283 {
3296 Lisp_Object insval = call3 (Qformat_decode, 3284 Lisp_Object insval = call3 (Qformat_decode,
3297 Qnil, make_int (inserted), visit); 3285 Qnil, make_int (inserted), visit);
3298 CHECK_INT (insval); 3286 CHECK_INT (insval);
3299 inserted = XINT (insval); 3287 inserted = XINT (insval);
3300 } 3288 }
3301 3289
3334 static Lisp_Object build_annotations (Lisp_Object start, Lisp_Object end); 3322 static Lisp_Object build_annotations (Lisp_Object start, Lisp_Object end);
3335 3323
3336 /* If build_annotations switched buffers, switch back to BUF. 3324 /* If build_annotations switched buffers, switch back to BUF.
3337 Kill the temporary buffer that was selected in the meantime. */ 3325 Kill the temporary buffer that was selected in the meantime. */
3338 3326
3339 static Lisp_Object 3327 static Lisp_Object
3340 build_annotations_unwind (Lisp_Object buf) 3328 build_annotations_unwind (Lisp_Object buf)
3341 { 3329 {
3342 Lisp_Object tembuf; 3330 Lisp_Object tembuf;
3343 3331
3344 if (XBUFFER (buf) == current_buffer) 3332 if (XBUFFER (buf) == current_buffer)
3423 if (NILP (handler) && STRINGP (visit)) 3411 if (NILP (handler) && STRINGP (visit))
3424 handler = Ffind_file_name_handler (visit, Qwrite_region); 3412 handler = Ffind_file_name_handler (visit, Qwrite_region);
3425 3413
3426 if (!NILP (handler)) 3414 if (!NILP (handler))
3427 { 3415 {
3428 Lisp_Object val = call8 (handler, Qwrite_region, start, end, 3416 Lisp_Object val = call8 (handler, Qwrite_region, start, end,
3429 filename, append, visit, lockname, codesys); 3417 filename, append, visit, lockname, codesys);
3430 if (visiting) 3418 if (visiting)
3431 { 3419 {
3432 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); 3420 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
3433 current_buffer->save_length = 3421 current_buffer->save_length =
3481 3469
3482 if (desc < 0) 3470 if (desc < 0)
3483 #ifndef VMS 3471 #ifndef VMS
3484 { 3472 {
3485 #ifdef DOS_NT 3473 #ifdef DOS_NT
3486 desc = open ((char *) XSTRING_DATA (fn), 3474 desc = open ((char *) XSTRING_DATA (fn),
3487 (O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type), 3475 (O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type),
3488 (S_IREAD | S_IWRITE)); 3476 (S_IREAD | S_IWRITE));
3489 #else /* not DOS_NT */ 3477 #else /* not DOS_NT */
3490 desc = creat ((char *) XSTRING_DATA (fn), 3478 desc = creat ((char *) XSTRING_DATA (fn),
3491 ((auto_saving) ? auto_save_mode_bits : 0666)); 3479 ((auto_saving) ? auto_save_mode_bits : 0666));
3492 #endif /* DOS_NT */ 3480 #endif /* DOS_NT */
3670 failure = 1; 3658 failure = 1;
3671 save_errno = errno; 3659 save_errno = errno;
3672 } 3660 }
3673 #endif 3661 #endif
3674 3662
3675 /* Spurious "file has changed on disk" warnings have been 3663 /* Spurious "file has changed on disk" warnings have been
3676 observed on Suns as well. 3664 observed on Suns as well.
3677 It seems that `close' can change the modtime, under nfs. 3665 It seems that `close' can change the modtime, under nfs.
3678 3666
3679 (This has supposedly been fixed in Sunos 4, 3667 (This has supposedly been fixed in Sunos 4,
3680 but who knows about all the other machines with NFS?) */ 3668 but who knows about all the other machines with NFS?) */
3695 build_annotations (switches back to the original current buffer 3683 build_annotations (switches back to the original current buffer
3696 as necessary). */ 3684 as necessary). */
3697 XCAR (desc_locative) = Qnil; 3685 XCAR (desc_locative) = Qnil;
3698 unbind_to (speccount, Qnil); 3686 unbind_to (speccount, Qnil);
3699 } 3687 }
3700 3688
3701 3689
3702 #ifdef VMS 3690 #ifdef VMS
3703 /* If we wrote to a temporary name and had no errors, rename to real name. */ 3691 /* If we wrote to a temporary name and had no errors, rename to real name. */
3704 if (!NILP (fname)) 3692 if (!NILP (fname))
3705 { 3693 {
3706 if (!failure) 3694 if (!failure)
3707 { 3695 {
3708 failure = (rename ((char *) XSTRING_DATA (fn), 3696 failure = (rename ((char *) XSTRING_DATA (fn),
3709 (char *) XSTRING_DATA (fname)) 3697 (char *) XSTRING_DATA (fname))
3710 != 0); 3698 != 0);
3711 save_errno = errno; 3699 save_errno = errno;
3712 } 3700 }
3713 fn = fname; 3701 fn = fname;
3728 next attempt to save. */ 3716 next attempt to save. */
3729 if (visiting) 3717 if (visiting)
3730 current_buffer->modtime = st.st_mtime; 3718 current_buffer->modtime = st.st_mtime;
3731 3719
3732 if (failure) 3720 if (failure)
3733 error ("IO error writing %s: %s", 3721 error ("IO error writing %s: %s",
3734 XSTRING_DATA (fn), 3722 XSTRING_DATA (fn),
3735 strerror (save_errno)); 3723 strerror (save_errno));
3736 3724
3737 if (visiting) 3725 if (visiting)
3738 { 3726 {
3739 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); 3727 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
3758 3746
3759 fsp = Ffile_symlink_p (fn); 3747 fsp = Ffile_symlink_p (fn);
3760 if (NILP (fsp)) 3748 if (NILP (fsp))
3761 message ("Wrote %s", XSTRING_DATA (fn)); 3749 message ("Wrote %s", XSTRING_DATA (fn));
3762 else 3750 else
3763 message ("Wrote %s (symlink to %s)", 3751 message ("Wrote %s (symlink to %s)",
3764 XSTRING_DATA (fn), XSTRING_DATA (fsp)); 3752 XSTRING_DATA (fn), XSTRING_DATA (fsp));
3765 UNGCPRO; 3753 UNGCPRO;
3766 } 3754 }
3767 } 3755 }
3768 return Qnil; 3756 return Qnil;
3904 { 3892 {
3905 while (pos != nextpos) 3893 while (pos != nextpos)
3906 { 3894 {
3907 /* Otherwise there is no point to that. Just go in batches. */ 3895 /* Otherwise there is no point to that. Just go in batches. */
3908 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE); 3896 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE);
3909 3897
3910 chunk = Lstream_read (instr, largebuf, chunk); 3898 chunk = Lstream_read (instr, largebuf, chunk);
3911 if (chunk < 0) 3899 if (chunk < 0)
3912 return -1; 3900 return -1;
3913 if (chunk == 0) /* EOF */ 3901 if (chunk == 0) /* EOF */
3914 break; 3902 break;
4090 { 4078 {
4091 Lisp_Object filename; 4079 Lisp_Object filename;
4092 struct stat st; 4080 struct stat st;
4093 Lisp_Object handler; 4081 Lisp_Object handler;
4094 struct gcpro gcpro1, gcpro2, gcpro3; 4082 struct gcpro gcpro1, gcpro2, gcpro3;
4095 4083
4096 GCPRO3 (filename, time_list, current_buffer->filename); 4084 GCPRO3 (filename, time_list, current_buffer->filename);
4097 filename = Fexpand_file_name (current_buffer->filename, Qnil); 4085 filename = Fexpand_file_name (current_buffer->filename, Qnil);
4098 4086
4099 /* If the file name has special constructs in it, 4087 /* If the file name has special constructs in it,
4100 call the corresponding file handler. */ 4088 call the corresponding file handler. */
4109 4097
4110 return Qnil; 4098 return Qnil;
4111 } 4099 }
4112 4100
4113 DEFUN ("set-buffer-modtime", Fset_buffer_modtime, 1, 2, 0, /* 4101 DEFUN ("set-buffer-modtime", Fset_buffer_modtime, 1, 2, 0, /*
4114 Update BUFFER's recorded modification time from the associated 4102 Update BUFFER's recorded modification time from the associated
4115 file's modtime, if there is an associated file. If not, use the 4103 file's modtime, if there is an associated file. If not, use the
4116 current time. In either case, if the optional arg TIME is supplied, 4104 current time. In either case, if the optional arg TIME is supplied,
4117 it will be used if it is either an integer or a cons of two integers. 4105 it will be used if it is either an integer or a cons of two integers.
4118 */ 4106 */
4119 (buf, in_time)) 4107 (buf, in_time))
4120 { 4108 {
4131 { 4119 {
4132 time_to_use = XINT (in_time); 4120 time_to_use = XINT (in_time);
4133 set_time_to_use = 1; 4121 set_time_to_use = 1;
4134 } 4122 }
4135 else if ((CONSP (in_time)) && 4123 else if ((CONSP (in_time)) &&
4136 (INTP (Fcar (in_time))) && 4124 (INTP (Fcar (in_time))) &&
4137 (INTP (Fcdr (in_time)))) 4125 (INTP (Fcdr (in_time))))
4138 { 4126 {
4139 time_t the_time; 4127 time_t the_time;
4140 lisp_to_time (in_time, &the_time); 4128 lisp_to_time (in_time, &the_time);
4141 time_to_use = (unsigned long) the_time; 4129 time_to_use = (unsigned long) the_time;
4182 time_to_use = time ((time_t *) 0); 4170 time_to_use = time ((time_t *) 0);
4183 } 4171 }
4184 } 4172 }
4185 4173
4186 XBUFFER (buf)->modtime = time_to_use; 4174 XBUFFER (buf)->modtime = time_to_use;
4187 4175
4188 return Qnil; 4176 return Qnil;
4189 } 4177 }
4190 4178
4191 4179
4192 static Lisp_Object 4180 static Lisp_Object
4354 b = XBUFFER (buf); 4342 b = XBUFFER (buf);
4355 4343
4356 if (!GC_NILP (current_only) 4344 if (!GC_NILP (current_only)
4357 && b != current_buffer) 4345 && b != current_buffer)
4358 continue; 4346 continue;
4359 4347
4360 /* Don't auto-save indirect buffers. 4348 /* Don't auto-save indirect buffers.
4361 The base buffer takes care of it. */ 4349 The base buffer takes care of it. */
4362 if (b->base_buffer) 4350 if (b->base_buffer)
4363 continue; 4351 continue;
4364 4352
4445 auto save name. */ 4433 auto save name. */
4446 if (listdesc >= 0) 4434 if (listdesc >= 0)
4447 { 4435 {
4448 Extbyte *auto_save_file_name_ext; 4436 Extbyte *auto_save_file_name_ext;
4449 Extcount auto_save_file_name_ext_len; 4437 Extcount auto_save_file_name_ext_len;
4450 4438
4451 GET_STRING_FILENAME_DATA_ALLOCA 4439 GET_STRING_FILENAME_DATA_ALLOCA
4452 (b->auto_save_file_name, 4440 (b->auto_save_file_name,
4453 auto_save_file_name_ext, 4441 auto_save_file_name_ext,
4454 auto_save_file_name_ext_len); 4442 auto_save_file_name_ext_len);
4455 if (!NILP (b->filename)) 4443 if (!NILP (b->filename))
4456 { 4444 {
4457 Extbyte *filename_ext; 4445 Extbyte *filename_ext;
4458 Extcount filename_ext_len; 4446 Extcount filename_ext_len;
4459 4447
4460 GET_STRING_FILENAME_DATA_ALLOCA (b->filename, 4448 GET_STRING_FILENAME_DATA_ALLOCA (b->filename,
4461 filename_ext, 4449 filename_ext,
4462 filename_ext_len); 4450 filename_ext_len);
4463 write (listdesc, filename_ext, filename_ext_len); 4451 write (listdesc, filename_ext, filename_ext_len);
4464 } 4452 }
4489 if (!BUFFER_LIVE_P (XBUFFER (old))) 4477 if (!BUFFER_LIVE_P (XBUFFER (old)))
4490 XSETBUFFER (old, current_buffer); 4478 XSETBUFFER (old, current_buffer);
4491 4479
4492 set_buffer_internal (XBUFFER (old)); 4480 set_buffer_internal (XBUFFER (old));
4493 auto_saved++; 4481 auto_saved++;
4494 4482
4495 /* Handler killed their own buffer! */ 4483 /* Handler killed their own buffer! */
4496 if (!BUFFER_LIVE_P(b)) 4484 if (!BUFFER_LIVE_P(b))
4497 continue; 4485 continue;
4498 4486
4499 b->auto_save_modified = BUF_MODIFF (b); 4487 b->auto_save_modified = BUF_MODIFF (b);