Commit f75d7a91 authored by Paul Eggert's avatar Paul Eggert
Browse files

* fileio.c, filelock.c, floatfns.c, fns.c: Use bool for boolean.

* fileio.c (auto_saving, auto_save_error_occurred, make_temp_name)
(Fexpand_file_name, barf_or_query_if_file_exists, Fcopy_file)
(file_name_absolute_p, Fsubstitute_in_file_name):
(check_executable, check_writable, Ffile_accessible_directory_p)
(Fset_file_selinux_context, Fdefault_file_modes)
(Finsert_file_contents, choose_write_coding_system)
(Fwrite_region, build_annotations, a_write, e_write)
(Fdo_auto_save):
* filelock.c (boot_time_initialized, get_boot_time)
(get_boot_time_1, lock_file_1, within_one_second):
* floatfns.c (in_float):
* fns.c (concat, internal_equal, Frequire, base64_encode_1)
(base64_decode_1, cmpfn_eql, cmpfn_user_defined)
(sweep_weak_table, sweep_weak_hash_tables, secure_hash):
* lisp.h (struct Lisp_Hash_Table.cmpfn):
* window.c (compare_window_configurations):
Use bool for booleans.
* fileio.c (auto_saving_dir_umask, auto_saving_mode_bits)
(Fdefault_file_modes): Now mode_t, not int, for modes.
(Fdo_auto_save): Set a boolean to 1 rather than using ++.
(internal_delete_file): Now returns void, not a (boolean) int,
since nobody was looking at the return value.
* lisp.h, window.h: Adjust to above API changes.
parent 7e570fbf
2012-09-05 Paul Eggert <eggert@cs.ucla.edu> 2012-09-05 Paul Eggert <eggert@cs.ucla.edu>
   
* fileio.c, filelock.c, floatfns.c, fns.c: Use bool for boolean.
* fileio.c (auto_saving, auto_save_error_occurred, make_temp_name)
(Fexpand_file_name, barf_or_query_if_file_exists, Fcopy_file)
(file_name_absolute_p, Fsubstitute_in_file_name):
(check_executable, check_writable, Ffile_accessible_directory_p)
(Fset_file_selinux_context, Fdefault_file_modes)
(Finsert_file_contents, choose_write_coding_system)
(Fwrite_region, build_annotations, a_write, e_write)
(Fdo_auto_save):
* filelock.c (boot_time_initialized, get_boot_time)
(get_boot_time_1, lock_file_1, within_one_second):
* floatfns.c (in_float):
* fns.c (concat, internal_equal, Frequire, base64_encode_1)
(base64_decode_1, cmpfn_eql, cmpfn_user_defined)
(sweep_weak_table, sweep_weak_hash_tables, secure_hash):
* lisp.h (struct Lisp_Hash_Table.cmpfn):
* window.c (compare_window_configurations):
Use bool for booleans.
* fileio.c (auto_saving_dir_umask, auto_saving_mode_bits)
(Fdefault_file_modes): Now mode_t, not int, for modes.
(Fdo_auto_save): Set a boolean to 1 rather than using ++.
(internal_delete_file): Now returns void, not a (boolean) int,
since nobody was looking at the return value.
* lisp.h, window.h: Adjust to above API changes.
* xdisp.c (set_message): Simplify and reindent last change. * xdisp.c (set_message): Simplify and reindent last change.
   
2012-09-05 Juanma Barranquero <lekktu@gmail.com> 2012-09-05 Juanma Barranquero <lekktu@gmail.com>
......
...@@ -85,18 +85,18 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -85,18 +85,18 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "commands.h" #include "commands.h"
/* Nonzero during writing of auto-save files. */ /* True during writing of auto-save files. */
static int auto_saving; static bool auto_saving;
/* Nonzero umask during creation of auto-save directories. */ /* Nonzero umask during creation of auto-save directories. */
static int auto_saving_dir_umask; static mode_t auto_saving_dir_umask;
/* Set by auto_save_1 to mode of original file so Fwrite_region will create /* Set by auto_save_1 to mode of original file so Fwrite_region will create
a new file with the same mode as the original. */ a new file with the same mode as the original. */
static int auto_save_mode_bits; static mode_t auto_save_mode_bits;
/* Set by auto_save_1 if an error occurred during the last auto-save. */ /* Set by auto_save_1 if an error occurred during the last auto-save. */
static int auto_save_error_occurred; static bool auto_save_error_occurred;
/* The symbol bound to coding-system-for-read when /* The symbol bound to coding-system-for-read when
insert-file-contents is called for recovering a file. This is not insert-file-contents is called for recovering a file. This is not
...@@ -145,9 +145,9 @@ Lisp_Object Qfile_name_history; ...@@ -145,9 +145,9 @@ Lisp_Object Qfile_name_history;
static Lisp_Object Qcar_less_than_car; static Lisp_Object Qcar_less_than_car;
static int a_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, static bool a_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t,
Lisp_Object *, struct coding_system *); Lisp_Object *, struct coding_system *);
static int e_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, static bool e_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t,
struct coding_system *); struct coding_system *);
...@@ -595,7 +595,7 @@ static unsigned make_temp_name_count, make_temp_name_count_initialized_p; ...@@ -595,7 +595,7 @@ static unsigned make_temp_name_count, make_temp_name_count_initialized_p;
which has no existing file. To make this work, PREFIX should be which has no existing file. To make this work, PREFIX should be
an absolute file name. an absolute file name.
BASE64_P non-zero means add the pid as 3 characters in base64 BASE64_P means add the pid as 3 characters in base64
encoding. In this case, 6 characters will be added to PREFIX to encoding. In this case, 6 characters will be added to PREFIX to
form the file name. Otherwise, if Emacs is running on a system form the file name. Otherwise, if Emacs is running on a system
with long file names, add the pid as a decimal number. 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,7 +604,7 @@ static unsigned make_temp_name_count, make_temp_name_count_initialized_p;
generated. */ generated. */
Lisp_Object Lisp_Object
make_temp_name (Lisp_Object prefix, int base64_p) make_temp_name (Lisp_Object prefix, bool base64_p)
{ {
Lisp_Object val; Lisp_Object val;
int len, clen; int len, clen;
...@@ -761,8 +761,8 @@ filesystem tree, not (expand-file-name ".." dirname). */) ...@@ -761,8 +761,8 @@ filesystem tree, not (expand-file-name ".." dirname). */)
struct passwd *pw; struct passwd *pw;
#ifdef DOS_NT #ifdef DOS_NT
int drive = 0; int drive = 0;
int collapse_newdir = 1; bool collapse_newdir = 1;
int is_escaped = 0; bool is_escaped = 0;
#endif /* DOS_NT */ #endif /* DOS_NT */
ptrdiff_t length; ptrdiff_t length;
Lisp_Object handler, result, handled_name; Lisp_Object handler, result, handled_name;
...@@ -920,10 +920,9 @@ filesystem tree, not (expand-file-name ".." dirname). */) ...@@ -920,10 +920,9 @@ filesystem tree, not (expand-file-name ".." dirname). */)
/* If it turns out that the filename we want to return is just a /* If it turns out that the filename we want to return is just a
suffix of FILENAME, we don't need to go through and edit suffix of FILENAME, we don't need to go through and edit
things; we just need to construct a new string using data things; we just need to construct a new string using data
starting at the middle of FILENAME. If we set lose to a starting at the middle of FILENAME. If we set LOSE, that
non-zero value, that means we've discovered that we can't do means we've discovered that we can't do that cool trick. */
that cool trick. */ bool lose = 0;
int lose = 0;
char *p = nm; char *p = nm;
while (*p) while (*p)
...@@ -1360,7 +1359,6 @@ See also the function `substitute-in-file-name'.") ...@@ -1360,7 +1359,6 @@ See also the function `substitute-in-file-name'.")
ptrdiff_t tlen; ptrdiff_t tlen;
unsigned char *target; unsigned char *target;
struct passwd *pw; struct passwd *pw;
int lose;
CHECK_STRING (name); CHECK_STRING (name);
nm = SDATA (name); nm = SDATA (name);
...@@ -1369,8 +1367,8 @@ See also the function `substitute-in-file-name'.") ...@@ -1369,8 +1367,8 @@ See also the function `substitute-in-file-name'.")
If no /./ or /../ we can return right away. */ If no /./ or /../ we can return right away. */
if (nm[0] == '/') if (nm[0] == '/')
{ {
bool lose = 0;
p = nm; p = nm;
lose = 0;
while (*p) while (*p)
{ {
if (p[0] == '/' && p[1] == '/' if (p[0] == '/' && p[1] == '/'
...@@ -1494,7 +1492,7 @@ See also the function `substitute-in-file-name'.") ...@@ -1494,7 +1492,7 @@ See also the function `substitute-in-file-name'.")
#endif #endif
/* If /~ or // appears, discard everything through first slash. */ /* If /~ or // appears, discard everything through first slash. */
static int static bool
file_name_absolute_p (const char *filename) file_name_absolute_p (const char *filename)
{ {
return return
...@@ -1560,12 +1558,10 @@ If `//' appears, everything up to and including the first of ...@@ -1560,12 +1558,10 @@ If `//' appears, everything up to and including the first of
those `/' is discarded. */) those `/' is discarded. */)
(Lisp_Object filename) (Lisp_Object filename)
{ {
char *nm; char *nm, *s, *p, *o, *x, *endp;
register char *s, *p, *o, *x, *endp;
char *target = NULL; char *target = NULL;
int total = 0; int total = 0;
int substituted = 0; bool substituted = 0;
bool multibyte; bool multibyte;
char *xnm; char *xnm;
Lisp_Object handler; Lisp_Object handler;
...@@ -1780,7 +1776,7 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) ...@@ -1780,7 +1776,7 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir)
} }
/* Signal an error if the file ABSNAME already exists. /* Signal an error if the file ABSNAME already exists.
If INTERACTIVE is nonzero, ask the user whether to proceed, If INTERACTIVE, ask the user whether to proceed,
and bypass the error if the user says to go ahead. and bypass the error if the user says to go ahead.
QUERYSTRING is a name for the action that is being considered QUERYSTRING is a name for the action that is being considered
to alter the file. to alter the file.
...@@ -1789,13 +1785,14 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) ...@@ -1789,13 +1785,14 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir)
If the file does not exist, STATPTR->st_mode is set to 0. If the file does not exist, STATPTR->st_mode is set to 0.
If STATPTR is null, we don't store into it. If STATPTR is null, we don't store into it.
If QUICK is nonzero, we ask for y or n, not yes or no. */ If QUICK, ask for y or n, not yes or no. */
static void static void
barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring, barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring,
int interactive, struct stat *statptr, int quick) bool interactive, struct stat *statptr,
bool quick)
{ {
register Lisp_Object tem, encoded_filename; Lisp_Object tem, encoded_filename;
struct stat statbuf; struct stat statbuf;
struct gcpro gcpro1; struct gcpro gcpro1;
...@@ -1869,11 +1866,11 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) ...@@ -1869,11 +1866,11 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
Lisp_Object handler; Lisp_Object handler;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
ptrdiff_t count = SPECPDL_INDEX (); ptrdiff_t count = SPECPDL_INDEX ();
int input_file_statable_p; bool input_file_statable_p;
Lisp_Object encoded_file, encoded_newname; Lisp_Object encoded_file, encoded_newname;
#if HAVE_LIBSELINUX #if HAVE_LIBSELINUX
security_context_t con; security_context_t con;
int fail, conlength = 0; int conlength = 0;
#endif #endif
encoded_file = encoded_newname = Qnil; encoded_file = encoded_newname = Qnil;
...@@ -1988,7 +1985,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) ...@@ -1988,7 +1985,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
S_IREAD | S_IWRITE); S_IREAD | S_IWRITE);
#else /* not MSDOS */ #else /* not MSDOS */
{ {
int new_mask = 0666; mode_t new_mask = 0666;
if (input_file_statable_p) if (input_file_statable_p)
{ {
if (!NILP (preserve_uid_gid)) if (!NILP (preserve_uid_gid))
...@@ -2018,7 +2015,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) ...@@ -2018,7 +2015,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
owner and group. */ owner and group. */
if (input_file_statable_p) if (input_file_statable_p)
{ {
int mode_mask = 07777; mode_t mode_mask = 07777;
if (!NILP (preserve_uid_gid)) if (!NILP (preserve_uid_gid))
{ {
/* Attempt to change owner and group. If that doesn't work /* 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,7 +2038,7 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
if (conlength > 0) if (conlength > 0)
{ {
/* Set the modified context back to the file. */ /* Set the modified context back to the file. */
fail = fsetfilecon (ofd, con); bool fail = fsetfilecon (ofd, con) != 0;
/* See http://debbugs.gnu.org/11245 for ENOTSUP. */ /* See http://debbugs.gnu.org/11245 for ENOTSUP. */
if (fail && errno != ENOTSUP) if (fail && errno != ENOTSUP)
report_file_error ("Doing fsetfilecon", Fcons (newname, Qnil)); report_file_error ("Doing fsetfilecon", Fcons (newname, Qnil));
...@@ -2184,17 +2181,14 @@ internal_delete_file_1 (Lisp_Object ignore) ...@@ -2184,17 +2181,14 @@ internal_delete_file_1 (Lisp_Object ignore)
return Qt; return Qt;
} }
/* Delete file FILENAME, returning 1 if successful and 0 if failed. /* Delete file FILENAME.
This ignores `delete-by-moving-to-trash'. */ This ignores `delete-by-moving-to-trash'. */
int void
internal_delete_file (Lisp_Object filename) internal_delete_file (Lisp_Object filename)
{ {
Lisp_Object tem; internal_condition_case_2 (Fdelete_file, filename, Qnil,
tem = internal_condition_case_2 (Fdelete_file, filename, Qnil,
Qt, internal_delete_file_1); Qt, internal_delete_file_1);
return NILP (tem);
} }
DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, DEFUN ("rename-file", Frename_file, Srename_file, 2, 3,
...@@ -2430,9 +2424,9 @@ On Unix, this is a name starting with a `/' or a `~'. */) ...@@ -2430,9 +2424,9 @@ On Unix, this is a name starting with a `/' or a `~'. */)
return file_name_absolute_p (SSDATA (filename)) ? Qt : Qnil; return file_name_absolute_p (SSDATA (filename)) ? Qt : Qnil;
} }
/* Return nonzero if file FILENAME exists and can be executed. */ /* Return true if file FILENAME exists and can be executed. */
static int static bool
check_executable (char *filename) check_executable (char *filename)
{ {
#ifdef DOS_NT #ifdef DOS_NT
...@@ -2452,9 +2446,9 @@ check_executable (char *filename) ...@@ -2452,9 +2446,9 @@ check_executable (char *filename)
#endif /* not DOS_NT */ #endif /* not DOS_NT */
} }
/* Return nonzero if file FILENAME exists and can be written. */ /* Return true if file FILENAME exists and can be written. */
static int static bool
check_writable (const char *filename) check_writable (const char *filename)
{ {
#ifdef MSDOS #ifdef MSDOS
...@@ -2464,7 +2458,7 @@ check_writable (const char *filename) ...@@ -2464,7 +2458,7 @@ check_writable (const char *filename)
return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode));
#else /* not MSDOS */ #else /* not MSDOS */
#ifdef HAVE_EUIDACCESS #ifdef HAVE_EUIDACCESS
int res = (euidaccess (filename, 2) >= 0); bool res = (euidaccess (filename, 2) >= 0);
#ifdef CYGWIN #ifdef CYGWIN
/* euidaccess may have returned failure because Cygwin couldn't /* euidaccess may have returned failure because Cygwin couldn't
determine the file's UID or GID; if so, we return success. */ determine the file's UID or GID; if so, we return success. */
...@@ -2732,7 +2726,7 @@ searchable directory. */) ...@@ -2732,7 +2726,7 @@ searchable directory. */)
(Lisp_Object filename) (Lisp_Object filename)
{ {
Lisp_Object handler; Lisp_Object handler;
int tem; bool tem;
struct gcpro gcpro1; struct gcpro gcpro1;
/* If the file name has special constructs in it, /* If the file name has special constructs in it,
...@@ -2868,7 +2862,8 @@ compiled with SELinux support. */) ...@@ -2868,7 +2862,8 @@ compiled with SELinux support. */)
Lisp_Object type = CAR_SAFE (CDR_SAFE (CDR_SAFE (context))); Lisp_Object type = CAR_SAFE (CDR_SAFE (CDR_SAFE (context)));
Lisp_Object range = CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (context)))); Lisp_Object range = CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (context))));
security_context_t con; security_context_t con;
int fail, conlength; bool fail;
int conlength;
context_t parsed_con; context_t parsed_con;
#endif #endif
...@@ -2912,8 +2907,9 @@ compiled with SELinux support. */) ...@@ -2912,8 +2907,9 @@ compiled with SELinux support. */)
} }
/* Set the modified context back to the file. */ /* Set the modified context back to the file. */
fail = lsetfilecon (SSDATA (encoded_absname), fail = (lsetfilecon (SSDATA (encoded_absname),
context_str (parsed_con)); context_str (parsed_con))
!= 0);
/* See http://debbugs.gnu.org/11245 for ENOTSUP. */ /* See http://debbugs.gnu.org/11245 for ENOTSUP. */
if (fail && errno != ENOTSUP) if (fail && errno != ENOTSUP)
report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil)); 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, ...@@ -3004,7 +3000,7 @@ DEFUN ("default-file-modes", Fdefault_file_modes, Sdefault_file_modes, 0, 0, 0,
The value is an integer. */) The value is an integer. */)
(void) (void)
{ {
int realmask; mode_t realmask;
Lisp_Object value; Lisp_Object value;
BLOCK_INPUT; BLOCK_INPUT;
...@@ -3246,29 +3242,29 @@ variable `last-coding-system-used' to the coding system actually used. */) ...@@ -3246,29 +3242,29 @@ variable `last-coding-system-used' to the coding system actually used. */)
struct stat st; struct stat st;
int file_status; int file_status;
EMACS_TIME mtime; EMACS_TIME mtime;
register int fd; int fd;
ptrdiff_t inserted = 0; ptrdiff_t inserted = 0;
int nochange = 0; bool nochange = 0;
register ptrdiff_t how_much; ptrdiff_t how_much;
off_t beg_offset, end_offset; off_t beg_offset, end_offset;
register int unprocessed; int unprocessed;
ptrdiff_t count = SPECPDL_INDEX (); ptrdiff_t count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
Lisp_Object handler, val, insval, orig_filename, old_undo; Lisp_Object handler, val, insval, orig_filename, old_undo;
Lisp_Object p; Lisp_Object p;
ptrdiff_t total = 0; ptrdiff_t total = 0;
int not_regular = 0; bool not_regular = 0;
int save_errno = 0; int save_errno = 0;
char read_buf[READ_BUF_SIZE]; char read_buf[READ_BUF_SIZE];
struct coding_system coding; struct coding_system coding;
char buffer[1 << 14]; char buffer[1 << 14];
int replace_handled = 0; bool replace_handled = 0;
int set_coding_system = 0; bool set_coding_system = 0;
Lisp_Object coding_system; Lisp_Object coding_system;
int read_quit = 0; bool read_quit = 0;
Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark; Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark;
int we_locked_file = 0; bool we_locked_file = 0;
int deferred_remove_unwind_protect = 0; bool deferred_remove_unwind_protect = 0;
if (current_buffer->base_buffer && ! NILP (visit)) if (current_buffer->base_buffer && ! NILP (visit))
error ("Cannot do file visiting in an indirect buffer"); 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,9 +3565,9 @@ variable `last-coding-system-used' to the coding system actually used. */)
ptrdiff_t same_at_end = ZV_BYTE; ptrdiff_t same_at_end = ZV_BYTE;
ptrdiff_t overlap; ptrdiff_t overlap;
/* There is still a possibility we will find the need to do code /* There is still a possibility we will find the need to do code
conversion. If that happens, we set this variable to 1 to conversion. If that happens, set this variable to
give up on handling REPLACE in the optimized way. */ give up on handling REPLACE in the optimized way. */
int giveup_match_end = 0; bool giveup_match_end = 0;
if (beg_offset != 0) if (beg_offset != 0)
{ {
...@@ -4427,8 +4423,8 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file ...@@ -4427,8 +4423,8 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file
If it is not set locally, we anyway have to convert EOL If it is not set locally, we anyway have to convert EOL
format if the default value of `buffer-file-coding-system' format if the default value of `buffer-file-coding-system'
tells that it is not Unix-like (LF only) format. */ tells that it is not Unix-like (LF only) format. */
int using_default_coding = 0; bool using_default_coding = 0;
int force_raw_text = 0; bool force_raw_text = 0;
val = BVAR (current_buffer, buffer_file_coding_system); val = BVAR (current_buffer, buffer_file_coding_system);
if (NILP (val) if (NILP (val)
...@@ -4537,8 +4533,8 @@ This calls `write-region-annotate-functions' at the start, and ...@@ -4537,8 +4533,8 @@ This calls `write-region-annotate-functions' at the start, and
`write-region-post-annotation-function' at the end. */) `write-region-post-annotation-function' at the end. */)
(Lisp_Object start, Lisp_Object end, Lisp_Object filename, Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, Lisp_Object mustbenew) (Lisp_Object start, Lisp_Object end, Lisp_Object filename, Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, Lisp_Object mustbenew)
{ {
register int desc; int desc;
int failure; bool ok;
int save_errno = 0; int save_errno = 0;
const char *fn; const char *fn;
struct stat st; struct stat st;
...@@ -4548,8 +4544,8 @@ This calls `write-region-annotate-functions' at the start, and ...@@ -4548,8 +4544,8 @@ This calls `write-region-annotate-functions' at the start, and
Lisp_Object visit_file; Lisp_Object visit_file;
Lisp_Object annotations; Lisp_Object annotations;
Lisp_Object encoded_filename; Lisp_Object encoded_filename;
int visiting = (EQ (visit, Qt) || STRINGP (visit)); bool visiting = (EQ (visit, Qt) || STRINGP (visit));
int quietly = !NILP (visit); bool quietly = !NILP (visit);
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
struct buffer *given_buffer; struct buffer *given_buffer;
struct coding_system coding; struct coding_system coding;
...@@ -4713,37 +4709,27 @@ This calls `write-region-annotate-functions' at the start, and ...@@ -4713,37 +4709,27 @@ This calls `write-region-annotate-functions' at the start, and
UNGCPRO; UNGCPRO;
failure = 0;
immediate_quit = 1; immediate_quit = 1;
if (STRINGP (start)) if (STRINGP (start))
{ ok = a_write (desc, start, 0, SCHARS (start), &annotations, &coding);
failure = 0 > a_write (desc, start, 0, SCHARS (start),
&annotations, &coding);
save_errno = errno;
}
else if (XINT (start) != XINT (end)) else if (XINT (start) != XINT (end))
{ ok = a_write (desc, Qnil, XINT (start), XINT (end) - XINT (start),
failure = 0 > a_write (desc, Qnil,
XINT (start), XINT (end) - XINT (start),
&annotations, &coding); &annotations, &coding);
save_errno = errno;
}
else else
{ {
/* If file was empty, still need to write the annotations */ /* If file was empty, still need to write the annotations. */
coding.mode |= CODING_MODE_LAST_BLOCK; coding.mode |= CODING_MODE_LAST_BLOCK;
failure = 0 > a_write (desc, Qnil, XINT (end), 0, &annotations, &coding); ok = a_write (desc, Qnil, XINT (end), 0, &annotations, &coding);
save_errno = errno;
} }
save_errno = errno;
if (CODING_REQUIRE_FLUSHING (&coding) if (ok && CODING_REQUIRE_FLUSHING (&coding)
&& !(coding.mode & CODING_MODE_LAST_BLOCK) && !(coding.mode & CODING_MODE_LAST_BLOCK))
&& ! failure)
{ {
/* We have to flush out a data. */ /* We have to flush out a data. */
coding.mode |= CODING_MODE_LAST_BLOCK; coding.mode |= CODING_MODE_LAST_BLOCK;
failure = 0 > e_write (desc, Qnil, 1, 1, &coding); ok = e_write (desc, Qnil, 1, 1, &coding);
save_errno = errno; save_errno = errno;
} }
...@@ -4760,13 +4746,13 @@ This calls `write-region-annotate-functions' at the start, and ...@@ -4760,13 +4746,13 @@ This calls `write-region-annotate-functions' at the start, and
ignore EINVAL which happens when fsync is not supported on this ignore EINVAL which happens when fsync is not supported on this
file. */ file. */
if (errno != EINTR && errno != EINVAL) if (errno != EINTR && errno != EINVAL)
failure = 1, save_errno = errno; ok = 0, save_errno = errno;
} }
#endif #endif
/* NFS can report a write failure now. */ /* NFS can report a write failure now. */
if (emacs_close (desc) < 0) if (emacs_close (desc) < 0)
failure = 1, save_errno = errno; ok = 0, save_errno = errno;
stat (fn, &st); stat (fn, &st);
...@@ -4803,7 +4789,7 @@ This calls `write-region-annotate-functions' at the start, and ...@@ -4803,7 +4789,7 @@ This calls `write-region-annotate-functions' at the start, and
current_buffer->modtime_size = st.st_size; current_buffer->modtime_size = st.st_size;