attempt fix for bug 29920

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30471 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-05-29 08:05:03 +00:00
parent d6ef02c19f
commit 0fa4308c1a
2 changed files with 28 additions and 8 deletions

View file

@ -1,3 +1,7 @@
2010-05-29 Richard Frith-Macdonald <rfm@gnu.org>
* NSData.m: Attempted fix for bug #29920
2010-05-29 Richard Frith-Macdonald <rfm@gnu.org> 2010-05-29 Richard Frith-Macdonald <rfm@gnu.org>
* NSConcreteHashTable.m: * NSConcreteHashTable.m:

View file

@ -169,7 +169,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
NSDebugFLog(@"Open (%@) attempt failed - %@", path, [NSError _last]); NSDebugFLog(@"Open (%@) attempt failed - %@", path, [NSError _last]);
goto failure; goto failure;
} }
/* /*
* Seek to the end of the file. * Seek to the end of the file.
*/ */
@ -203,7 +203,8 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
[NSError _last]); [NSError _last]);
goto failure; goto failure;
} }
clearerr(theFile);
if (fileLength == 0) if (fileLength == 0)
{ {
unsigned char buf[BUFSIZ]; unsigned char buf[BUFSIZ];
@ -246,6 +247,8 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
} }
else else
{ {
long offset = 0;
#if GS_WITH_GC #if GS_WITH_GC
tmp = NSAllocateCollectable(fileLength, 0); tmp = NSAllocateCollectable(fileLength, 0);
#else #else
@ -258,15 +261,28 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
goto failure; goto failure;
} }
c = fread(tmp, 1, fileLength, theFile); while (offset < fileLength
if (c != (int)fileLength) && (c = fread(tmp + offset, 1, fileLength - offset, theFile)) != 0)
{ {
NSWarnFLog(@"read of file (%@) contents failed - %@", path, offset += c;
[NSError _last]); }
goto failure; if (offset < fileLength)
{
fileLength = offset;
#if GS_WITH_GC
tmp = NSReallocateCollectable(tmp, fileLength, 0);
#else
tmp = NSZoneRealloc(zone, tmp, fileLength);
#endif
} }
} }
if (ferror(theFile))
{
NSWarnFLog(@"read of file (%@) contents failed - %@", path,
[NSError _last]);
goto failure;
}
*buf = tmp; *buf = tmp;
*len = fileLength; *len = fileLength;
fclose(theFile); fclose(theFile);