aboutsummaryrefslogtreecommitdiff
path: root/gcc/protoize.c
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-11-02 08:30:37 +0000
committerRichard Stallman <rms@gnu.org>1993-11-02 08:30:37 +0000
commitfa0cd3ff7cb011bf28a6c64f4fa6bc6e9ac518db (patch)
tree101eef46591295e8f6cf5377aa2200019e99e41c /gcc/protoize.c
parent83a4b97f7d16c257beb423ea3835f8a8c9ad86c8 (diff)
downloadgcc-fa0cd3ff7cb011bf28a6c64f4fa6bc6e9ac518db.zip
gcc-fa0cd3ff7cb011bf28a6c64f4fa6bc6e9ac518db.tar.gz
gcc-fa0cd3ff7cb011bf28a6c64f4fa6bc6e9ac518db.tar.bz2
(edit_file): Use safe_write.
(safe_write): New subroutine. From-SVN: r5972
Diffstat (limited to 'gcc/protoize.c')
-rw-r--r--gcc/protoize.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/gcc/protoize.c b/gcc/protoize.c
index ee1db6d..7dd0d66 100644
--- a/gcc/protoize.c
+++ b/gcc/protoize.c
@@ -4033,6 +4033,26 @@ scan_for_missed_items (file_p)
}
}
+/* Write LEN bytes at PTR to descriptor DESC,
+ retrying if necessary, and treating any real error as fatal. */
+
+static void
+safe_write (desc, ptr, len, out_fname)
+ int desc;
+ char *ptr;
+ int len;
+ char *out_fname;
+{
+ while (len > 0) {
+ int written = write (fileno (stdout), ptr, len);
+ if (written < 0)
+ fprintf (stderr, "%s: error writing file `%s': %s\n",
+ pname, shortpath (NULL, out_fname), sys_errlist[errno]);
+ ptr += written;
+ len -= written;
+ }
+}
+
/* Do all editing operations for a single source file (either a "base" file
or an "include" file). To do this we read the file into memory, keep a
virgin copy there, make another cleaned in-core copy of the original file
@@ -4190,9 +4210,7 @@ edit_file (hp)
/* Write the clean file. */
- if (write (clean_file, new_clean_text_base, clean_size) != clean_size)
- fprintf (stderr, "%s: error writing file `%s': %s\n",
- pname, shortpath (NULL, clean_filename), sys_errlist[errno]);
+ safe_write (clean_file, new_clean_text_base, clean_size, clean_filename);
close (clean_file);
}
@@ -4326,10 +4344,7 @@ edit_file (hp)
{
unsigned int out_size = (repl_write_ptr + 1) - repl_text_base;
- if (write (output_file, repl_text_base, out_size) != out_size)
- fprintf (stderr, "%s: error writing file `%s': %s\n",
- pname, shortpath (NULL, convert_filename),
- sys_errlist[errno]);
+ safe_write (output_file, repl_text_base, out_size, convert_filename);
}
close (output_file);