diff options
| author | Richard M. Stallman | 1997-04-02 06:12:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-04-02 06:12:48 +0000 |
| commit | d4b8687bfa37a4af8f1075004961b29f46f19447 (patch) | |
| tree | 1f194d393aa2ca4f0eb226f07b0d9c5c021f20fc /src | |
| parent | 727a0b4a0f92e32aa57f5c1567a6ec7993e4d610 (diff) | |
| download | emacs-d4b8687bfa37a4af8f1075004961b29f46f19447.tar.gz emacs-d4b8687bfa37a4af8f1075004961b29f46f19447.zip | |
(Finsert_file_contents): Handle non-regular files.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/src/fileio.c b/src/fileio.c index 65219833360..d9dde6c4a7e 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -3101,13 +3101,15 @@ This does code conversion according to the value of\n\ | |||
| 3101 | least signal an error. */ | 3101 | least signal an error. */ |
| 3102 | if (!S_ISREG (st.st_mode)) | 3102 | if (!S_ISREG (st.st_mode)) |
| 3103 | { | 3103 | { |
| 3104 | if (NILP (visit)) | 3104 | not_regular = 1; |
| 3105 | |||
| 3106 | if (! NILP (visit)) | ||
| 3107 | goto notfound; | ||
| 3108 | |||
| 3109 | if (! NILP (replace) || ! NILP (beg) || ! NILP (end)) | ||
| 3105 | Fsignal (Qfile_error, | 3110 | Fsignal (Qfile_error, |
| 3106 | Fcons (build_string ("not a regular file"), | 3111 | Fcons (build_string ("not a regular file"), |
| 3107 | Fcons (filename, Qnil))); | 3112 | Fcons (filename, Qnil))); |
| 3108 | |||
| 3109 | not_regular = 1; | ||
| 3110 | goto notfound; | ||
| 3111 | } | 3113 | } |
| 3112 | #endif | 3114 | #endif |
| 3113 | 3115 | ||
| @@ -3122,7 +3124,7 @@ This does code conversion according to the value of\n\ | |||
| 3122 | record_unwind_protect (close_file_unwind, make_number (fd)); | 3124 | record_unwind_protect (close_file_unwind, make_number (fd)); |
| 3123 | 3125 | ||
| 3124 | /* Supposedly happens on VMS. */ | 3126 | /* Supposedly happens on VMS. */ |
| 3125 | if (st.st_size < 0) | 3127 | if (! not_regular && st.st_size < 0) |
| 3126 | error ("File size is negative"); | 3128 | error ("File size is negative"); |
| 3127 | 3129 | ||
| 3128 | if (!NILP (beg) || !NILP (end)) | 3130 | if (!NILP (beg) || !NILP (end)) |
| @@ -3138,9 +3140,12 @@ This does code conversion according to the value of\n\ | |||
| 3138 | CHECK_NUMBER (end, 0); | 3140 | CHECK_NUMBER (end, 0); |
| 3139 | else | 3141 | else |
| 3140 | { | 3142 | { |
| 3141 | XSETINT (end, st.st_size); | 3143 | if (! not_regular) |
| 3142 | if (XINT (end) != st.st_size) | 3144 | { |
| 3143 | error ("maximum buffer size exceeded"); | 3145 | XSETINT (end, st.st_size); |
| 3146 | if (XINT (end) != st.st_size) | ||
| 3147 | error ("Maximum buffer size exceeded"); | ||
| 3148 | } | ||
| 3144 | } | 3149 | } |
| 3145 | 3150 | ||
| 3146 | /* If requested, replace the accessible part of the buffer | 3151 | /* If requested, replace the accessible part of the buffer |
| @@ -3472,16 +3477,20 @@ This does code conversion according to the value of\n\ | |||
| 3472 | goto handled; | 3477 | goto handled; |
| 3473 | } | 3478 | } |
| 3474 | 3479 | ||
| 3475 | total = XINT (end) - XINT (beg); | 3480 | if (! not_regular) |
| 3481 | { | ||
| 3482 | register Lisp_Object temp; | ||
| 3476 | 3483 | ||
| 3477 | { | 3484 | total = XINT (end) - XINT (beg); |
| 3478 | register Lisp_Object temp; | ||
| 3479 | 3485 | ||
| 3480 | /* Make sure point-max won't overflow after this insertion. */ | 3486 | /* Make sure point-max won't overflow after this insertion. */ |
| 3481 | XSETINT (temp, total); | 3487 | XSETINT (temp, total); |
| 3482 | if (total != XINT (temp)) | 3488 | if (total != XINT (temp)) |
| 3483 | error ("maximum buffer size exceeded"); | 3489 | error ("Maximum buffer size exceeded"); |
| 3484 | } | 3490 | } |
| 3491 | else | ||
| 3492 | /* For a special file, all we can do is guess. */ | ||
| 3493 | total = READ_BUF_SIZE; | ||
| 3485 | 3494 | ||
| 3486 | if (NILP (visit) && total > 0) | 3495 | if (NILP (visit) && total > 0) |
| 3487 | prepare_to_modify_buffer (PT, PT); | 3496 | prepare_to_modify_buffer (PT, PT); |
| @@ -3525,7 +3534,13 @@ This does code conversion according to the value of\n\ | |||
| 3525 | break; | 3534 | break; |
| 3526 | } | 3535 | } |
| 3527 | 3536 | ||
| 3528 | how_much += this; | 3537 | /* For a regular file, where TOTAL is the real size, |
| 3538 | count HOW_MUCH to compare with it. | ||
| 3539 | For a special file, where TOTAL is just a buffer size, | ||
| 3540 | so don't bother counting in HOW_MUCH. | ||
| 3541 | (INSERTED is where we count the number of characters inserted.) */ | ||
| 3542 | if (! not_regular) | ||
| 3543 | how_much += this; | ||
| 3529 | 3544 | ||
| 3530 | if (CODING_REQUIRE_CONVERSION (&coding)) | 3545 | if (CODING_REQUIRE_CONVERSION (&coding)) |
| 3531 | { | 3546 | { |
| @@ -3536,8 +3551,21 @@ This does code conversion according to the value of\n\ | |||
| 3536 | require = decoding_buffer_size (&coding, this); | 3551 | require = decoding_buffer_size (&coding, this); |
| 3537 | if (GAP_SIZE < require) | 3552 | if (GAP_SIZE < require) |
| 3538 | make_gap (require - GAP_SIZE); | 3553 | make_gap (require - GAP_SIZE); |
| 3539 | if (how_much >= total) /* This is the last block. */ | 3554 | |
| 3540 | coding.last_block = 1; | 3555 | if (! not_regular) |
| 3556 | { | ||
| 3557 | if (how_much >= total) /* This is the last block. */ | ||
| 3558 | coding.last_block = 1; | ||
| 3559 | } | ||
| 3560 | else | ||
| 3561 | { | ||
| 3562 | /* If we encounter EOF, say it is the last block. (The | ||
| 3563 | data this will apply to is the UNPROCESSED characters | ||
| 3564 | carried over from the last batch.) */ | ||
| 3565 | if (this == 0) | ||
| 3566 | coding.last_block = 1; | ||
| 3567 | } | ||
| 3568 | |||
| 3541 | produced = decode_coding (&coding, read_buf, | 3569 | produced = decode_coding (&coding, read_buf, |
| 3542 | POS_ADDR (PT + inserted - 1) + 1, | 3570 | POS_ADDR (PT + inserted - 1) + 1, |
| 3543 | this, GAP_SIZE, &consumed); | 3571 | this, GAP_SIZE, &consumed); |