diff options
Diffstat (limited to 'src/fileio.c')
| -rw-r--r-- | src/fileio.c | 202 |
1 files changed, 94 insertions, 108 deletions
diff --git a/src/fileio.c b/src/fileio.c index 7466914af1c..ca71af7ed95 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -23,7 +23,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 23 | #include <stdio.h> | 23 | #include <stdio.h> |
| 24 | #include <sys/types.h> | 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> | 25 | #include <sys/stat.h> |
| 26 | #include <setjmp.h> | ||
| 27 | #include <unistd.h> | 26 | #include <unistd.h> |
| 28 | 27 | ||
| 29 | #ifdef HAVE_PWD_H | 28 | #ifdef HAVE_PWD_H |
| @@ -85,18 +84,18 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 85 | 84 | ||
| 86 | #include "commands.h" | 85 | #include "commands.h" |
| 87 | 86 | ||
| 88 | /* Nonzero during writing of auto-save files. */ | 87 | /* True during writing of auto-save files. */ |
| 89 | static int auto_saving; | 88 | static bool auto_saving; |
| 90 | 89 | ||
| 91 | /* Nonzero umask during creation of auto-save directories. */ | 90 | /* Nonzero umask during creation of auto-save directories. */ |
| 92 | static int auto_saving_dir_umask; | 91 | static mode_t auto_saving_dir_umask; |
| 93 | 92 | ||
| 94 | /* Set by auto_save_1 to mode of original file so Fwrite_region will create | 93 | /* Set by auto_save_1 to mode of original file so Fwrite_region will create |
| 95 | a new file with the same mode as the original. */ | 94 | a new file with the same mode as the original. */ |
| 96 | static int auto_save_mode_bits; | 95 | static mode_t auto_save_mode_bits; |
| 97 | 96 | ||
| 98 | /* Set by auto_save_1 if an error occurred during the last auto-save. */ | 97 | /* Set by auto_save_1 if an error occurred during the last auto-save. */ |
| 99 | static int auto_save_error_occurred; | 98 | static bool auto_save_error_occurred; |
| 100 | 99 | ||
| 101 | /* The symbol bound to coding-system-for-read when | 100 | /* The symbol bound to coding-system-for-read when |
| 102 | insert-file-contents is called for recovering a file. This is not | 101 | insert-file-contents is called for recovering a file. This is not |
| @@ -145,10 +144,10 @@ Lisp_Object Qfile_name_history; | |||
| 145 | 144 | ||
| 146 | static Lisp_Object Qcar_less_than_car; | 145 | static Lisp_Object Qcar_less_than_car; |
| 147 | 146 | ||
| 148 | static int a_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, | 147 | static bool a_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, |
| 149 | Lisp_Object *, struct coding_system *); | 148 | Lisp_Object *, struct coding_system *); |
| 150 | static int e_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, | 149 | static bool e_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, |
| 151 | struct coding_system *); | 150 | struct coding_system *); |
| 152 | 151 | ||
| 153 | 152 | ||
| 154 | void | 153 | void |
| @@ -595,7 +594,7 @@ static unsigned make_temp_name_count, make_temp_name_count_initialized_p; | |||
| 595 | which has no existing file. To make this work, PREFIX should be | 594 | which has no existing file. To make this work, PREFIX should be |
| 596 | an absolute file name. | 595 | an absolute file name. |
| 597 | 596 | ||
| 598 | BASE64_P non-zero means add the pid as 3 characters in base64 | 597 | BASE64_P means add the pid as 3 characters in base64 |
| 599 | encoding. In this case, 6 characters will be added to PREFIX to | 598 | encoding. In this case, 6 characters will be added to PREFIX to |
| 600 | form the file name. Otherwise, if Emacs is running on a system | 599 | form the file name. Otherwise, if Emacs is running on a system |
| 601 | with long file names, add the pid as a decimal number. | 600 | with long file names, add the pid as a decimal number. |
| @@ -604,7 +603,7 @@ static unsigned make_temp_name_count, make_temp_name_count_initialized_p; | |||
| 604 | generated. */ | 603 | generated. */ |
| 605 | 604 | ||
| 606 | Lisp_Object | 605 | Lisp_Object |
| 607 | make_temp_name (Lisp_Object prefix, int base64_p) | 606 | make_temp_name (Lisp_Object prefix, bool base64_p) |
| 608 | { | 607 | { |
| 609 | Lisp_Object val; | 608 | Lisp_Object val; |
| 610 | int len, clen; | 609 | int len, clen; |
| @@ -761,8 +760,8 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 761 | struct passwd *pw; | 760 | struct passwd *pw; |
| 762 | #ifdef DOS_NT | 761 | #ifdef DOS_NT |
| 763 | int drive = 0; | 762 | int drive = 0; |
| 764 | int collapse_newdir = 1; | 763 | bool collapse_newdir = 1; |
| 765 | int is_escaped = 0; | 764 | bool is_escaped = 0; |
| 766 | #endif /* DOS_NT */ | 765 | #endif /* DOS_NT */ |
| 767 | ptrdiff_t length; | 766 | ptrdiff_t length; |
| 768 | Lisp_Object handler, result, handled_name; | 767 | Lisp_Object handler, result, handled_name; |
| @@ -920,10 +919,9 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 920 | /* If it turns out that the filename we want to return is just a | 919 | /* If it turns out that the filename we want to return is just a |
| 921 | suffix of FILENAME, we don't need to go through and edit | 920 | suffix of FILENAME, we don't need to go through and edit |
| 922 | things; we just need to construct a new string using data | 921 | things; we just need to construct a new string using data |
| 923 | starting at the middle of FILENAME. If we set lose to a | 922 | starting at the middle of FILENAME. If we set LOSE, that |
| 924 | non-zero value, that means we've discovered that we can't do | 923 | means we've discovered that we can't do that cool trick. */ |
| 925 | that cool trick. */ | 924 | bool lose = 0; |
| 926 | int lose = 0; | ||
| 927 | char *p = nm; | 925 | char *p = nm; |
| 928 | 926 | ||
| 929 | while (*p) | 927 | while (*p) |
| @@ -1294,7 +1292,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1294 | if (!(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]))) | 1292 | if (!(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]))) |
| 1295 | #endif /* WINDOWSNT */ | 1293 | #endif /* WINDOWSNT */ |
| 1296 | { | 1294 | { |
| 1297 | if (!drive) abort (); | 1295 | if (!drive) emacs_abort (); |
| 1298 | target -= 2; | 1296 | target -= 2; |
| 1299 | target[0] = DRIVE_LETTER (drive); | 1297 | target[0] = DRIVE_LETTER (drive); |
| 1300 | target[1] = ':'; | 1298 | target[1] = ':'; |
| @@ -1360,7 +1358,6 @@ See also the function `substitute-in-file-name'.") | |||
| 1360 | ptrdiff_t tlen; | 1358 | ptrdiff_t tlen; |
| 1361 | unsigned char *target; | 1359 | unsigned char *target; |
| 1362 | struct passwd *pw; | 1360 | struct passwd *pw; |
| 1363 | int lose; | ||
| 1364 | 1361 | ||
| 1365 | CHECK_STRING (name); | 1362 | CHECK_STRING (name); |
| 1366 | nm = SDATA (name); | 1363 | nm = SDATA (name); |
| @@ -1369,8 +1366,8 @@ See also the function `substitute-in-file-name'.") | |||
| 1369 | If no /./ or /../ we can return right away. */ | 1366 | If no /./ or /../ we can return right away. */ |
| 1370 | if (nm[0] == '/') | 1367 | if (nm[0] == '/') |
| 1371 | { | 1368 | { |
| 1369 | bool lose = 0; | ||
| 1372 | p = nm; | 1370 | p = nm; |
| 1373 | lose = 0; | ||
| 1374 | while (*p) | 1371 | while (*p) |
| 1375 | { | 1372 | { |
| 1376 | if (p[0] == '/' && p[1] == '/' | 1373 | if (p[0] == '/' && p[1] == '/' |
| @@ -1494,7 +1491,7 @@ See also the function `substitute-in-file-name'.") | |||
| 1494 | #endif | 1491 | #endif |
| 1495 | 1492 | ||
| 1496 | /* If /~ or // appears, discard everything through first slash. */ | 1493 | /* If /~ or // appears, discard everything through first slash. */ |
| 1497 | static int | 1494 | static bool |
| 1498 | file_name_absolute_p (const char *filename) | 1495 | file_name_absolute_p (const char *filename) |
| 1499 | { | 1496 | { |
| 1500 | return | 1497 | return |
| @@ -1560,12 +1557,10 @@ If `//' appears, everything up to and including the first of | |||
| 1560 | those `/' is discarded. */) | 1557 | those `/' is discarded. */) |
| 1561 | (Lisp_Object filename) | 1558 | (Lisp_Object filename) |
| 1562 | { | 1559 | { |
| 1563 | char *nm; | 1560 | char *nm, *s, *p, *o, *x, *endp; |
| 1564 | |||
| 1565 | register char *s, *p, *o, *x, *endp; | ||
| 1566 | char *target = NULL; | 1561 | char *target = NULL; |
| 1567 | int total = 0; | 1562 | int total = 0; |
| 1568 | int substituted = 0; | 1563 | bool substituted = 0; |
| 1569 | bool multibyte; | 1564 | bool multibyte; |
| 1570 | char *xnm; | 1565 | char *xnm; |
| 1571 | Lisp_Object handler; | 1566 | Lisp_Object handler; |
| @@ -1780,7 +1775,7 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) | |||
| 1780 | } | 1775 | } |
| 1781 | 1776 | ||
| 1782 | /* Signal an error if the file ABSNAME already exists. | 1777 | /* Signal an error if the file ABSNAME already exists. |
| 1783 | If INTERACTIVE is nonzero, ask the user whether to proceed, | 1778 | If INTERACTIVE, ask the user whether to proceed, |
| 1784 | and bypass the error if the user says to go ahead. | 1779 | and bypass the error if the user says to go ahead. |
| 1785 | QUERYSTRING is a name for the action that is being considered | 1780 | QUERYSTRING is a name for the action that is being considered |
| 1786 | to alter the file. | 1781 | to alter the file. |
| @@ -1789,13 +1784,14 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) | |||
| 1789 | If the file does not exist, STATPTR->st_mode is set to 0. | 1784 | If the file does not exist, STATPTR->st_mode is set to 0. |
| 1790 | If STATPTR is null, we don't store into it. | 1785 | If STATPTR is null, we don't store into it. |
| 1791 | 1786 | ||
| 1792 | If QUICK is nonzero, we ask for y or n, not yes or no. */ | 1787 | If QUICK, ask for y or n, not yes or no. */ |
| 1793 | 1788 | ||
| 1794 | static void | 1789 | static void |
| 1795 | barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring, | 1790 | barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring, |
| 1796 | int interactive, struct stat *statptr, int quick) | 1791 | bool interactive, struct stat *statptr, |
| 1792 | bool quick) | ||
| 1797 | { | 1793 | { |
| 1798 | register Lisp_Object tem, encoded_filename; | 1794 | Lisp_Object tem, encoded_filename; |
| 1799 | struct stat statbuf; | 1795 | struct stat statbuf; |
| 1800 | struct gcpro gcpro1; | 1796 | struct gcpro gcpro1; |
| 1801 | 1797 | ||
| @@ -1869,11 +1865,11 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 1869 | Lisp_Object handler; | 1865 | Lisp_Object handler; |
| 1870 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 1866 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 1871 | ptrdiff_t count = SPECPDL_INDEX (); | 1867 | ptrdiff_t count = SPECPDL_INDEX (); |
| 1872 | int input_file_statable_p; | 1868 | bool input_file_statable_p; |
| 1873 | Lisp_Object encoded_file, encoded_newname; | 1869 | Lisp_Object encoded_file, encoded_newname; |
| 1874 | #if HAVE_LIBSELINUX | 1870 | #if HAVE_LIBSELINUX |
| 1875 | security_context_t con; | 1871 | security_context_t con; |
| 1876 | int fail, conlength = 0; | 1872 | int conlength = 0; |
| 1877 | #endif | 1873 | #endif |
| 1878 | 1874 | ||
| 1879 | encoded_file = encoded_newname = Qnil; | 1875 | encoded_file = encoded_newname = Qnil; |
| @@ -1988,7 +1984,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 1988 | S_IREAD | S_IWRITE); | 1984 | S_IREAD | S_IWRITE); |
| 1989 | #else /* not MSDOS */ | 1985 | #else /* not MSDOS */ |
| 1990 | { | 1986 | { |
| 1991 | int new_mask = 0666; | 1987 | mode_t new_mask = 0666; |
| 1992 | if (input_file_statable_p) | 1988 | if (input_file_statable_p) |
| 1993 | { | 1989 | { |
| 1994 | if (!NILP (preserve_uid_gid)) | 1990 | if (!NILP (preserve_uid_gid)) |
| @@ -2018,7 +2014,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 2018 | owner and group. */ | 2014 | owner and group. */ |
| 2019 | if (input_file_statable_p) | 2015 | if (input_file_statable_p) |
| 2020 | { | 2016 | { |
| 2021 | int mode_mask = 07777; | 2017 | mode_t mode_mask = 07777; |
| 2022 | if (!NILP (preserve_uid_gid)) | 2018 | if (!NILP (preserve_uid_gid)) |
| 2023 | { | 2019 | { |
| 2024 | /* Attempt to change owner and group. If that doesn't work | 2020 | /* Attempt to change owner and group. If that doesn't work |
| @@ -2041,7 +2037,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 2041 | if (conlength > 0) | 2037 | if (conlength > 0) |
| 2042 | { | 2038 | { |
| 2043 | /* Set the modified context back to the file. */ | 2039 | /* Set the modified context back to the file. */ |
| 2044 | fail = fsetfilecon (ofd, con); | 2040 | bool fail = fsetfilecon (ofd, con) != 0; |
| 2045 | /* See http://debbugs.gnu.org/11245 for ENOTSUP. */ | 2041 | /* See http://debbugs.gnu.org/11245 for ENOTSUP. */ |
| 2046 | if (fail && errno != ENOTSUP) | 2042 | if (fail && errno != ENOTSUP) |
| 2047 | report_file_error ("Doing fsetfilecon", Fcons (newname, Qnil)); | 2043 | report_file_error ("Doing fsetfilecon", Fcons (newname, Qnil)); |
| @@ -2184,17 +2180,14 @@ internal_delete_file_1 (Lisp_Object ignore) | |||
| 2184 | return Qt; | 2180 | return Qt; |
| 2185 | } | 2181 | } |
| 2186 | 2182 | ||
| 2187 | /* Delete file FILENAME, returning 1 if successful and 0 if failed. | 2183 | /* Delete file FILENAME. |
| 2188 | This ignores `delete-by-moving-to-trash'. */ | 2184 | This ignores `delete-by-moving-to-trash'. */ |
| 2189 | 2185 | ||
| 2190 | int | 2186 | void |
| 2191 | internal_delete_file (Lisp_Object filename) | 2187 | internal_delete_file (Lisp_Object filename) |
| 2192 | { | 2188 | { |
| 2193 | Lisp_Object tem; | 2189 | internal_condition_case_2 (Fdelete_file, filename, Qnil, |
| 2194 | 2190 | Qt, internal_delete_file_1); | |
| 2195 | tem = internal_condition_case_2 (Fdelete_file, filename, Qnil, | ||
| 2196 | Qt, internal_delete_file_1); | ||
| 2197 | return NILP (tem); | ||
| 2198 | } | 2191 | } |
| 2199 | 2192 | ||
| 2200 | DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, | 2193 | DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, |
| @@ -2430,9 +2423,9 @@ On Unix, this is a name starting with a `/' or a `~'. */) | |||
| 2430 | return file_name_absolute_p (SSDATA (filename)) ? Qt : Qnil; | 2423 | return file_name_absolute_p (SSDATA (filename)) ? Qt : Qnil; |
| 2431 | } | 2424 | } |
| 2432 | 2425 | ||
| 2433 | /* Return nonzero if file FILENAME exists and can be executed. */ | 2426 | /* Return true if file FILENAME exists and can be executed. */ |
| 2434 | 2427 | ||
| 2435 | static int | 2428 | static bool |
| 2436 | check_executable (char *filename) | 2429 | check_executable (char *filename) |
| 2437 | { | 2430 | { |
| 2438 | #ifdef DOS_NT | 2431 | #ifdef DOS_NT |
| @@ -2452,9 +2445,9 @@ check_executable (char *filename) | |||
| 2452 | #endif /* not DOS_NT */ | 2445 | #endif /* not DOS_NT */ |
| 2453 | } | 2446 | } |
| 2454 | 2447 | ||
| 2455 | /* Return nonzero if file FILENAME exists and can be written. */ | 2448 | /* Return true if file FILENAME exists and can be written. */ |
| 2456 | 2449 | ||
| 2457 | static int | 2450 | static bool |
| 2458 | check_writable (const char *filename) | 2451 | check_writable (const char *filename) |
| 2459 | { | 2452 | { |
| 2460 | #ifdef MSDOS | 2453 | #ifdef MSDOS |
| @@ -2464,7 +2457,7 @@ check_writable (const char *filename) | |||
| 2464 | return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); | 2457 | return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); |
| 2465 | #else /* not MSDOS */ | 2458 | #else /* not MSDOS */ |
| 2466 | #ifdef HAVE_EUIDACCESS | 2459 | #ifdef HAVE_EUIDACCESS |
| 2467 | int res = (euidaccess (filename, 2) >= 0); | 2460 | bool res = (euidaccess (filename, 2) >= 0); |
| 2468 | #ifdef CYGWIN | 2461 | #ifdef CYGWIN |
| 2469 | /* euidaccess may have returned failure because Cygwin couldn't | 2462 | /* euidaccess may have returned failure because Cygwin couldn't |
| 2470 | determine the file's UID or GID; if so, we return success. */ | 2463 | determine the file's UID or GID; if so, we return success. */ |
| @@ -2732,7 +2725,7 @@ searchable directory. */) | |||
| 2732 | (Lisp_Object filename) | 2725 | (Lisp_Object filename) |
| 2733 | { | 2726 | { |
| 2734 | Lisp_Object handler; | 2727 | Lisp_Object handler; |
| 2735 | int tem; | 2728 | bool tem; |
| 2736 | struct gcpro gcpro1; | 2729 | struct gcpro gcpro1; |
| 2737 | 2730 | ||
| 2738 | /* If the file name has special constructs in it, | 2731 | /* If the file name has special constructs in it, |
| @@ -2868,7 +2861,8 @@ compiled with SELinux support. */) | |||
| 2868 | Lisp_Object type = CAR_SAFE (CDR_SAFE (CDR_SAFE (context))); | 2861 | Lisp_Object type = CAR_SAFE (CDR_SAFE (CDR_SAFE (context))); |
| 2869 | Lisp_Object range = CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (context)))); | 2862 | Lisp_Object range = CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (context)))); |
| 2870 | security_context_t con; | 2863 | security_context_t con; |
| 2871 | int fail, conlength; | 2864 | bool fail; |
| 2865 | int conlength; | ||
| 2872 | context_t parsed_con; | 2866 | context_t parsed_con; |
| 2873 | #endif | 2867 | #endif |
| 2874 | 2868 | ||
| @@ -2912,8 +2906,9 @@ compiled with SELinux support. */) | |||
| 2912 | } | 2906 | } |
| 2913 | 2907 | ||
| 2914 | /* Set the modified context back to the file. */ | 2908 | /* Set the modified context back to the file. */ |
| 2915 | fail = lsetfilecon (SSDATA (encoded_absname), | 2909 | fail = (lsetfilecon (SSDATA (encoded_absname), |
| 2916 | context_str (parsed_con)); | 2910 | context_str (parsed_con)) |
| 2911 | != 0); | ||
| 2917 | /* See http://debbugs.gnu.org/11245 for ENOTSUP. */ | 2912 | /* See http://debbugs.gnu.org/11245 for ENOTSUP. */ |
| 2918 | if (fail && errno != ENOTSUP) | 2913 | if (fail && errno != ENOTSUP) |
| 2919 | report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil)); | 2914 | report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil)); |
| @@ -3004,7 +2999,7 @@ DEFUN ("default-file-modes", Fdefault_file_modes, Sdefault_file_modes, 0, 0, 0, | |||
| 3004 | The value is an integer. */) | 2999 | The value is an integer. */) |
| 3005 | (void) | 3000 | (void) |
| 3006 | { | 3001 | { |
| 3007 | int realmask; | 3002 | mode_t realmask; |
| 3008 | Lisp_Object value; | 3003 | Lisp_Object value; |
| 3009 | 3004 | ||
| 3010 | BLOCK_INPUT; | 3005 | BLOCK_INPUT; |
| @@ -3246,29 +3241,29 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3246 | struct stat st; | 3241 | struct stat st; |
| 3247 | int file_status; | 3242 | int file_status; |
| 3248 | EMACS_TIME mtime; | 3243 | EMACS_TIME mtime; |
| 3249 | register int fd; | 3244 | int fd; |
| 3250 | ptrdiff_t inserted = 0; | 3245 | ptrdiff_t inserted = 0; |
| 3251 | int nochange = 0; | 3246 | bool nochange = 0; |
| 3252 | register ptrdiff_t how_much; | 3247 | ptrdiff_t how_much; |
| 3253 | off_t beg_offset, end_offset; | 3248 | off_t beg_offset, end_offset; |
| 3254 | register int unprocessed; | 3249 | int unprocessed; |
| 3255 | ptrdiff_t count = SPECPDL_INDEX (); | 3250 | ptrdiff_t count = SPECPDL_INDEX (); |
| 3256 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | 3251 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
| 3257 | Lisp_Object handler, val, insval, orig_filename, old_undo; | 3252 | Lisp_Object handler, val, insval, orig_filename, old_undo; |
| 3258 | Lisp_Object p; | 3253 | Lisp_Object p; |
| 3259 | ptrdiff_t total = 0; | 3254 | ptrdiff_t total = 0; |
| 3260 | int not_regular = 0; | 3255 | bool not_regular = 0; |
| 3261 | int save_errno = 0; | 3256 | int save_errno = 0; |
| 3262 | char read_buf[READ_BUF_SIZE]; | 3257 | char read_buf[READ_BUF_SIZE]; |
| 3263 | struct coding_system coding; | 3258 | struct coding_system coding; |
| 3264 | char buffer[1 << 14]; | 3259 | char buffer[1 << 14]; |
| 3265 | int replace_handled = 0; | 3260 | bool replace_handled = 0; |
| 3266 | int set_coding_system = 0; | 3261 | bool set_coding_system = 0; |
| 3267 | Lisp_Object coding_system; | 3262 | Lisp_Object coding_system; |
| 3268 | int read_quit = 0; | 3263 | bool read_quit = 0; |
| 3269 | Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark; | 3264 | Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark; |
| 3270 | int we_locked_file = 0; | 3265 | bool we_locked_file = 0; |
| 3271 | int deferred_remove_unwind_protect = 0; | 3266 | bool deferred_remove_unwind_protect = 0; |
| 3272 | 3267 | ||
| 3273 | if (current_buffer->base_buffer && ! NILP (visit)) | 3268 | if (current_buffer->base_buffer && ! NILP (visit)) |
| 3274 | error ("Cannot do file visiting in an indirect buffer"); | 3269 | error ("Cannot do file visiting in an indirect buffer"); |
| @@ -3569,9 +3564,9 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3569 | ptrdiff_t same_at_end = ZV_BYTE; | 3564 | ptrdiff_t same_at_end = ZV_BYTE; |
| 3570 | ptrdiff_t overlap; | 3565 | ptrdiff_t overlap; |
| 3571 | /* There is still a possibility we will find the need to do code | 3566 | /* There is still a possibility we will find the need to do code |
| 3572 | conversion. If that happens, we set this variable to 1 to | 3567 | conversion. If that happens, set this variable to |
| 3573 | give up on handling REPLACE in the optimized way. */ | 3568 | give up on handling REPLACE in the optimized way. */ |
| 3574 | int giveup_match_end = 0; | 3569 | bool giveup_match_end = 0; |
| 3575 | 3570 | ||
| 3576 | if (beg_offset != 0) | 3571 | if (beg_offset != 0) |
| 3577 | { | 3572 | { |
| @@ -4427,8 +4422,8 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file | |||
| 4427 | If it is not set locally, we anyway have to convert EOL | 4422 | If it is not set locally, we anyway have to convert EOL |
| 4428 | format if the default value of `buffer-file-coding-system' | 4423 | format if the default value of `buffer-file-coding-system' |
| 4429 | tells that it is not Unix-like (LF only) format. */ | 4424 | tells that it is not Unix-like (LF only) format. */ |
| 4430 | int using_default_coding = 0; | 4425 | bool using_default_coding = 0; |
| 4431 | int force_raw_text = 0; | 4426 | bool force_raw_text = 0; |
| 4432 | 4427 | ||
| 4433 | val = BVAR (current_buffer, buffer_file_coding_system); | 4428 | val = BVAR (current_buffer, buffer_file_coding_system); |
| 4434 | if (NILP (val) | 4429 | if (NILP (val) |
| @@ -4537,8 +4532,8 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4537 | `write-region-post-annotation-function' at the end. */) | 4532 | `write-region-post-annotation-function' at the end. */) |
| 4538 | (Lisp_Object start, Lisp_Object end, Lisp_Object filename, Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, Lisp_Object mustbenew) | 4533 | (Lisp_Object start, Lisp_Object end, Lisp_Object filename, Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, Lisp_Object mustbenew) |
| 4539 | { | 4534 | { |
| 4540 | register int desc; | 4535 | int desc; |
| 4541 | int failure; | 4536 | bool ok; |
| 4542 | int save_errno = 0; | 4537 | int save_errno = 0; |
| 4543 | const char *fn; | 4538 | const char *fn; |
| 4544 | struct stat st; | 4539 | struct stat st; |
| @@ -4548,8 +4543,8 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4548 | Lisp_Object visit_file; | 4543 | Lisp_Object visit_file; |
| 4549 | Lisp_Object annotations; | 4544 | Lisp_Object annotations; |
| 4550 | Lisp_Object encoded_filename; | 4545 | Lisp_Object encoded_filename; |
| 4551 | int visiting = (EQ (visit, Qt) || STRINGP (visit)); | 4546 | bool visiting = (EQ (visit, Qt) || STRINGP (visit)); |
| 4552 | int quietly = !NILP (visit); | 4547 | bool quietly = !NILP (visit); |
| 4553 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | 4548 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
| 4554 | struct buffer *given_buffer; | 4549 | struct buffer *given_buffer; |
| 4555 | struct coding_system coding; | 4550 | struct coding_system coding; |
| @@ -4713,37 +4708,27 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4713 | 4708 | ||
| 4714 | UNGCPRO; | 4709 | UNGCPRO; |
| 4715 | 4710 | ||
| 4716 | failure = 0; | ||
| 4717 | immediate_quit = 1; | 4711 | immediate_quit = 1; |
| 4718 | 4712 | ||
| 4719 | if (STRINGP (start)) | 4713 | if (STRINGP (start)) |
| 4720 | { | 4714 | ok = a_write (desc, start, 0, SCHARS (start), &annotations, &coding); |
| 4721 | failure = 0 > a_write (desc, start, 0, SCHARS (start), | ||
| 4722 | &annotations, &coding); | ||
| 4723 | save_errno = errno; | ||
| 4724 | } | ||
| 4725 | else if (XINT (start) != XINT (end)) | 4715 | else if (XINT (start) != XINT (end)) |
| 4726 | { | 4716 | ok = a_write (desc, Qnil, XINT (start), XINT (end) - XINT (start), |
| 4727 | failure = 0 > a_write (desc, Qnil, | 4717 | &annotations, &coding); |
| 4728 | XINT (start), XINT (end) - XINT (start), | ||
| 4729 | &annotations, &coding); | ||
| 4730 | save_errno = errno; | ||
| 4731 | } | ||
| 4732 | else | 4718 | else |
| 4733 | { | 4719 | { |
| 4734 | /* If file was empty, still need to write the annotations */ | 4720 | /* If file was empty, still need to write the annotations. */ |
| 4735 | coding.mode |= CODING_MODE_LAST_BLOCK; | 4721 | coding.mode |= CODING_MODE_LAST_BLOCK; |
| 4736 | failure = 0 > a_write (desc, Qnil, XINT (end), 0, &annotations, &coding); | 4722 | ok = a_write (desc, Qnil, XINT (end), 0, &annotations, &coding); |
| 4737 | save_errno = errno; | ||
| 4738 | } | 4723 | } |
| 4724 | save_errno = errno; | ||
| 4739 | 4725 | ||
| 4740 | if (CODING_REQUIRE_FLUSHING (&coding) | 4726 | if (ok && CODING_REQUIRE_FLUSHING (&coding) |
| 4741 | && !(coding.mode & CODING_MODE_LAST_BLOCK) | 4727 | && !(coding.mode & CODING_MODE_LAST_BLOCK)) |
| 4742 | && ! failure) | ||
| 4743 | { | 4728 | { |
| 4744 | /* We have to flush out a data. */ | 4729 | /* We have to flush out a data. */ |
| 4745 | coding.mode |= CODING_MODE_LAST_BLOCK; | 4730 | coding.mode |= CODING_MODE_LAST_BLOCK; |
| 4746 | failure = 0 > e_write (desc, Qnil, 1, 1, &coding); | 4731 | ok = e_write (desc, Qnil, 1, 1, &coding); |
| 4747 | save_errno = errno; | 4732 | save_errno = errno; |
| 4748 | } | 4733 | } |
| 4749 | 4734 | ||
| @@ -4760,13 +4745,13 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4760 | ignore EINVAL which happens when fsync is not supported on this | 4745 | ignore EINVAL which happens when fsync is not supported on this |
| 4761 | file. */ | 4746 | file. */ |
| 4762 | if (errno != EINTR && errno != EINVAL) | 4747 | if (errno != EINTR && errno != EINVAL) |
| 4763 | failure = 1, save_errno = errno; | 4748 | ok = 0, save_errno = errno; |
| 4764 | } | 4749 | } |
| 4765 | #endif | 4750 | #endif |
| 4766 | 4751 | ||
| 4767 | /* NFS can report a write failure now. */ | 4752 | /* NFS can report a write failure now. */ |
| 4768 | if (emacs_close (desc) < 0) | 4753 | if (emacs_close (desc) < 0) |
| 4769 | failure = 1, save_errno = errno; | 4754 | ok = 0, save_errno = errno; |
| 4770 | 4755 | ||
| 4771 | stat (fn, &st); | 4756 | stat (fn, &st); |
| 4772 | 4757 | ||
| @@ -4803,7 +4788,7 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4803 | current_buffer->modtime_size = st.st_size; | 4788 | current_buffer->modtime_size = st.st_size; |
| 4804 | } | 4789 | } |
| 4805 | 4790 | ||
| 4806 | if (failure) | 4791 | if (! ok) |
| 4807 | error ("IO error writing %s: %s", SDATA (filename), | 4792 | error ("IO error writing %s: %s", SDATA (filename), |
| 4808 | emacs_strerror (save_errno)); | 4793 | emacs_strerror (save_errno)); |
| 4809 | 4794 | ||
| @@ -4859,7 +4844,8 @@ build_annotations (Lisp_Object start, Lisp_Object end) | |||
| 4859 | Lisp_Object p, res; | 4844 | Lisp_Object p, res; |
| 4860 | struct gcpro gcpro1, gcpro2; | 4845 | struct gcpro gcpro1, gcpro2; |
| 4861 | Lisp_Object original_buffer; | 4846 | Lisp_Object original_buffer; |
| 4862 | int i, used_global = 0; | 4847 | int i; |
| 4848 | bool used_global = 0; | ||
| 4863 | 4849 | ||
| 4864 | XSETBUFFER (original_buffer, current_buffer); | 4850 | XSETBUFFER (original_buffer, current_buffer); |
| 4865 | 4851 | ||
| @@ -4939,11 +4925,11 @@ build_annotations (Lisp_Object start, Lisp_Object end) | |||
| 4939 | 4925 | ||
| 4940 | We modify *ANNOT by discarding elements as we use them up. | 4926 | We modify *ANNOT by discarding elements as we use them up. |
| 4941 | 4927 | ||
| 4942 | The return value is negative in case of system call failure. */ | 4928 | Return true if successful. */ |
| 4943 | 4929 | ||
| 4944 | static int | 4930 | static bool |
| 4945 | a_write (int desc, Lisp_Object string, ptrdiff_t pos, | 4931 | a_write (int desc, Lisp_Object string, ptrdiff_t pos, |
| 4946 | register ptrdiff_t nchars, Lisp_Object *annot, | 4932 | ptrdiff_t nchars, Lisp_Object *annot, |
| 4947 | struct coding_system *coding) | 4933 | struct coding_system *coding) |
| 4948 | { | 4934 | { |
| 4949 | Lisp_Object tem; | 4935 | Lisp_Object tem; |
| @@ -4965,29 +4951,29 @@ a_write (int desc, Lisp_Object string, ptrdiff_t pos, | |||
| 4965 | /* Output buffer text up to the next annotation's position. */ | 4951 | /* Output buffer text up to the next annotation's position. */ |
| 4966 | if (nextpos > pos) | 4952 | if (nextpos > pos) |
| 4967 | { | 4953 | { |
| 4968 | if (0 > e_write (desc, string, pos, nextpos, coding)) | 4954 | if (!e_write (desc, string, pos, nextpos, coding)) |
| 4969 | return -1; | 4955 | return 0; |
| 4970 | pos = nextpos; | 4956 | pos = nextpos; |
| 4971 | } | 4957 | } |
| 4972 | /* Output the annotation. */ | 4958 | /* Output the annotation. */ |
| 4973 | tem = Fcdr (Fcar (*annot)); | 4959 | tem = Fcdr (Fcar (*annot)); |
| 4974 | if (STRINGP (tem)) | 4960 | if (STRINGP (tem)) |
| 4975 | { | 4961 | { |
| 4976 | if (0 > e_write (desc, tem, 0, SCHARS (tem), coding)) | 4962 | if (!e_write (desc, tem, 0, SCHARS (tem), coding)) |
| 4977 | return -1; | 4963 | return 0; |
| 4978 | } | 4964 | } |
| 4979 | *annot = Fcdr (*annot); | 4965 | *annot = Fcdr (*annot); |
| 4980 | } | 4966 | } |
| 4981 | return 0; | 4967 | return 1; |
| 4982 | } | 4968 | } |
| 4983 | 4969 | ||
| 4984 | 4970 | ||
| 4985 | /* Write text in the range START and END into descriptor DESC, | 4971 | /* Write text in the range START and END into descriptor DESC, |
| 4986 | encoding them with coding system CODING. If STRING is nil, START | 4972 | encoding them with coding system CODING. If STRING is nil, START |
| 4987 | and END are character positions of the current buffer, else they | 4973 | and END are character positions of the current buffer, else they |
| 4988 | are indexes to the string STRING. */ | 4974 | are indexes to the string STRING. Return true if successful. */ |
| 4989 | 4975 | ||
| 4990 | static int | 4976 | static bool |
| 4991 | e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end, | 4977 | e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end, |
| 4992 | struct coding_system *coding) | 4978 | struct coding_system *coding) |
| 4993 | { | 4979 | { |
| @@ -5056,12 +5042,12 @@ e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end, | |||
| 5056 | coding->produced); | 5042 | coding->produced); |
| 5057 | 5043 | ||
| 5058 | if (coding->produced) | 5044 | if (coding->produced) |
| 5059 | return -1; | 5045 | return 0; |
| 5060 | } | 5046 | } |
| 5061 | start += coding->consumed_char; | 5047 | start += coding->consumed_char; |
| 5062 | } | 5048 | } |
| 5063 | 5049 | ||
| 5064 | return 0; | 5050 | return 1; |
| 5065 | } | 5051 | } |
| 5066 | 5052 | ||
| 5067 | DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, | 5053 | DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, |
| @@ -5300,12 +5286,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) | |||
| 5300 | { | 5286 | { |
| 5301 | struct buffer *old = current_buffer, *b; | 5287 | struct buffer *old = current_buffer, *b; |
| 5302 | Lisp_Object tail, buf, hook; | 5288 | Lisp_Object tail, buf, hook; |
| 5303 | int auto_saved = 0; | 5289 | bool auto_saved = 0; |
| 5304 | int do_handled_files; | 5290 | int do_handled_files; |
| 5305 | Lisp_Object oquit; | 5291 | Lisp_Object oquit; |
| 5306 | FILE *stream = NULL; | 5292 | FILE *stream = NULL; |
| 5307 | ptrdiff_t count = SPECPDL_INDEX (); | 5293 | ptrdiff_t count = SPECPDL_INDEX (); |
| 5308 | int orig_minibuffer_auto_raise = minibuffer_auto_raise; | 5294 | bool orig_minibuffer_auto_raise = minibuffer_auto_raise; |
| 5309 | bool old_message_p = 0; | 5295 | bool old_message_p = 0; |
| 5310 | struct gcpro gcpro1, gcpro2; | 5296 | struct gcpro gcpro1, gcpro2; |
| 5311 | 5297 | ||
| @@ -5452,7 +5438,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) | |||
| 5452 | if (!auto_saved && NILP (no_message)) | 5438 | if (!auto_saved && NILP (no_message)) |
| 5453 | message1 ("Auto-saving..."); | 5439 | message1 ("Auto-saving..."); |
| 5454 | internal_condition_case (auto_save_1, Qt, auto_save_error); | 5440 | internal_condition_case (auto_save_1, Qt, auto_save_error); |
| 5455 | auto_saved++; | 5441 | auto_saved = 1; |
| 5456 | BUF_AUTOSAVE_MODIFF (b) = BUF_MODIFF (b); | 5442 | BUF_AUTOSAVE_MODIFF (b) = BUF_MODIFF (b); |
| 5457 | XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG); | 5443 | XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG); |
| 5458 | set_buffer_internal (old); | 5444 | set_buffer_internal (old); |