aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c109
1 files changed, 57 insertions, 52 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 18e9dbe9680..5d33fb93878 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -178,7 +178,7 @@ report_file_error (const char *string, Lisp_Object data)
178 178
179 str = SSDATA (errstring); 179 str = SSDATA (errstring);
180 c = STRING_CHAR ((unsigned char *) str); 180 c = STRING_CHAR ((unsigned char *) str);
181 Faset (errstring, make_number (0), make_number (DOWNCASE (c))); 181 Faset (errstring, make_number (0), make_number (downcase (c)));
182 } 182 }
183 183
184 xsignal (Qfile_error, 184 xsignal (Qfile_error,
@@ -433,8 +433,8 @@ get a current directory to run processes in. */)
433} 433}
434 434
435 435
436char * 436static char *
437file_name_as_directory (char *out, char *in) 437file_name_as_directory (char *out, const char *in)
438{ 438{
439 int size = strlen (in) - 1; 439 int size = strlen (in) - 1;
440 440
@@ -496,7 +496,7 @@ For a Unix-syntax file name, just appends a slash. */)
496 * Value is nonzero if the string output is different from the input. 496 * Value is nonzero if the string output is different from the input.
497 */ 497 */
498 498
499int 499static int
500directory_file_name (char *src, char *dst) 500directory_file_name (char *src, char *dst)
501{ 501{
502 long slen; 502 long slen;
@@ -728,7 +728,8 @@ filesystem tree, not (expand-file-name ".." dirname). */)
728{ 728{
729 /* These point to SDATA and need to be careful with string-relocation 729 /* These point to SDATA and need to be careful with string-relocation
730 during GC (via DECODE_FILE). */ 730 during GC (via DECODE_FILE). */
731 char *nm, *newdir; 731 char *nm;
732 const char *newdir;
732 /* This should only point to alloca'd data. */ 733 /* This should only point to alloca'd data. */
733 char *target; 734 char *target;
734 735
@@ -1013,21 +1014,23 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1013 if (!newdir && drive) 1014 if (!newdir && drive)
1014 { 1015 {
1015 /* Get default directory if needed to make nm absolute. */ 1016 /* Get default directory if needed to make nm absolute. */
1017 char *adir = NULL;
1016 if (!IS_DIRECTORY_SEP (nm[0])) 1018 if (!IS_DIRECTORY_SEP (nm[0]))
1017 { 1019 {
1018 newdir = alloca (MAXPATHLEN + 1); 1020 adir = alloca (MAXPATHLEN + 1);
1019 if (!getdefdir (toupper (drive) - 'A' + 1, newdir)) 1021 if (!getdefdir (toupper (drive) - 'A' + 1, adir))
1020 newdir = NULL; 1022 adir = NULL;
1021 } 1023 }
1022 if (!newdir) 1024 if (!adir)
1023 { 1025 {
1024 /* Either nm starts with /, or drive isn't mounted. */ 1026 /* Either nm starts with /, or drive isn't mounted. */
1025 newdir = alloca (4); 1027 adir = alloca (4);
1026 newdir[0] = DRIVE_LETTER (drive); 1028 adir[0] = DRIVE_LETTER (drive);
1027 newdir[1] = ':'; 1029 adir[1] = ':';
1028 newdir[2] = '/'; 1030 adir[2] = '/';
1029 newdir[3] = 0; 1031 adir[3] = 0;
1030 } 1032 }
1033 newdir = adir;
1031 } 1034 }
1032#endif /* DOS_NT */ 1035#endif /* DOS_NT */
1033 1036
@@ -1074,7 +1077,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1074 when we have pointers into lisp strings, we accomplish this 1077 when we have pointers into lisp strings, we accomplish this
1075 indirectly by prepending newdir to nm if necessary, and using 1078 indirectly by prepending newdir to nm if necessary, and using
1076 cwd (or the wd of newdir's drive) as the new newdir. */ 1079 cwd (or the wd of newdir's drive) as the new newdir. */
1077 1080 char *adir;
1078 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) 1081 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1]))
1079 { 1082 {
1080 drive = (unsigned char) newdir[0]; 1083 drive = (unsigned char) newdir[0];
@@ -1087,14 +1090,15 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1087 strcat (tmp, nm); 1090 strcat (tmp, nm);
1088 nm = tmp; 1091 nm = tmp;
1089 } 1092 }
1090 newdir = alloca (MAXPATHLEN + 1); 1093 adir = alloca (MAXPATHLEN + 1);
1091 if (drive) 1094 if (drive)
1092 { 1095 {
1093 if (!getdefdir (toupper (drive) - 'A' + 1, newdir)) 1096 if (!getdefdir (toupper (drive) - 'A' + 1, adir))
1094 newdir = "/"; 1097 newdir = "/";
1095 } 1098 }
1096 else 1099 else
1097 getwd (newdir); 1100 getwd (adir);
1101 newdir = adir;
1098 } 1102 }
1099 1103
1100 /* Strip off drive name from prefix, if present. */ 1104 /* Strip off drive name from prefix, if present. */
@@ -1111,13 +1115,13 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1111#ifdef WINDOWSNT 1115#ifdef WINDOWSNT
1112 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) 1116 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]))
1113 { 1117 {
1114 char *p; 1118 char *adir = strcpy (alloca (strlen (newdir) + 1), newdir);
1115 newdir = strcpy (alloca (strlen (newdir) + 1), newdir); 1119 char *p = adir + 2;
1116 p = newdir + 2;
1117 while (*p && !IS_DIRECTORY_SEP (*p)) p++; 1120 while (*p && !IS_DIRECTORY_SEP (*p)) p++;
1118 p++; 1121 p++;
1119 while (*p && !IS_DIRECTORY_SEP (*p)) p++; 1122 while (*p && !IS_DIRECTORY_SEP (*p)) p++;
1120 *p = 0; 1123 *p = 0;
1124 newdir = adir;
1121 } 1125 }
1122 else 1126 else
1123#endif 1127#endif
@@ -1734,7 +1738,7 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir)
1734 1738
1735 If QUICK is nonzero, we ask for y or n, not yes or no. */ 1739 If QUICK is nonzero, we ask for y or n, not yes or no. */
1736 1740
1737void 1741static void
1738barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring, 1742barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring,
1739 int interactive, struct stat *statptr, int quick) 1743 int interactive, struct stat *statptr, int quick)
1740{ 1744{
@@ -2041,7 +2045,6 @@ DEFUN ("delete-directory-internal", Fdelete_directory_internal,
2041 (Lisp_Object directory) 2045 (Lisp_Object directory)
2042{ 2046{
2043 const char *dir; 2047 const char *dir;
2044 Lisp_Object handler;
2045 Lisp_Object encoded_dir; 2048 Lisp_Object encoded_dir;
2046 2049
2047 CHECK_STRING (directory); 2050 CHECK_STRING (directory);
@@ -2753,7 +2756,7 @@ if file does not exist, is not accessible, or SELinux is disabled */)
2753#if HAVE_LIBSELINUX 2756#if HAVE_LIBSELINUX
2754 if (is_selinux_enabled ()) 2757 if (is_selinux_enabled ())
2755 { 2758 {
2756 conlength = lgetfilecon (SDATA (absname), &con); 2759 conlength = lgetfilecon (SSDATA (absname), &con);
2757 if (conlength > 0) 2760 if (conlength > 0)
2758 { 2761 {
2759 context = context_new (con); 2762 context = context_new (con);
@@ -2808,34 +2811,35 @@ is disabled. */)
2808 if (is_selinux_enabled ()) 2811 if (is_selinux_enabled ())
2809 { 2812 {
2810 /* Get current file context. */ 2813 /* Get current file context. */
2811 conlength = lgetfilecon (SDATA (encoded_absname), &con); 2814 conlength = lgetfilecon (SSDATA (encoded_absname), &con);
2812 if (conlength > 0) 2815 if (conlength > 0)
2813 { 2816 {
2814 parsed_con = context_new (con); 2817 parsed_con = context_new (con);
2815 /* Change the parts defined in the parameter.*/ 2818 /* Change the parts defined in the parameter.*/
2816 if (STRINGP (user)) 2819 if (STRINGP (user))
2817 { 2820 {
2818 if (context_user_set (parsed_con, SDATA (user))) 2821 if (context_user_set (parsed_con, SSDATA (user)))
2819 error ("Doing context_user_set"); 2822 error ("Doing context_user_set");
2820 } 2823 }
2821 if (STRINGP (role)) 2824 if (STRINGP (role))
2822 { 2825 {
2823 if (context_role_set (parsed_con, SDATA (role))) 2826 if (context_role_set (parsed_con, SSDATA (role)))
2824 error ("Doing context_role_set"); 2827 error ("Doing context_role_set");
2825 } 2828 }
2826 if (STRINGP (type)) 2829 if (STRINGP (type))
2827 { 2830 {
2828 if (context_type_set (parsed_con, SDATA (type))) 2831 if (context_type_set (parsed_con, SSDATA (type)))
2829 error ("Doing context_type_set"); 2832 error ("Doing context_type_set");
2830 } 2833 }
2831 if (STRINGP (range)) 2834 if (STRINGP (range))
2832 { 2835 {
2833 if (context_range_set (parsed_con, SDATA (range))) 2836 if (context_range_set (parsed_con, SSDATA (range)))
2834 error ("Doing context_range_set"); 2837 error ("Doing context_range_set");
2835 } 2838 }
2836 2839
2837 /* Set the modified context back to the file. */ 2840 /* Set the modified context back to the file. */
2838 fail = lsetfilecon (SDATA (encoded_absname), context_str (parsed_con)); 2841 fail = lsetfilecon (SSDATA (encoded_absname),
2842 context_str (parsed_con));
2839 if (fail) 2843 if (fail)
2840 report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil)); 2844 report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil));
2841 2845
@@ -2937,19 +2941,19 @@ The value is an integer. */)
2937 2941
2938 2942
2939DEFUN ("set-file-times", Fset_file_times, Sset_file_times, 1, 2, 0, 2943DEFUN ("set-file-times", Fset_file_times, Sset_file_times, 1, 2, 0,
2940 doc: /* Set times of file FILENAME to TIME. 2944 doc: /* Set times of file FILENAME to TIMESTAMP.
2941Set both access and modification times. 2945Set both access and modification times.
2942Return t on success, else nil. 2946Return t on success, else nil.
2943Use the current time if TIME is nil. TIME is in the format of 2947Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of
2944`current-time'. */) 2948`current-time'. */)
2945 (Lisp_Object filename, Lisp_Object time) 2949 (Lisp_Object filename, Lisp_Object timestamp)
2946{ 2950{
2947 Lisp_Object absname, encoded_absname; 2951 Lisp_Object absname, encoded_absname;
2948 Lisp_Object handler; 2952 Lisp_Object handler;
2949 time_t sec; 2953 time_t sec;
2950 int usec; 2954 int usec;
2951 2955
2952 if (! lisp_time_argument (time, &sec, &usec)) 2956 if (! lisp_time_argument (timestamp, &sec, &usec))
2953 error ("Invalid time specification"); 2957 error ("Invalid time specification");
2954 2958
2955 absname = Fexpand_file_name (filename, BVAR (current_buffer, directory)); 2959 absname = Fexpand_file_name (filename, BVAR (current_buffer, directory));
@@ -2958,7 +2962,7 @@ Use the current time if TIME is nil. TIME is in the format of
2958 call the corresponding file handler. */ 2962 call the corresponding file handler. */
2959 handler = Ffind_file_name_handler (absname, Qset_file_times); 2963 handler = Ffind_file_name_handler (absname, Qset_file_times);
2960 if (!NILP (handler)) 2964 if (!NILP (handler))
2961 return call3 (handler, Qset_file_times, absname, time); 2965 return call3 (handler, Qset_file_times, absname, timestamp);
2962 2966
2963 encoded_absname = ENCODE_FILE (absname); 2967 encoded_absname = ENCODE_FILE (absname);
2964 2968
@@ -3354,13 +3358,13 @@ variable `last-coding-system-used' to the coding system actually used. */)
3354 else if (nread > 0) 3358 else if (nread > 0)
3355 { 3359 {
3356 struct buffer *prev = current_buffer; 3360 struct buffer *prev = current_buffer;
3357 Lisp_Object buffer; 3361 Lisp_Object workbuf;
3358 struct buffer *buf; 3362 struct buffer *buf;
3359 3363
3360 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3364 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
3361 3365
3362 buffer = Fget_buffer_create (build_string (" *code-converting-work*")); 3366 workbuf = Fget_buffer_create (build_string (" *code-converting-work*"));
3363 buf = XBUFFER (buffer); 3367 buf = XBUFFER (workbuf);
3364 3368
3365 delete_all_overlays (buf); 3369 delete_all_overlays (buf);
3366 BVAR (buf, directory) = BVAR (current_buffer, directory); 3370 BVAR (buf, directory) = BVAR (current_buffer, directory);
@@ -3872,7 +3876,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3872 3876
3873 if (not_regular) 3877 if (not_regular)
3874 { 3878 {
3875 Lisp_Object val; 3879 Lisp_Object nbytes;
3876 3880
3877 /* Maybe make more room. */ 3881 /* Maybe make more room. */
3878 if (gap_size < trytry) 3882 if (gap_size < trytry)
@@ -3887,15 +3891,16 @@ variable `last-coding-system-used' to the coding system actually used. */)
3887 non_regular_fd = fd; 3891 non_regular_fd = fd;
3888 non_regular_inserted = inserted; 3892 non_regular_inserted = inserted;
3889 non_regular_nbytes = trytry; 3893 non_regular_nbytes = trytry;
3890 val = internal_condition_case_1 (read_non_regular, Qnil, Qerror, 3894 nbytes = internal_condition_case_1 (read_non_regular,
3891 read_non_regular_quit); 3895 Qnil, Qerror,
3892 if (NILP (val)) 3896 read_non_regular_quit);
3897 if (NILP (nbytes))
3893 { 3898 {
3894 read_quit = 1; 3899 read_quit = 1;
3895 break; 3900 break;
3896 } 3901 }
3897 3902
3898 this = XINT (val); 3903 this = XINT (nbytes);
3899 } 3904 }
3900 else 3905 else
3901 { 3906 {
@@ -3986,7 +3991,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3986 care of marker adjustment. By this way, we can run Lisp 3991 care of marker adjustment. By this way, we can run Lisp
3987 program safely before decoding the inserted text. */ 3992 program safely before decoding the inserted text. */
3988 Lisp_Object unwind_data; 3993 Lisp_Object unwind_data;
3989 int count = SPECPDL_INDEX (); 3994 int count1 = SPECPDL_INDEX ();
3990 3995
3991 unwind_data = Fcons (BVAR (current_buffer, enable_multibyte_characters), 3996 unwind_data = Fcons (BVAR (current_buffer, enable_multibyte_characters),
3992 Fcons (BVAR (current_buffer, undo_list), 3997 Fcons (BVAR (current_buffer, undo_list),
@@ -4013,7 +4018,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
4013 if (CONSP (coding_system)) 4018 if (CONSP (coding_system))
4014 coding_system = XCAR (coding_system); 4019 coding_system = XCAR (coding_system);
4015 } 4020 }
4016 unbind_to (count, Qnil); 4021 unbind_to (count1, Qnil);
4017 inserted = Z_BYTE - BEG_BYTE; 4022 inserted = Z_BYTE - BEG_BYTE;
4018 } 4023 }
4019 4024
@@ -4116,7 +4121,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
4116 if (inserted > 0) 4121 if (inserted > 0)
4117 { 4122 {
4118 /* Don't run point motion or modification hooks when decoding. */ 4123 /* Don't run point motion or modification hooks when decoding. */
4119 int count = SPECPDL_INDEX (); 4124 int count1 = SPECPDL_INDEX ();
4120 EMACS_INT old_inserted = inserted; 4125 EMACS_INT old_inserted = inserted;
4121 specbind (Qinhibit_point_motion_hooks, Qt); 4126 specbind (Qinhibit_point_motion_hooks, Qt);
4122 specbind (Qinhibit_modification_hooks, Qt); 4127 specbind (Qinhibit_modification_hooks, Qt);
@@ -4228,7 +4233,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
4228 Otherwise start with an empty undo_list. */ 4233 Otherwise start with an empty undo_list. */
4229 BVAR (current_buffer, undo_list) = EQ (old_undo, Qt) ? Qt : Qnil; 4234 BVAR (current_buffer, undo_list) = EQ (old_undo, Qt) ? Qt : Qnil;
4230 4235
4231 unbind_to (count, Qnil); 4236 unbind_to (count1, Qnil);
4232 } 4237 }
4233 4238
4234 /* Call after-change hooks for the inserted text, aside from the case 4239 /* Call after-change hooks for the inserted text, aside from the case
@@ -5059,8 +5064,8 @@ An argument specifies the modification time value to use
5059 return Qnil; 5064 return Qnil;
5060} 5065}
5061 5066
5062Lisp_Object 5067static Lisp_Object
5063auto_save_error (Lisp_Object error) 5068auto_save_error (Lisp_Object error_val)
5064{ 5069{
5065 Lisp_Object args[3], msg; 5070 Lisp_Object args[3], msg;
5066 int i, nbytes; 5071 int i, nbytes;
@@ -5074,7 +5079,7 @@ auto_save_error (Lisp_Object error)
5074 5079
5075 args[0] = build_string ("Auto-saving %s: %s"); 5080 args[0] = build_string ("Auto-saving %s: %s");
5076 args[1] = BVAR (current_buffer, name); 5081 args[1] = BVAR (current_buffer, name);
5077 args[2] = Ferror_message_string (error); 5082 args[2] = Ferror_message_string (error_val);
5078 msg = Fformat (3, args); 5083 msg = Fformat (3, args);
5079 GCPRO1 (msg); 5084 GCPRO1 (msg);
5080 nbytes = SBYTES (msg); 5085 nbytes = SBYTES (msg);
@@ -5095,7 +5100,7 @@ auto_save_error (Lisp_Object error)
5095 return Qnil; 5100 return Qnil;
5096} 5101}
5097 5102
5098Lisp_Object 5103static Lisp_Object
5099auto_save_1 (void) 5104auto_save_1 (void)
5100{ 5105{
5101 struct stat st; 5106 struct stat st;
@@ -5426,7 +5431,7 @@ before any other event (mouse or keypress) is handled. */)
5426Lisp_Object 5431Lisp_Object
5427Fread_file_name (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object initial, Lisp_Object predicate) 5432Fread_file_name (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object initial, Lisp_Object predicate)
5428{ 5433{
5429 struct gcpro gcpro1, gcpro2; 5434 struct gcpro gcpro1;
5430 Lisp_Object args[7]; 5435 Lisp_Object args[7];
5431 5436
5432 GCPRO1 (default_filename); 5437 GCPRO1 (default_filename);