so don't look for #include "foo" the source-file directory. */
static int ignore_srcdir;
\f
+/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
+ retrying if necessary. Return the actual number of bytes read. */
+
+static int
+safe_read (desc, ptr, len)
+ int desc;
+ char *ptr;
+ int len;
+{
+ int left = len;
+ while (left > 0) {
+ int nchars = read (desc, ptr, left);
+ if (nchars < 0)
+ return nchars;
+ if (nchars == 0)
+ break;
+ ptr += nchars;
+ left -= nchars;
+ }
+ return len - left;
+}
+
+/* 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 (desc, ptr, len);
+ if (written < 0)
+ pfatal_with_name (out_fname);
+ ptr += written;
+ len -= written;
+ }
+}
+\f
int
main (argc, argv)
int argc;
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
bufp = fp->buf;
for (;;) {
- cnt = read (f, bufp, bsize - size);
+ cnt = safe_read (f, bufp, bsize - size);
if (cnt < 0) goto perror; /* error! */
if (cnt == 0) break; /* End of file */
size += cnt;
fp->buf = (U_CHAR *) xmalloc (st_size + 2);
while (st_size > 0) {
- i = read (f, fp->buf + fp->length, st_size);
+ i = safe_read (f, fp->buf + fp->length, st_size);
if (i <= 0) {
if (i == 0) break;
goto perror;
/* Read the file contents, knowing that st_size is an upper bound
on the number of bytes we can read. */
while (st_size > 0) {
- i = read (f, fp->buf + fp->length, st_size);
+ i = safe_read (f, fp->buf + fp->length, st_size);
if (i <= 0) {
if (i == 0) break;
goto nope;
bufp = basep;
for (;;) {
- i = read (f, bufp, bsize - st_size);
+ i = safe_read (f, bufp, bsize - st_size);
if (i < 0)
goto nope; /* error! */
if (i == 0)
buf = xmalloc (st_size + 2);
while (st_size > 0)
{
- i = read (pcf, buf + length, st_size);
+ i = safe_read (pcf, buf + length, st_size);
if (i < 0)
goto nope;
if (i == 0)
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