diff options
| author | Richard M. Stallman | 1992-03-20 20:54:03 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-03-20 20:54:03 +0000 |
| commit | b5148e8537732d90d363618a1fffd0d9bcb498a4 (patch) | |
| tree | b1ee681ec101fd445eaea3824f098f53a4eb98a8 /src | |
| parent | f58b36863ac639e85c0e5bd92a904491053e30d9 (diff) | |
| download | emacs-b5148e8537732d90d363618a1fffd0d9bcb498a4.tar.gz emacs-b5148e8537732d90d363618a1fffd0d9bcb498a4.zip | |
*** empty log message ***
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/fileio.c b/src/fileio.c index cc8ef43eb21..4b258b67fbe 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -117,6 +117,12 @@ report_file_error (string, data) | |||
| 117 | Fsignal (Qfile_error, | 117 | Fsignal (Qfile_error, |
| 118 | Fcons (build_string (string), Fcons (errstring, data))); | 118 | Fcons (build_string (string), Fcons (errstring, data))); |
| 119 | } | 119 | } |
| 120 | |||
| 121 | close_file_unwind (fd) | ||
| 122 | Lisp_Object fd; | ||
| 123 | { | ||
| 124 | close (XFASTINT (fd)); | ||
| 125 | } | ||
| 120 | 126 | ||
| 121 | DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, | 127 | DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, |
| 122 | 1, 1, 0, | 128 | 1, 1, 0, |
| @@ -1374,6 +1380,7 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 1374 | char buf[16 * 1024]; | 1380 | char buf[16 * 1024]; |
| 1375 | struct stat st; | 1381 | struct stat st; |
| 1376 | struct gcpro gcpro1, gcpro2; | 1382 | struct gcpro gcpro1, gcpro2; |
| 1383 | int count = specpdl_ptr - specpdl; | ||
| 1377 | 1384 | ||
| 1378 | GCPRO2 (filename, newname); | 1385 | GCPRO2 (filename, newname); |
| 1379 | CHECK_STRING (filename, 0); | 1386 | CHECK_STRING (filename, 0); |
| @@ -1389,6 +1396,8 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 1389 | if (ifd < 0) | 1396 | if (ifd < 0) |
| 1390 | report_file_error ("Opening input file", Fcons (filename, Qnil)); | 1397 | report_file_error ("Opening input file", Fcons (filename, Qnil)); |
| 1391 | 1398 | ||
| 1399 | record_unwind_protect (close_file_unwind, make_number (ifd)); | ||
| 1400 | |||
| 1392 | #ifdef VMS | 1401 | #ifdef VMS |
| 1393 | /* Create the copy file with the same record format as the input file */ | 1402 | /* Create the copy file with the same record format as the input file */ |
| 1394 | ofd = sys_creat (XSTRING (newname)->data, 0666, ifd); | 1403 | ofd = sys_creat (XSTRING (newname)->data, 0666, ifd); |
| @@ -1396,18 +1405,16 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 1396 | ofd = creat (XSTRING (newname)->data, 0666); | 1405 | ofd = creat (XSTRING (newname)->data, 0666); |
| 1397 | #endif /* VMS */ | 1406 | #endif /* VMS */ |
| 1398 | if (ofd < 0) | 1407 | if (ofd < 0) |
| 1399 | { | 1408 | report_file_error ("Opening output file", Fcons (newname, Qnil)); |
| 1400 | close (ifd); | 1409 | |
| 1401 | report_file_error ("Opening output file", Fcons (newname, Qnil)); | 1410 | record_unwind_protect (close_file_unwind, make_number (ofd)); |
| 1402 | } | ||
| 1403 | 1411 | ||
| 1412 | immediate_quit = 1; | ||
| 1413 | QUIT; | ||
| 1404 | while ((n = read (ifd, buf, sizeof buf)) > 0) | 1414 | while ((n = read (ifd, buf, sizeof buf)) > 0) |
| 1405 | if (write (ofd, buf, n) != n) | 1415 | if (write (ofd, buf, n) != n) |
| 1406 | { | 1416 | report_file_error ("I/O error", Fcons (newname, Qnil)); |
| 1407 | close (ifd); | 1417 | immediate_quit = 0; |
| 1408 | close (ofd); | ||
| 1409 | report_file_error ("I/O error", Fcons (newname, Qnil)); | ||
| 1410 | } | ||
| 1411 | 1418 | ||
| 1412 | if (fstat (ifd, &st) >= 0) | 1419 | if (fstat (ifd, &st) >= 0) |
| 1413 | { | 1420 | { |
| @@ -1424,6 +1431,9 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 1424 | chmod (XSTRING (newname)->data, st.st_mode & 07777); | 1431 | chmod (XSTRING (newname)->data, st.st_mode & 07777); |
| 1425 | } | 1432 | } |
| 1426 | 1433 | ||
| 1434 | /* Discard the unwind protects. */ | ||
| 1435 | specpdl_ptr = specpdl + count; | ||
| 1436 | |||
| 1427 | close (ifd); | 1437 | close (ifd); |
| 1428 | if (close (ofd) < 0) | 1438 | if (close (ofd) < 0) |
| 1429 | report_file_error ("I/O error", Fcons (newname, Qnil)); | 1439 | report_file_error ("I/O error", Fcons (newname, Qnil)); |
| @@ -1949,12 +1959,6 @@ otherwise, if FILE2 does not exist, the answer is t.") | |||
| 1949 | return (mtime1 > st.st_mtime) ? Qt : Qnil; | 1959 | return (mtime1 > st.st_mtime) ? Qt : Qnil; |
| 1950 | } | 1960 | } |
| 1951 | 1961 | ||
| 1952 | close_file_unwind (fd) | ||
| 1953 | Lisp_Object fd; | ||
| 1954 | { | ||
| 1955 | close (XFASTINT (fd)); | ||
| 1956 | } | ||
| 1957 | |||
| 1958 | DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, | 1962 | DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, |
| 1959 | 1, 2, 0, | 1963 | 1, 2, 0, |
| 1960 | "Insert contents of file FILENAME after point.\n\ | 1964 | "Insert contents of file FILENAME after point.\n\ |
| @@ -2022,7 +2026,13 @@ before the error is signaled.") | |||
| 2022 | while (1) | 2026 | while (1) |
| 2023 | { | 2027 | { |
| 2024 | int try = min (st.st_size - inserted, 64 << 10); | 2028 | int try = min (st.st_size - inserted, 64 << 10); |
| 2025 | int this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, try); | 2029 | int this; |
| 2030 | |||
| 2031 | /* Allow quitting out of the actual I/O. */ | ||
| 2032 | immediate_quit = 1; | ||
| 2033 | QUIT; | ||
| 2034 | this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, try); | ||
| 2035 | immediate_quit = 0; | ||
| 2026 | 2036 | ||
| 2027 | if (this <= 0) | 2037 | if (this <= 0) |
| 2028 | { | 2038 | { |