aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1994-03-10 15:02:45 -0500
committerRichard Kenner <kenner@gcc.gnu.org>1994-03-10 15:02:45 -0500
commit53e52f00a4e5210e9b09df4ecdcfec734a811dfa (patch)
tree59d94d9b0beb9e90b3c7b4adb96dc9d6976412b2
parentcd86f81df5baae52f2da15e4a2582d66d5c69ca6 (diff)
downloadgcc-53e52f00a4e5210e9b09df4ecdcfec734a811dfa.zip
gcc-53e52f00a4e5210e9b09df4ecdcfec734a811dfa.tar.gz
gcc-53e52f00a4e5210e9b09df4ecdcfec734a811dfa.tar.bz2
(main, finclude, check_precompiled): When safe_read returns a partial buffer, this means EOF has been reached...
(main, finclude, check_precompiled): When safe_read returns a partial buffer, this means EOF has been reached; don't try to read any more. From-SVN: r6738
-rw-r--r--gcc/cccp.c78
1 files changed, 20 insertions, 58 deletions
diff --git a/gcc/cccp.c b/gcc/cccp.c
index 951bad5..a37ab31 100644
--- a/gcc/cccp.c
+++ b/gcc/cccp.c
@@ -993,7 +993,9 @@ static int deps_column;
static int ignore_srcdir;
/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
- retrying if necessary. Return the actual number of bytes read. */
+ retrying if necessary. Return a negative value if an error occurs,
+ otherwise return the actual number of bytes read,
+ which must be LEN unless end-of-file was reached. */
static int
safe_read (desc, ptr, len)
@@ -1942,41 +1944,25 @@ main (argc, argv)
int size;
int bsize;
int cnt;
- U_CHAR *bufp;
bsize = 2000;
size = 0;
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
- bufp = fp->buf;
for (;;) {
- cnt = safe_read (f, bufp, bsize - size);
+ cnt = safe_read (f, fp->buf + size, bsize - size);
if (cnt < 0) goto perror; /* error! */
- if (cnt == 0) break; /* End of file */
size += cnt;
- bufp += cnt;
- if (bsize == size) { /* Buffer is full! */
- bsize *= 2;
- fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
- bufp = fp->buf + size; /* May have moved */
- }
+ if (size != bsize) break; /* End of file */
+ bsize *= 2;
+ fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
}
fp->length = size;
} else {
/* Read a file whose size we can determine in advance.
For the sake of VMS, st_size is just an upper bound. */
- long i;
- fp->length = 0;
fp->buf = (U_CHAR *) xmalloc (st_size + 2);
-
- while (st_size > 0) {
- i = safe_read (f, fp->buf + fp->length, st_size);
- if (i <= 0) {
- if (i == 0) break;
- goto perror;
- }
- fp->length += i;
- st_size -= i;
- }
+ fp->length = safe_read (f, fp->buf, st_size);
+ if (fp->length < 0) goto perror;
}
fp->bufp = fp->buf;
fp->if_stack = if_stack;
@@ -4563,15 +4549,8 @@ finclude (f, fname, op, system_header_p, dirptr)
/* 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 = safe_read (f, fp->buf + fp->length, st_size);
- if (i <= 0) {
- if (i == 0) break;
- goto nope;
- }
- fp->length += i;
- st_size -= i;
- }
+ fp->length = safe_read (f, fp->buf, st_size);
+ if (fp->length < 0) goto nope;
}
else if (S_ISDIR (st_mode)) {
error ("directory `%s' specified in #include", fname);
@@ -4582,29 +4561,20 @@ finclude (f, fname, op, system_header_p, dirptr)
First read the entire file into heap and
copy them into buffer on stack. */
- U_CHAR *bufp;
- U_CHAR *basep;
int bsize = 2000;
st_size = 0;
- basep = (U_CHAR *) xmalloc (bsize + 2);
- fp->buf = basep; /* So it will get freed, on error. */
- bufp = basep;
+ fp->buf = (U_CHAR *) xmalloc (bsize + 2);
for (;;) {
- i = safe_read (f, bufp, bsize - st_size);
+ i = safe_read (f, fp->buf + st_size, bsize - st_size);
if (i < 0)
goto nope; /* error! */
- if (i == 0)
- break; /* End of file */
st_size += i;
- bufp += i;
- if (bsize == st_size) { /* Buffer is full! */
- bsize *= 2;
- basep = (U_CHAR *) xrealloc (basep, bsize + 2);
- fp->buf = basep;
- bufp = basep + st_size; /* May have moved */
- }
+ if (st_size != bsize)
+ break; /* End of file */
+ bsize *= 2;
+ fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
}
fp->bufp = fp->buf;
fp->length = st_size;
@@ -4792,7 +4762,6 @@ check_precompiled (pcf, fname, limit)
long st_size;
int length = 0;
char *buf;
- int i;
char *cp;
if (pcp_outfile)
@@ -4804,16 +4773,9 @@ check_precompiled (pcf, fname, limit)
if (S_ISREG (st_mode))
{
buf = xmalloc (st_size + 2);
- while (st_size > 0)
- {
- i = safe_read (pcf, buf + length, st_size);
- if (i < 0)
- goto nope;
- if (i == 0)
- break;
- length += i;
- st_size -= i;
- }
+ length = safe_read (pcf, buf, st_size);
+ if (length < 0)
+ goto nope;
}
else
abort ();