diff lib64gfx.c @ 567:b2b461829c61

Move utility function dmReadDataFile() to dmfile module instead.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 04 Jan 2013 16:48:15 +0200
parents cf39f51d4e74
children 5d158c4321bb
line wrap: on
line diff
--- a/lib64gfx.c	Sun Dec 30 13:18:08 2012 +0200
+++ b/lib64gfx.c	Fri Jan 04 16:48:15 2013 +0200
@@ -821,74 +821,6 @@
 }
 
 
-int dmReadDataFile(FILE *inFile, const char *filename, Uint8 **pbuf, size_t *pbufSize)
-{
-    FILE *f;
-    int res = DMERR_OK;
-    Uint8 *dataBuf = NULL;
-    size_t readSize, dataSize, dataRead, dataPos;
-    
-    if (inFile != NULL)
-        f = inFile;
-    else
-    if (filename != NULL)
-    {
-        if ((f = fopen(filename, "rb")) == NULL)
-        {
-            dmError("Could not open '%s' for reading.\n", filename);
-            return DMERR_FOPEN;
-        }
-    }
-    else
-    {
-        dmError("NULL filename and stream pointers.\n");
-        return DMERR_NULLPTR;
-    }
-
-    // Allocate initial data buffer
-    readSize = dataSize = BUF_SIZE_INITIAL;
-    if ((dataBuf = dmMalloc(dataSize)) == NULL)
-    {
-        dmError("Error allocating memory for data, %d bytes.\n", dataSize);
-        res = DMERR_MALLOC;
-        goto error;
-    }
-
-    dataPos = 0;
-    dataRead = 0;
-
-    while (!feof(f) && !ferror(f))
-    {
-        size_t read = fread(dataBuf + dataPos, 1, readSize, f);
-        dataPos += read;
-        dataRead += read;
-
-        if (dataRead >= dataSize)
-        {
-            readSize = BUF_SIZE_GROW;
-            dataSize += BUF_SIZE_GROW;
-            if ((dataBuf = dmRealloc(dataBuf, dataSize)) == NULL)
-            {
-                dmError("Error reallocating memory for data, %d bytes.\n", dataSize);
-                res = DMERR_MALLOC;
-                goto error;
-            }
-        }
-        else
-            break;
-    }
-
-    *pbufSize = dataRead;
-    *pbuf = dataBuf;
-
-error:
-    if (f != inFile)
-        fclose(f);
-    
-    return res;
-}
-
-
 int dmC64DecodeBMP(DMC64Image *img, const Uint8 *buf, const size_t len,
     const size_t probeOffs, const size_t loadOffs,
     const DMC64ImageFormat **fmt, const DMC64ImageFormat *forced)