comparison src/fileio.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 697ef44129c6
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
69 } while (0) 69 } while (0)
70 #define IS_DRIVE(x) isalpha (x) 70 #define IS_DRIVE(x) isalpha (x)
71 /* Need to lower-case the drive letter, or else expanded 71 /* Need to lower-case the drive letter, or else expanded
72 filenames will sometimes compare inequal, because 72 filenames will sometimes compare inequal, because
73 `expand-file-name' doesn't always down-case the drive letter. */ 73 `expand-file-name' doesn't always down-case the drive letter. */
74 #define DRIVE_LETTER(x) (tolower (x)) 74 #define DRIVE_LETTER(x) tolower (x)
75 #endif /* WINDOWSNT */ 75 #endif /* WINDOWSNT */
76 76
77 int lisp_to_time (Lisp_Object, time_t *); 77 int lisp_to_time (Lisp_Object, time_t *);
78 Lisp_Object time_to_lisp (time_t); 78 Lisp_Object time_to_lisp (time_t);
79 79
106 106
107 /* File name in which we write a list of all our auto save files. */ 107 /* File name in which we write a list of all our auto save files. */
108 Lisp_Object Vauto_save_list_file_name; 108 Lisp_Object Vauto_save_list_file_name;
109 109
110 int disable_auto_save_when_buffer_shrinks; 110 int disable_auto_save_when_buffer_shrinks;
111
112 Lisp_Object Qfile_name_handler_alist;
113 111
114 Lisp_Object Vdirectory_sep_char; 112 Lisp_Object Vdirectory_sep_char;
115 113
116 /* These variables describe handlers that have "already" had a chance 114 /* These variables describe handlers that have "already" had a chance
117 to handle the current operation. 115 to handle the current operation.
1301 if (!NILP (handler)) 1299 if (!NILP (handler))
1302 return call2_check_string (handler, Qfile_truename, expanded_name); 1300 return call2_check_string (handler, Qfile_truename, expanded_name);
1303 1301
1304 { 1302 {
1305 char resolved_path[MAXPATHLEN]; 1303 char resolved_path[MAXPATHLEN];
1306 char path[MAXPATHLEN]; 1304 Extbyte *path;
1307 char *p = path; 1305 Extbyte *p;
1308 int elen = XSTRING_LENGTH (expanded_name); 1306 Extcount elen = XSTRING_LENGTH (expanded_name);
1309 1307
1310 if (elen >= countof (path)) 1308 GET_STRING_FILENAME_DATA_ALLOCA (expanded_name,path,elen);
1309 p = path;
1310 if (elen > MAXPATHLEN)
1311 goto toolong; 1311 goto toolong;
1312 1312
1313 memcpy (path, XSTRING_DATA (expanded_name), elen + 1);
1314 /* memset (resolved_path, 0, sizeof (resolved_path)); */
1315
1316 /* Try doing it all at once. */ 1313 /* Try doing it all at once. */
1317 /* !!#### Does realpath() Mule-encapsulate? */ 1314 /* !! Does realpath() Mule-encapsulate?
1318 if (!xrealpath (path, resolved_path)) 1315 Answer: Nope! So we do it above */
1316 if (!xrealpath ((char *) path, resolved_path))
1319 { 1317 {
1320 /* Didn't resolve it -- have to do it one component at a time. */ 1318 /* Didn't resolve it -- have to do it one component at a time. */
1321 /* "realpath" is a typically useless, stupid un*x piece of crap. 1319 /* "realpath" is a typically useless, stupid un*x piece of crap.
1322 It claims to return a useful value in the "error" case, but since 1320 It claims to return a useful value in the "error" case, but since
1323 there is no indication provided of how far along the pathname 1321 there is no indication provided of how far along the pathname
1324 the function went before erring, there is no way to use the 1322 the function went before erring, there is no way to use the
1325 partial result returned. What a piece of junk. */ 1323 partial result returned. What a piece of junk. */
1326 for (;;) 1324 for (;;)
1327 { 1325 {
1328 p = (char *) memchr (p + 1, '/', elen - (p + 1 - path)); 1326 p = (Extbyte *) memchr (p + 1, '/', elen - (p + 1 - path));
1329 if (p) 1327 if (p)
1330 *p = 0; 1328 *p = 0;
1331 1329
1332 /* memset (resolved_path, 0, sizeof (resolved_path)); */ 1330 /* memset (resolved_path, 0, sizeof (resolved_path)); */
1333 if (xrealpath (path, resolved_path)) 1331 if (xrealpath ((char *) path, resolved_path))
1334 { 1332 {
1335 if (p) 1333 if (p)
1336 *p = '/'; 1334 *p = '/';
1337 else 1335 else
1338 break; 1336 break;
1996 if (errno == EXDEV) 1994 if (errno == EXDEV)
1997 { 1995 {
1998 Fcopy_file (filename, newname, 1996 Fcopy_file (filename, newname,
1999 /* We have already prompted if it was an integer, 1997 /* We have already prompted if it was an integer,
2000 so don't have copy-file prompt again. */ 1998 so don't have copy-file prompt again. */
2001 ((NILP (ok_if_already_exists)) ? Qnil : Qt), 1999 (NILP (ok_if_already_exists) ? Qnil : Qt),
2002 Qt); 2000 Qt);
2003 Fdelete_file (filename); 2001 Fdelete_file (filename);
2004 } 2002 }
2005 else 2003 else
2006 { 2004 {
3907 if (minibuf_level != 0 || preparing_for_armageddon) 3905 if (minibuf_level != 0 || preparing_for_armageddon)
3908 no_message = Qt; 3906 no_message = Qt;
3909 3907
3910 run_hook (Qauto_save_hook); 3908 run_hook (Qauto_save_hook);
3911 3909
3912 if (GC_STRINGP (Vauto_save_list_file_name)) 3910 if (STRINGP (Vauto_save_list_file_name))
3913 listfile = condition_case_1 (Qt, 3911 listfile = condition_case_1 (Qt,
3914 auto_save_expand_name, 3912 auto_save_expand_name,
3915 Vauto_save_list_file_name, 3913 Vauto_save_list_file_name,
3916 auto_save_expand_name_error, Qnil); 3914 auto_save_expand_name_error, Qnil);
3917 3915
3926 autosave perfectly ordinary files because it couldn't handle some 3924 autosave perfectly ordinary files because it couldn't handle some
3927 ange-ftp'd file. */ 3925 ange-ftp'd file. */
3928 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) 3926 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++)
3929 { 3927 {
3930 for (tail = Vbuffer_alist; 3928 for (tail = Vbuffer_alist;
3931 GC_CONSP (tail); 3929 CONSP (tail);
3932 tail = XCDR (tail)) 3930 tail = XCDR (tail))
3933 { 3931 {
3934 buf = XCDR (XCAR (tail)); 3932 buf = XCDR (XCAR (tail));
3935 b = XBUFFER (buf); 3933 b = XBUFFER (buf);
3936 3934
3937 if (!GC_NILP (current_only) 3935 if (!NILP (current_only)
3938 && b != current_buffer) 3936 && b != current_buffer)
3939 continue; 3937 continue;
3940 3938
3941 /* Don't auto-save indirect buffers. 3939 /* Don't auto-save indirect buffers.
3942 The base buffer takes care of it. */ 3940 The base buffer takes care of it. */
3944 continue; 3942 continue;
3945 3943
3946 /* Check for auto save enabled 3944 /* Check for auto save enabled
3947 and file changed since last auto save 3945 and file changed since last auto save
3948 and file changed since last real save. */ 3946 and file changed since last real save. */
3949 if (GC_STRINGP (b->auto_save_file_name) 3947 if (STRINGP (b->auto_save_file_name)
3950 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b) 3948 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)
3951 && b->auto_save_modified < BUF_MODIFF (b) 3949 && b->auto_save_modified < BUF_MODIFF (b)
3952 /* -1 means we've turned off autosaving for a while--see below. */ 3950 /* -1 means we've turned off autosaving for a while--see below. */
3953 && XINT (b->saved_size) >= 0 3951 && XINT (b->saved_size) >= 0
3954 && (do_handled_files 3952 && (do_handled_files
3989 if (!gc_in_progress) 3987 if (!gc_in_progress)
3990 Fsleep_for (make_int (1)); 3988 Fsleep_for (make_int (1));
3991 continue; 3989 continue;
3992 } 3990 }
3993 set_buffer_internal (b); 3991 set_buffer_internal (b);
3994 if (!auto_saved && GC_NILP (no_message)) 3992 if (!auto_saved && NILP (no_message))
3995 { 3993 {
3996 static CONST unsigned char *msg 3994 static CONST unsigned char *msg
3997 = (CONST unsigned char *) "Auto-saving..."; 3995 = (CONST unsigned char *) "Auto-saving...";
3998 echo_area_message (selected_frame (), msg, Qnil, 3996 echo_area_message (selected_frame (), msg, Qnil,
3999 0, strlen ((CONST char *) msg), 3997 0, strlen ((CONST char *) msg),
4001 } 3999 }
4002 4000
4003 /* Open the auto-save list file, if necessary. 4001 /* Open the auto-save list file, if necessary.
4004 We only do this now so that the file only exists 4002 We only do this now so that the file only exists
4005 if we actually auto-saved any files. */ 4003 if we actually auto-saved any files. */
4006 if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0) 4004 if (!auto_saved && STRINGP (listfile) && listdesc < 0)
4007 { 4005 {
4008 listdesc = open ((char *) XSTRING_DATA (listfile), 4006 listdesc = open ((char *) XSTRING_DATA (listfile),
4009 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, 4007 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
4010 CREAT_MODE); 4008 CREAT_MODE);
4011 4009
4090 4088
4091 /* If we didn't save anything into the listfile, remove the old 4089 /* If we didn't save anything into the listfile, remove the old
4092 one because nothing needed to be auto-saved. Do this afterwards 4090 one because nothing needed to be auto-saved. Do this afterwards
4093 rather than before in case we get a crash attempting to autosave 4091 rather than before in case we get a crash attempting to autosave
4094 (in that case we'd still want the old one around). */ 4092 (in that case we'd still want the old one around). */
4095 if (listdesc < 0 && !auto_saved && GC_STRINGP (listfile)) 4093 if (listdesc < 0 && !auto_saved && STRINGP (listfile))
4096 unlink ((char *) XSTRING_DATA (listfile)); 4094 unlink ((char *) XSTRING_DATA (listfile));
4097 4095
4098 /* Show "...done" only if the echo area would otherwise be empty. */ 4096 /* Show "...done" only if the echo area would otherwise be empty. */
4099 if (auto_saved && NILP (no_message) 4097 if (auto_saved && NILP (no_message)
4100 && NILP (clear_echo_area (selected_frame (), Qauto_saving, 0))) 4098 && NILP (clear_echo_area (selected_frame (), Qauto_saving, 0)))
4178 defsymbol (&Qwrite_region, "write-region"); 4176 defsymbol (&Qwrite_region, "write-region");
4179 defsymbol (&Qverify_visited_file_modtime, "verify-visited-file-modtime"); 4177 defsymbol (&Qverify_visited_file_modtime, "verify-visited-file-modtime");
4180 defsymbol (&Qset_visited_file_modtime, "set-visited-file-modtime"); 4178 defsymbol (&Qset_visited_file_modtime, "set-visited-file-modtime");
4181 defsymbol (&Qcar_less_than_car, "car-less-than-car"); /* Vomitous! */ 4179 defsymbol (&Qcar_less_than_car, "car-less-than-car"); /* Vomitous! */
4182 4180
4183 defsymbol (&Qfile_name_handler_alist, "file-name-handler-alist");
4184 defsymbol (&Qauto_save_hook, "auto-save-hook"); 4181 defsymbol (&Qauto_save_hook, "auto-save-hook");
4185 defsymbol (&Qauto_save_error, "auto-save-error"); 4182 defsymbol (&Qauto_save_error, "auto-save-error");
4186 defsymbol (&Qauto_saving, "auto-saving"); 4183 defsymbol (&Qauto_saving, "auto-saving");
4187 4184
4188 defsymbol (&Qformat_decode, "format-decode"); 4185 defsymbol (&Qformat_decode, "format-decode");