changeset 1036:1a0a327d8fed

Use 64bit file offsets.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Mar 2015 16:57:50 +0200
parents d2fa4f6d6117
children d674ddc0fc82
files src/dmres.c src/dmres.h tools/packed.c
diffstat 3 files changed, 33 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/dmres.c	Sun Mar 01 16:41:01 2015 +0200
+++ b/src/dmres.c	Sun Mar 01 16:57:50 2015 +0200
@@ -170,9 +170,15 @@
 }
 
 
-static int dm_stdio_fseek(DMResource *f, const off_t pos, const int whence)
+static Sint64 dm_stdio_ftell(DMResource * f)
 {
-    int ret = fseek(f->fh, pos, whence);
+    return DM_FTELL64(f->fh);
+}
+
+
+static int dm_stdio_fseek(DMResource *f, const Sint64 pos, const int whence)
+{
+    int ret = DM_FSEEK64(f->fh, pos, whence);
     f->error = dmGetErrno();
     return ret;
 }
@@ -181,7 +187,7 @@
 static int dm_stdio_freset(DMResource * f)
 {
     if (f->fh != NULL)
-        return dm_stdio_fseek(f, 0L, SEEK_SET);
+        return dm_stdio_fseek(f, 0, SEEK_SET);
     else
         return DMERR_OK;
 }
@@ -196,31 +202,19 @@
         return f->rawSize;
 
     // Get file size
-    savePos = ftello(f->fh);
-    if (fseeko(f->fh, 0L, SEEK_END) != 0)
-    {
-        f->error = dmGetErrno();
+    savePos = dm_stdio_ftell(f);
+    if (dm_stdio_fseek(f, 0, SEEK_END) != 0)
         return -1;
-    }
 
-    fileSize = ftello(f->fh);
-    if (fseeko(f->fh, savePos, SEEK_SET) != 0)
-    {
-        f->error = dmGetErrno();
+    fileSize = dm_stdio_ftell(f);
+    if (dm_stdio_fseek(f, savePos, SEEK_SET) != 0)
         return -1;
-    }
 
     f->rawSize = fileSize;
     return fileSize;
 }
 
 
-static off_t dm_stdio_ftell(DMResource * f)
-{
-    return ftell(f->fh);
-}
-
-
 static BOOL dm_stdio_feof(DMResource * f)
 {
     return feof(f->fh);
@@ -456,7 +450,7 @@
     }
 
     // Seek to entry
-    if (fseek(handle->lib->packFile->file, node->offset, SEEK_SET) == -1)
+    if (DM_FSEEK64(handle->lib->packFile->file, node->offset, SEEK_SET) == -1)
     {
         ret = dmError(DMERR_FSEEK,
             "Could not seek node position in PACK file.\n");
@@ -543,7 +537,7 @@
 }
 
 
-static int dm_mem_fseek(DMResource * f, const off_t offset, const int whence)
+static int dm_mem_fseek(DMResource * f, const Sint64 offset, const int whence)
 {
     off_t newPos;
 
@@ -583,7 +577,7 @@
 }
 
 
-static off_t dm_mem_ftell(DMResource * f)
+static Sint64 dm_mem_ftell(DMResource * f)
 {
     return f->rawOffset;
 }
@@ -892,7 +886,7 @@
     return f->fops->ferror(f);
 }
 
-int dmfseek(DMResource * f, off_t offset, int whence)
+int dmfseek(DMResource * f, Sint64 offset, int whence)
 {
     f->atime = time(NULL);
     return f->fops->fseek(f, offset, whence);
--- a/src/dmres.h	Sun Mar 01 16:41:01 2015 +0200
+++ b/src/dmres.h	Sun Mar 01 16:57:50 2015 +0200
@@ -17,6 +17,14 @@
 extern "C" {
 #endif
 
+#ifdef HAVE_FSEEK64
+#    define DM_FSEEK64 fseek64
+#    define DM_FTELL64 ftell64
+#else
+#    define DM_FSEEK64 fseeko
+#    define DM_FTELL64 ftello
+#endif
+
 
 /* Constants
  */
@@ -113,9 +121,9 @@
 
     int     (*freset)(DMResource *);
     int     (*ferror)(DMResource *);
-    int     (*fseek)(DMResource *, const off_t, const int);
+    int     (*fseek)(DMResource *, const Sint64, const int);
     off_t   (*fsize)(DMResource *);
-    off_t   (*ftell)(DMResource *);
+    Sint64  (*ftell)(DMResource *);
     BOOL    (*feof)(DMResource *);
     int     (*fgetc)(DMResource *);
     int     (*fputc)(int, DMResource *);
@@ -159,9 +167,9 @@
 // Basic resource access functions
 int          dmfreset(DMResource *);
 int          dmferror(DMResource *);
-int          dmfseek(DMResource *, const off_t, const int);
+int          dmfseek(DMResource *, Sint64, const int);
 off_t        dmfsize(DMResource *);
-off_t        dmftell(DMResource *);
+Sint64       dmftell(DMResource *);
 BOOL         dmfeof(DMResource *);
 int          dmfgetc(DMResource *);
 int          dmfputc(int, DMResource *);
--- a/tools/packed.c	Sun Mar 01 16:41:01 2015 +0200
+++ b/tools/packed.c	Sun Mar 01 16:57:50 2015 +0200
@@ -211,7 +211,7 @@
     }
 
     // Write PACK header
-    if (fseek(pack->file, 0L, SEEK_SET) != 0)
+    if (DM_FSEEK64(pack->file, 0, SEEK_SET) != 0)
         return DMERR_FSEEK;
 
     if (!dm_fwrite_str(pack->file, (Uint8 *) & hdr.ident, sizeof(hdr.ident)) ||
@@ -221,7 +221,7 @@
         return DMERR_FWRITE;
 
     // Write the directory
-    if (fseek(pack->file, hdr.dirOffset, SEEK_SET) != 0)
+    if (DM_FSEEK64(pack->file, hdr.dirOffset, SEEK_SET) != 0)
         return DMERR_FSEEK;
 
     node = pack->entries;
@@ -294,7 +294,7 @@
     }
 
     // Seek to the position
-    if (fseek(pack->file, startOffs, SEEK_SET) != 0)
+    if (DM_FSEEK64(pack->file, startOffs, SEEK_SET) != 0)
         return DMERR_INVALID;
 
     // Read file data
@@ -411,7 +411,7 @@
         return DMERR_FOPEN;
 
     // Seek to the position
-    if (fseek(pack->file, entry->offset, SEEK_SET) != 0)
+    if (DM_FSEEK64(pack->file, entry->offset, SEEK_SET) != 0)
         return DMERR_FSEEK;
 
     // Open destination file