summaryrefslogtreecommitdiff
path: root/gcc/cccp.c
diff options
context:
space:
mode:
authorrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>1993-11-01 07:07:46 +0000
committerrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>1993-11-01 07:07:46 +0000
commita73430cb79f7446bf6fa0d330c7558c705b9c22d (patch)
tree71a6dac1b66406c3581f72174bc647fb8d28e3e2 /gcc/cccp.c
parentfb424f56ea42a8dddf19884b56eda47b29d0dab0 (diff)
downloadgcc-a73430cb79f7446bf6fa0d330c7558c705b9c22d.tar.gz
(safe_write): New function.
(write_output): Use safe_write. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@5960 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cccp.c')
-rw-r--r--gcc/cccp.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/gcc/cccp.c b/gcc/cccp.c
index 5bf87046a93..671d7deb5e7 100644
--- a/gcc/cccp.c
+++ b/gcc/cccp.c
@@ -4746,6 +4746,24 @@ pcstring_used (hp)
delete_macro (hp);
}
+/* 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)
+ int desc;
+ char *ptr;
+ int len;
+{
+ while (len > 0) {
+ int written = write (fileno (stdout), ptr, len);
+ if (written < 0)
+ pfatal_with_name (out_fname);
+ ptr += written;
+ len -= written;
+ }
+}
+
/* Write the output, interspersing precompiled strings in their */
/* appropriate places. */
static void
@@ -4756,6 +4774,7 @@ write_output ()
int line_command_len = 80;
char *line_command = xmalloc (line_command_len);
int len;
+ int written;
/* In each run through the loop, either cur_buf_loc == */
/* next_string_loc, in which case we print a series of strings, or */
@@ -4776,10 +4795,8 @@ write_output ()
strcpy (quote_string (line_command + strlen (line_command),
next_string->filename),
"\n");
- if (write (fileno (stdout), line_command, strlen (line_command)) < 0)
- pfatal_with_name (out_fname);
- if (write (fileno (stdout), next_string->contents, next_string->len) < 0)
- pfatal_with_name (out_fname);
+ safe_write (fileno (stdout), line_command, strlen (line_command));
+ safe_write (fileno (stdout), next_string->contents, next_string->len);
}
next_string = next_string->chain;
}
@@ -4789,8 +4806,7 @@ write_output ()
- (cur_buf_loc - outbuf.buf))
: outbuf.bufp - cur_buf_loc);
- if (write (fileno (stdout), cur_buf_loc, len) < len)
- pfatal_with_name (out_fname);
+ safe_write (fileno (stdout), cur_buf_loc, len);
cur_buf_loc += len;
}
}