Add Yavor's lfs patch

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38010 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2014-07-25 10:38:20 +00:00
parent f13bdb2ad2
commit c5164239ef
6 changed files with 41 additions and 23 deletions

View file

@ -1,3 +1,15 @@
2014-07-13 Yavor Doganov <yavor@gnu.org>
Add large file support (LFS) for NSData.
* configure.ac: Call AC_FUNC_FSEEKO/AC_SYS_LARGEFILE.
* Source/NSData.m (readContentsOfFile): Use fseeko/ftello and
off_t as appropriate.
(-initWithContentsOfFile:): Define fileLength of type off_t.
* Source/GSFileHandle.m:
* Source/win32/GSFileHandle.m:
* Source/NSFileManager.m: Remove _FILE_OFFSET_BITS define (now
defined globally in config.h).
2014-07-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRunLoop.m: ([-runMode:beforeDate:]) check performers as

View file

@ -22,8 +22,6 @@
Boston, MA 02111 USA.
*/
#define _FILE_OFFSET_BITS 64
#import "common.h"
#define EXPOSE_NSFileHandle_IVARS 1
#define EXPOSE_GSFileHandle_IVARS 1

View file

@ -140,7 +140,7 @@ static SEL appendSel;
static IMP appendImp;
static BOOL
readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
{
#if defined(__MINGW__)
const unichar *thePath = 0;
@ -150,7 +150,7 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
FILE *theFile = 0;
void *tmp = 0;
int c;
long fileLength;
off_t fileLength;
#if defined(__MINGW__)
thePath = (const unichar*)[path fileSystemRepresentation];
@ -175,14 +175,10 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
goto failure;
}
// FIXME: since fseek returns a long, this code will fail on files
// larger than ~2GB on 32-bit systems. Probably this entire function should
// be removed and NSFileHandle used instead. -Eric
/*
* Seek to the end of the file.
*/
c = fseek(theFile, 0L, SEEK_END);
c = fseeko(theFile, 0, SEEK_END);
if (c != 0)
{
NSWarnFLog(@"Seek to end of file (%@) failed - %@", path,
@ -192,10 +188,10 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
/*
* Determine the length of the file (having seeked to the end of the
* file) by calling ftell().
* file) by calling ftello().
*/
fileLength = ftell(theFile);
if (fileLength == -1)
fileLength = ftello(theFile);
if (fileLength == (off_t) -1)
{
NSWarnFLog(@"Ftell on %@ failed - %@", path, [NSError _last]);
goto failure;
@ -205,7 +201,7 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
* Rewind the file pointer to the beginning, preparing to read in
* the file.
*/
c = fseek(theFile, 0L, SEEK_SET);
c = fseeko(theFile, 0, SEEK_SET);
if (c != 0)
{
NSWarnFLog(@"Fseek to start of file (%@) failed - %@", path,
@ -246,8 +242,8 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
#endif
if (tmp == 0)
{
NSLog(@"Malloc failed for file (%@) of length %ld - %@", path,
fileLength + c, [NSError _last]);
NSLog(@"Malloc failed for file (%@) of length %jd - %@", path,
(intmax_t)fileLength + c, [NSError _last]);
goto failure;
}
memcpy(tmp + fileLength, buf, c);
@ -256,7 +252,7 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
}
else
{
long offset = 0;
off_t offset = 0;
#if GS_WITH_GC
tmp = NSAllocateCollectable(fileLength, 0);
@ -265,8 +261,8 @@ readContentsOfFile(NSString* path, void** buf, long* len, NSZone* zone)
#endif
if (tmp == 0)
{
NSLog(@"Malloc failed for file (%@) of length %ld - %@", path,
fileLength, [NSError _last]);
NSLog(@"Malloc failed for file (%@) of length %jd - %@", path,
(intmax_t)fileLength, [NSError _last]);
goto failure;
}
@ -632,7 +628,7 @@ failure:
- (id) initWithContentsOfFile: (NSString*)path
{
void *fileBytes;
long fileLength;
off_t fileLength;
#if GS_WITH_GC
if (readContentsOfFile(path, &fileBytes, &fileLength, 0) == NO)
@ -647,7 +643,7 @@ failure:
}
#endif
self = [self initWithBytesNoCopy: fileBytes
length: fileLength
length: (NSUInteger)fileLength
freeWhenDone: YES];
return self;
}

View file

@ -37,7 +37,6 @@
$Date$ $Revision$
*/
#define _FILE_OFFSET_BITS 64
/* The following define is needed for Solaris get(pw/gr)(nam/uid)_r declartions
which default to pre POSIX declaration. */
#define _POSIX_PTHREAD_SEMANTICS

View file

@ -22,8 +22,6 @@
Boston, MA 02111 USA.
*/
#define _FILE_OFFSET_BITS 64
#include "common.h"
#import "Foundation/NSObject.h"

View file

@ -1067,6 +1067,21 @@ if test "$CC" != "$MAKECC"; then
exit 1
fi
# Large file support needed by NSData/NSFileHandle.
# These macros must be called after AC_USE_SYSTEM_EXTENSIONS because
# the `fseeko' declaration may be hidden by default on some systems.
AC_FUNC_FSEEKO
AH_BOTTOM([
/* Define `fseeko' to `fseek' if the former is missing.
Likewise for `ftello'. */
#if !HAVE_FSEEKO
# define fseeko fseek
# define ftello ftell
#endif
])
AC_SYS_LARGEFILE
AC_TYPE_OFF_T
#--------------------------------------------------------------------
# Check wether the compiler supports UTF-8 constant strings
#--------------------------------------------------------------------