diff options
| author | Paul Eggert | 2011-06-14 18:07:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-14 18:07:35 -0700 |
| commit | e69dafade3ccd5c2997a3f6fd6c7bea29e75ad8e (patch) | |
| tree | fafd4097ed5744e11298b381b7e51a41cbad2580 /src | |
| parent | 566684ead5a577f6b2506f242494f2fa57eb5a49 (diff) | |
| download | emacs-e69dafade3ccd5c2997a3f6fd6c7bea29e75ad8e.tar.gz emacs-e69dafade3ccd5c2997a3f6fd6c7bea29e75ad8e.zip | |
* fileio.c: Don't assume EMACS_INT fits in off_t.
(emacs_lseek): New static function.
(Finsert_file_contents, Fwrite_region): Use it.
Use SEEK_SET, SEEK_CUR, SEEK_END as appropriate.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/fileio.c | 29 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 35dab796be7..e477162b32b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2011-06-15 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * fileio.c: Don't assume EMACS_INT fits in off_t. | ||
| 4 | (emacs_lseek): New static function. | ||
| 5 | (Finsert_file_contents, Fwrite_region): Use it. | ||
| 6 | Use SEEK_SET, SEEK_CUR, SEEK_END as appropriate. | ||
| 7 | |||
| 1 | 2011-06-14 Paul Eggert <eggert@cs.ucla.edu> | 8 | 2011-06-14 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 9 | ||
| 3 | * fns.c (Fload_average): Don't assume 100 * load average fits in int. | 10 | * fns.c (Fload_average): Don't assume 100 * load average fits in int. |
diff --git a/src/fileio.c b/src/fileio.c index 9a08e11e27e..2e0b3831e8d 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -3109,6 +3109,19 @@ read_non_regular_quit (Lisp_Object ignore) | |||
| 3109 | return Qnil; | 3109 | return Qnil; |
| 3110 | } | 3110 | } |
| 3111 | 3111 | ||
| 3112 | /* Reposition FD to OFFSET, based on WHENCE. This acts like lseek | ||
| 3113 | except that it also tests for OFFSET being out of lseek's range. */ | ||
| 3114 | static off_t | ||
| 3115 | emacs_lseek (int fd, EMACS_INT offset, int whence) | ||
| 3116 | { | ||
| 3117 | if (! (TYPE_MINIMUM (off_t) <= offset && offset <= TYPE_MAXIMUM (off_t))) | ||
| 3118 | { | ||
| 3119 | errno = EINVAL; | ||
| 3120 | return -1; | ||
| 3121 | } | ||
| 3122 | return lseek (fd, offset, whence); | ||
| 3123 | } | ||
| 3124 | |||
| 3112 | 3125 | ||
| 3113 | DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, | 3126 | DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, |
| 3114 | 1, 5, 0, | 3127 | 1, 5, 0, |
| @@ -3317,7 +3330,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3317 | nread = emacs_read (fd, read_buf, 1024); | 3330 | nread = emacs_read (fd, read_buf, 1024); |
| 3318 | if (nread >= 0) | 3331 | if (nread >= 0) |
| 3319 | { | 3332 | { |
| 3320 | if (lseek (fd, st.st_size - (1024 * 3), 0) < 0) | 3333 | if (lseek (fd, st.st_size - (1024 * 3), SEEK_SET) < 0) |
| 3321 | report_file_error ("Setting file position", | 3334 | report_file_error ("Setting file position", |
| 3322 | Fcons (orig_filename, Qnil)); | 3335 | Fcons (orig_filename, Qnil)); |
| 3323 | nread += emacs_read (fd, read_buf + nread, 1024 * 3); | 3336 | nread += emacs_read (fd, read_buf + nread, 1024 * 3); |
| @@ -3361,7 +3374,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3361 | specpdl_ptr--; | 3374 | specpdl_ptr--; |
| 3362 | 3375 | ||
| 3363 | /* Rewind the file for the actual read done later. */ | 3376 | /* Rewind the file for the actual read done later. */ |
| 3364 | if (lseek (fd, 0, 0) < 0) | 3377 | if (lseek (fd, 0, SEEK_SET) < 0) |
| 3365 | report_file_error ("Setting file position", | 3378 | report_file_error ("Setting file position", |
| 3366 | Fcons (orig_filename, Qnil)); | 3379 | Fcons (orig_filename, Qnil)); |
| 3367 | } | 3380 | } |
| @@ -3428,7 +3441,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3428 | 3441 | ||
| 3429 | if (XINT (beg) != 0) | 3442 | if (XINT (beg) != 0) |
| 3430 | { | 3443 | { |
| 3431 | if (lseek (fd, XINT (beg), 0) < 0) | 3444 | if (emacs_lseek (fd, XINT (beg), SEEK_SET) < 0) |
| 3432 | report_file_error ("Setting file position", | 3445 | report_file_error ("Setting file position", |
| 3433 | Fcons (orig_filename, Qnil)); | 3446 | Fcons (orig_filename, Qnil)); |
| 3434 | } | 3447 | } |
| @@ -3500,7 +3513,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3500 | break; | 3513 | break; |
| 3501 | /* How much can we scan in the next step? */ | 3514 | /* How much can we scan in the next step? */ |
| 3502 | trial = min (curpos, sizeof buffer); | 3515 | trial = min (curpos, sizeof buffer); |
| 3503 | if (lseek (fd, curpos - trial, 0) < 0) | 3516 | if (emacs_lseek (fd, curpos - trial, SEEK_SET) < 0) |
| 3504 | report_file_error ("Setting file position", | 3517 | report_file_error ("Setting file position", |
| 3505 | Fcons (orig_filename, Qnil)); | 3518 | Fcons (orig_filename, Qnil)); |
| 3506 | 3519 | ||
| @@ -3618,7 +3631,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3618 | /* First read the whole file, performing code conversion into | 3631 | /* First read the whole file, performing code conversion into |
| 3619 | CONVERSION_BUFFER. */ | 3632 | CONVERSION_BUFFER. */ |
| 3620 | 3633 | ||
| 3621 | if (lseek (fd, XINT (beg), 0) < 0) | 3634 | if (emacs_lseek (fd, XINT (beg), SEEK_SET) < 0) |
| 3622 | report_file_error ("Setting file position", | 3635 | report_file_error ("Setting file position", |
| 3623 | Fcons (orig_filename, Qnil)); | 3636 | Fcons (orig_filename, Qnil)); |
| 3624 | 3637 | ||
| @@ -3817,7 +3830,7 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3817 | 3830 | ||
| 3818 | if (XINT (beg) != 0 || !NILP (replace)) | 3831 | if (XINT (beg) != 0 || !NILP (replace)) |
| 3819 | { | 3832 | { |
| 3820 | if (lseek (fd, XINT (beg), 0) < 0) | 3833 | if (emacs_lseek (fd, XINT (beg), SEEK_SET) < 0) |
| 3821 | report_file_error ("Setting file position", | 3834 | report_file_error ("Setting file position", |
| 3822 | Fcons (orig_filename, Qnil)); | 3835 | Fcons (orig_filename, Qnil)); |
| 3823 | } | 3836 | } |
| @@ -4549,9 +4562,9 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4549 | long ret; | 4562 | long ret; |
| 4550 | 4563 | ||
| 4551 | if (NUMBERP (append)) | 4564 | if (NUMBERP (append)) |
| 4552 | ret = lseek (desc, XINT (append), 1); | 4565 | ret = emacs_lseek (desc, XINT (append), SEEK_CUR); |
| 4553 | else | 4566 | else |
| 4554 | ret = lseek (desc, 0, 2); | 4567 | ret = lseek (desc, 0, SEEK_END); |
| 4555 | if (ret < 0) | 4568 | if (ret < 0) |
| 4556 | { | 4569 | { |
| 4557 | #ifdef CLASH_DETECTION | 4570 | #ifdef CLASH_DETECTION |