Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 183:e121b013d1f0 r20-3b18
Import from CVS: tag r20-3b18
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:54:23 +0200 |
parents | 8eaf7971accc |
children | 3d6bfa290dbd |
comparison
equal
deleted
inserted
replaced
182:f07455f06202 | 183:e121b013d1f0 |
---|---|
48 #ifdef HPUX | 48 #ifdef HPUX |
49 #include <netio.h> | 49 #include <netio.h> |
50 #ifdef HPUX_PRE_8_0 | 50 #ifdef HPUX_PRE_8_0 |
51 #include <errnet.h> | 51 #include <errnet.h> |
52 #endif | 52 #endif |
53 #endif | 53 #endif /* HPUX */ |
54 | 54 |
55 /* Nonzero during writing of auto-save files */ | 55 /* Nonzero during writing of auto-save files */ |
56 static int auto_saving; | 56 static int auto_saving; |
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 |
1137 /* Problem when expanding "~\" if HOME is not on current drive. | 1137 /* Problem when expanding "~\" if HOME is not on current drive. |
1138 Ulrich Leodolter, Wed Jan 11 10:20:35 1995 */ | 1138 Ulrich Leodolter, Wed Jan 11 10:20:35 1995 */ |
1139 if (newdir[1] == ':') | 1139 if (newdir[1] == ':') |
1140 drive = newdir[0]; | 1140 drive = newdir[0]; |
1141 dostounix_filename (newdir); | 1141 dostounix_filename (newdir); |
1142 #endif | 1142 #endif /* DOS_NT */ |
1143 nm++; | 1143 nm++; |
1144 #ifdef VMS | 1144 #ifdef VMS |
1145 nm++; /* Don't leave the slash in nm. */ | 1145 nm++; /* Don't leave the slash in nm. */ |
1146 #endif /* VMS */ | 1146 #endif /* VMS */ |
1147 } | 1147 } |
2386 || stricmp (suffix, ".exe") == 0 | 2386 || stricmp (suffix, ".exe") == 0 |
2387 || stricmp (suffix, ".bat") == 0) | 2387 || stricmp (suffix, ".bat") == 0) |
2388 || (st.st_mode & S_IFMT) == S_IFDIR); | 2388 || (st.st_mode & S_IFMT) == S_IFDIR); |
2389 #else /* not DOS_NT */ | 2389 #else /* not DOS_NT */ |
2390 #ifdef HAVE_EACCESS | 2390 #ifdef HAVE_EACCESS |
2391 return (eaccess (filename, 1) >= 0); | 2391 return eaccess (filename, 1) >= 0; |
2392 #else | 2392 #else |
2393 /* Access isn't quite right because it uses the real uid | 2393 /* Access isn't quite right because it uses the real uid |
2394 and we really want to test with the effective uid. | 2394 and we really want to test with the effective uid. |
2395 But Unix doesn't give us a right way to do it. */ | 2395 But Unix doesn't give us a right way to do it. */ |
2396 return (access (filename, 1) >= 0); | 2396 return access (filename, 1) >= 0; |
2397 #endif | 2397 #endif /* HAVE_EACCESS */ |
2398 #endif /* not DOS_NT */ | 2398 #endif /* not DOS_NT */ |
2399 } | 2399 } |
2400 | 2400 |
2401 /* Return nonzero if file FILENAME exists and can be written. */ | 2401 /* Return nonzero if file FILENAME exists and can be written. */ |
2402 | 2402 |
2969 return Fsignal (Qfile_error, | 2969 return Fsignal (Qfile_error, |
2970 list2 (build_translated_string("not a regular file"), | 2970 list2 (build_translated_string("not a regular file"), |
2971 filename)); | 2971 filename)); |
2972 } | 2972 } |
2973 } | 2973 } |
2974 #endif | 2974 #endif /* S_IFREG */ |
2975 | 2975 |
2976 if (!NILP (beg)) | 2976 if (!NILP (beg)) |
2977 CHECK_INT (beg); | 2977 CHECK_INT (beg); |
2978 else | 2978 else |
2979 beg = Qzero; | 2979 beg = Qzero; |
3168 #ifdef MULE | 3168 #ifdef MULE |
3169 stream = make_decoding_input_stream | 3169 stream = make_decoding_input_stream |
3170 (XLSTREAM (stream), Fget_coding_system (codesys)); | 3170 (XLSTREAM (stream), Fget_coding_system (codesys)); |
3171 Lstream_set_character_mode (XLSTREAM (stream)); | 3171 Lstream_set_character_mode (XLSTREAM (stream)); |
3172 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); | 3172 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); |
3173 #endif | 3173 #endif /* MULE */ |
3174 | 3174 |
3175 record_unwind_protect (close_stream_unwind, stream); | 3175 record_unwind_protect (close_stream_unwind, stream); |
3176 | 3176 |
3177 /* No need to limit the amount of stuff we attempt to read. (It would | 3177 /* No need to limit the amount of stuff we attempt to read. (It would |
3178 be incorrect, anyway, when Mule is enabled.) Instead, the limiting | 3178 be incorrect, anyway, when Mule is enabled.) Instead, the limiting |
3204 if (!NILP (used_codesys)) | 3204 if (!NILP (used_codesys)) |
3205 { | 3205 { |
3206 Fset (used_codesys, | 3206 Fset (used_codesys, |
3207 XCODING_SYSTEM_NAME (decoding_stream_coding_system (XLSTREAM (stream)))); | 3207 XCODING_SYSTEM_NAME (decoding_stream_coding_system (XLSTREAM (stream)))); |
3208 } | 3208 } |
3209 #endif | 3209 #endif /* MULE */ |
3210 NUNGCPRO; | 3210 NUNGCPRO; |
3211 } | 3211 } |
3212 | 3212 |
3213 #if 0 | 3213 #if 0 |
3214 /* XXXX Why the #### ? Bogus anyway. If they are there, display em! */ | 3214 /* XXXX Why the #### ? Bogus anyway. If they are there, display em! */ |
3225 { | 3225 { |
3226 buffer_do_msdos_crlf_to_lf (buf, ####); | 3226 buffer_do_msdos_crlf_to_lf (buf, ####); |
3227 } | 3227 } |
3228 } | 3228 } |
3229 #endif | 3229 #endif |
3230 #endif | 3230 #endif /* 0 */ |
3231 | 3231 |
3232 /* Close the file/stream */ | 3232 /* Close the file/stream */ |
3233 unbind_to (speccount, Qnil); | 3233 unbind_to (speccount, Qnil); |
3234 | 3234 |
3235 if (saverrno != 0) | 3235 if (saverrno != 0) |
3381 #if 0 | 3381 #if 0 |
3382 #ifdef DOS_NT | 3382 #ifdef DOS_NT |
3383 int buffer_file_type | 3383 int buffer_file_type |
3384 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; | 3384 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; |
3385 #endif /* DOS_NT */ | 3385 #endif /* DOS_NT */ |
3386 #endif | 3386 #endif /* 0 */ |
3387 | 3387 |
3388 #ifdef MULE | 3388 #ifdef MULE |
3389 codesys = Fget_coding_system (codesys); | 3389 codesys = Fget_coding_system (codesys); |
3390 #endif /* MULE */ | 3390 #endif /* MULE */ |
3391 | 3391 |
3545 try to truncate and rewrite existing version if any. | 3545 try to truncate and rewrite existing version if any. |
3546 */ | 3546 */ |
3547 vms_truncate (fn_data); | 3547 vms_truncate (fn_data); |
3548 desc = open (fn_data, O_RDWR, 0); | 3548 desc = open (fn_data, O_RDWR, 0); |
3549 } | 3549 } |
3550 #endif | 3550 #endif /* 0 */ |
3551 } | 3551 } |
3552 } | 3552 } |
3553 UNGCPRO; | 3553 UNGCPRO; |
3554 } | 3554 } |
3555 UNGCPRO; | 3555 UNGCPRO; |
3606 * Yech! | 3606 * Yech! |
3607 */ | 3607 */ |
3608 you lose -- fix this | 3608 you lose -- fix this |
3609 if (GPT > BUF_BEG (current_buffer) && *GPT_ADDR[-1] != '\n') | 3609 if (GPT > BUF_BEG (current_buffer) && *GPT_ADDR[-1] != '\n') |
3610 move_gap (find_next_newline (current_buffer, GPT, 1)); | 3610 move_gap (find_next_newline (current_buffer, GPT, 1)); |
3611 #endif | 3611 #endif /* VMS */ |
3612 | 3612 |
3613 failure = 0; | 3613 failure = 0; |
3614 | 3614 |
3615 /* Note: I tried increasing the buffering size, along with | 3615 /* Note: I tried increasing the buffering size, along with |
3616 various other tricks, but nothing seemed to make much of | 3616 various other tricks, but nothing seemed to make much of |
3628 #ifdef MULE | 3628 #ifdef MULE |
3629 outstream = | 3629 outstream = |
3630 make_encoding_output_stream ( XLSTREAM (outstream), codesys); | 3630 make_encoding_output_stream ( XLSTREAM (outstream), codesys); |
3631 Lstream_set_buffering (XLSTREAM (outstream), | 3631 Lstream_set_buffering (XLSTREAM (outstream), |
3632 LSTREAM_BLOCKN_BUFFERED, 65536); | 3632 LSTREAM_BLOCKN_BUFFERED, 65536); |
3633 #endif | 3633 #endif /* MULE */ |
3634 if (STRINGP (start)) | 3634 if (STRINGP (start)) |
3635 { | 3635 { |
3636 instream = make_lisp_string_input_stream (start, 0, -1); | 3636 instream = make_lisp_string_input_stream (start, 0, -1); |
3637 start1 = 0; | 3637 start1 = 0; |
3638 } | 3638 } |
3664 && errno != EINTR) | 3664 && errno != EINTR) |
3665 { | 3665 { |
3666 failure = 1; | 3666 failure = 1; |
3667 save_errno = errno; | 3667 save_errno = errno; |
3668 } | 3668 } |
3669 #endif | 3669 #endif /* HAVE_FSYNC */ |
3670 | 3670 |
3671 /* Spurious "file has changed on disk" warnings have been | 3671 /* Spurious "file has changed on disk" warnings have been |
3672 observed on Suns as well. | 3672 observed on Suns as well. |
3673 It seems that `close' can change the modtime, under nfs. | 3673 It seems that `close' can change the modtime, under nfs. |
3674 | 3674 |
3818 { | 3818 { |
3819 start = make_int (BUF_BEGV (current_buffer)); | 3819 start = make_int (BUF_BEGV (current_buffer)); |
3820 end = make_int (BUF_ZV (current_buffer)); | 3820 end = make_int (BUF_ZV (current_buffer)); |
3821 annotations = Qnil; | 3821 annotations = Qnil; |
3822 } | 3822 } |
3823 (void) Flength (res); /* Check basic validity of return value */ | 3823 Flength (res); /* Check basic validity of return value */ |
3824 annotations = merge (annotations, res, Qcar_less_than_car); | 3824 annotations = merge (annotations, res, Qcar_less_than_car); |
3825 p = Fcdr (p); | 3825 p = Fcdr (p); |
3826 } | 3826 } |
3827 | 3827 |
3828 /* Now do the same for annotation functions implied by the file-format */ | 3828 /* Now do the same for annotation functions implied by the file-format */ |
3839 { | 3839 { |
3840 start = make_int (BUF_BEGV (current_buffer)); | 3840 start = make_int (BUF_BEGV (current_buffer)); |
3841 end = make_int (BUF_ZV (current_buffer)); | 3841 end = make_int (BUF_ZV (current_buffer)); |
3842 annotations = Qnil; | 3842 annotations = Qnil; |
3843 } | 3843 } |
3844 (void) Flength (res); | 3844 Flength (res); |
3845 annotations = merge (annotations, res, Qcar_less_than_car); | 3845 annotations = merge (annotations, res, Qcar_less_than_car); |
3846 p = Fcdr (p); | 3846 p = Fcdr (p); |
3847 } | 3847 } |
3848 UNGCPRO; | 3848 UNGCPRO; |
3849 return annotations; | 3849 return annotations; |
3894 return -1; | 3894 return -1; |
3895 pos++; | 3895 pos++; |
3896 } | 3896 } |
3897 } | 3897 } |
3898 else | 3898 else |
3899 #endif | 3899 #endif /* MULE */ |
3900 { | 3900 { |
3901 while (pos != nextpos) | 3901 while (pos != nextpos) |
3902 { | 3902 { |
3903 /* Otherwise there is no point to that. Just go in batches. */ | 3903 /* Otherwise there is no point to that. Just go in batches. */ |
3904 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE); | 3904 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE); |
3954 rounded_size = XSTRING_LENGTH (string) + extra; | 3954 rounded_size = XSTRING_LENGTH (string) + extra; |
3955 encrypted_string = alloca (rounded_size + 1); | 3955 encrypted_string = alloca (rounded_size + 1); |
3956 memcpy (encrypted_string, XSTRING_DATA (string), XSTRING_LENGTH (string)); | 3956 memcpy (encrypted_string, XSTRING_DATA (string), XSTRING_LENGTH (string)); |
3957 memset (encrypted_string + rounded_size - extra, 0, extra + 1); | 3957 memset (encrypted_string + rounded_size - extra, 0, extra + 1); |
3958 | 3958 |
3959 if (XSTRING_LENGTH (key) > CRYPT_KEY_SIZE) | 3959 key_size = min (CRYPT_KEY_SIZE, XSTRING_LENGTH (key)) |
3960 key_size = CRYPT_KEY_SIZE; | |
3961 else | |
3962 key_size = XSTRING_LENGTH (key); | |
3963 | 3960 |
3964 raw_key = alloca (CRYPT_KEY_SIZE + 1); | 3961 raw_key = alloca (CRYPT_KEY_SIZE + 1); |
3965 memcpy (raw_key, XSTRING_DATA (key), key_size); | 3962 memcpy (raw_key, XSTRING_DATA (key), key_size); |
3966 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); | 3963 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); |
3967 | 3964 |
3968 (void) ecb_crypt (raw_key, encrypted_string, rounded_size, | 3965 ecb_crypt (raw_key, encrypted_string, rounded_size, |
3969 DES_ENCRYPT | DES_SW); | 3966 DES_ENCRYPT | DES_SW); |
3970 return make_string (encrypted_string, rounded_size); | 3967 return make_string (encrypted_string, rounded_size); |
3971 } | 3968 } |
3972 | 3969 |
3973 DEFUN ("decrypt-string", Fdecrypt_string, 2, 2, 0, /* | 3970 DEFUN ("decrypt-string", Fdecrypt_string, 2, 2, 0, /* |
3974 Decrypt STRING using KEY. | 3971 Decrypt STRING using KEY. |
3984 string_size = XSTRING_LENGTH (string) + 1; | 3981 string_size = XSTRING_LENGTH (string) + 1; |
3985 decrypted_string = alloca (string_size); | 3982 decrypted_string = alloca (string_size); |
3986 memcpy (decrypted_string, XSTRING_DATA (string), string_size); | 3983 memcpy (decrypted_string, XSTRING_DATA (string), string_size); |
3987 decrypted_string[string_size - 1] = '\0'; | 3984 decrypted_string[string_size - 1] = '\0'; |
3988 | 3985 |
3989 if (XSTRING_LENGTH (key) > CRYPT_KEY_SIZE) | 3986 key_size = min (CRYPT_KEY_SIZE, XSTRING_LENGTH (key)) |
3990 key_size = CRYPT_KEY_SIZE; | |
3991 else | |
3992 key_size = XSTRING_LENGTH (key); | |
3993 | 3987 |
3994 raw_key = alloca (CRYPT_KEY_SIZE + 1); | 3988 raw_key = alloca (CRYPT_KEY_SIZE + 1); |
3995 memcpy (raw_key, XSTRING_DATA (key), key_size); | 3989 memcpy (raw_key, XSTRING_DATA (key), key_size); |
3996 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); | 3990 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); |
3997 | 3991 |
3998 | 3992 |
3999 (void) ecb_crypt (raw_key, decrypted_string, string_size, | 3993 ecb_crypt (raw_key, decrypted_string, string_size, D | DES_SW); |
4000 DES_DECRYPT | DES_SW); | |
4001 return make_string (decrypted_string, string_size - 1); | 3994 return make_string (decrypted_string, string_size - 1); |
4002 } | 3995 } |
4003 #endif | 3996 #endif /* 0 */ |
4004 | 3997 |
4005 | 3998 |
4006 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, 1, 1, 0, /* | 3999 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, 1, 1, 0, /* |
4007 Return t if last mod time of BUF's visited file matches what BUF records. | 4000 Return t if last mod time of BUF's visited file matches what BUF records. |
4008 This means that the file has not been changed since it was visited or saved. | 4001 This means that the file has not been changed since it was visited or saved. |
4720 Vafter_insert_file_functions = Qnil; | 4713 Vafter_insert_file_functions = Qnil; |
4721 | 4714 |
4722 DEFVAR_LISP ("write-region-annotate-functions", | 4715 DEFVAR_LISP ("write-region-annotate-functions", |
4723 &Vwrite_region_annotate_functions /* | 4716 &Vwrite_region_annotate_functions /* |
4724 A list of functions to be called at the start of `write-region'. | 4717 A list of functions to be called at the start of `write-region'. |
4725 Each is passed two arguments, START and END as for `write-region'. | 4718 Each is passed two arguments, START and END, as for `write-region'. |
4726 It should return a list of pairs (POSITION . STRING) of strings to be | 4719 It should return a list of pairs (POSITION . STRING) of strings to be |
4727 effectively inserted at the specified positions of the file being written | 4720 effectively inserted at the specified positions of the file being written |
4728 \(1 means to insert before the first byte written). The POSITIONs must be | 4721 \(1 means to insert before the first byte written). The POSITIONs must be |
4729 sorted into increasing order. If there are several functions in the list, | 4722 sorted into increasing order. If there are several functions in the list, |
4730 the several lists are merged destructively. | 4723 the several lists are merged destructively. |