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