cpu/cpu-1.4.3-read.patch

52 lines
1.3 KiB
Diff

diff -Nur -x '*.orig' -x '*.rej' cpu-1.4.3/src/util/parser.c mezzanine_patched_cpu-1.4.3/src/util/parser.c
--- cpu-1.4.3/src/util/parser.c 2003-10-22 17:17:15.000000000 -0400
+++ mezzanine_patched_cpu-1.4.3/src/util/parser.c 2007-07-24 15:17:47.000000000 -0400
@@ -57,6 +57,8 @@
{
int fd = 0;
ssize_t retval = 0;
+ ssize_t nread;
+ ssize_t bufsize;
void * temp;
struct stat buf;
@@ -75,14 +77,31 @@
return NULL;
}
- temp = malloc(buf.st_size);
- if ( temp == NULL )
- return NULL;
- bzero(temp, buf.st_size);
-
- retval = read(fd, temp, buf.st_size);
+ for (nread = 0, temp = NULL, bufsize = 4096; ;bufsize *= 2)
+ {
+ void *temp2;
+ ssize_t rbufsize;
+ temp2 = malloc(bufsize);
+ if ( temp2 == NULL )
+ {
+ perror(filename);
+ return NULL;
+ }
+ bzero(temp2, bufsize);
+ if (temp)
+ {
+ memcpy(temp2, temp, nread);
+ free(temp);
+ }
+ temp = temp2;
+ rbufsize = bufsize - nread;
+ retval = read(fd, temp+nread, rbufsize);
+ nread += retval;
+ if (retval < rbufsize)
+ break;
+ }
close(fd);
- if ( retval != buf.st_size )
+ if (buf.st_size && nread != buf.st_size )
printf("Hmm, didn't read all wanted data. Continuing\n");
if ( retval < 0 )
return NULL;