Ignore:
Timestamp:
Apr 17, 2001, 2:26:28 AM (24 years ago)
Author:
bird
Message:

Second iteration of the kFile* classes and interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/common/kFileFormatBase.cpp

    r5053 r5531  
    1 /* $Id: kFileFormatBase.cpp,v 1.3 2001-02-02 08:45:41 bird Exp $
     1/* $Id: kFileFormatBase.cpp,v 1.4 2001-04-17 00:26:11 bird Exp $
    22 *
    33 * kFileFormatBase - Base class for kFile<format> classes.
     
    2121
    2222#include "kFile.h"
     23#include "kInterfaces.h"
    2324#include "kFileFormatBase.h"
    2425
    25 
    26 
    27 
    28 /**
    29  * Creates a memory buffer for a binary file.
    30  * @returns   Pointer to file memoryblock. NULL on error.
    31  * @param     pszFilename  Pointer to filename string.
    32  * @remark    This function is the one using most of the execution
    33  *            time (DosRead + DosOpen) - about 70% of the execution time!
    34  */
    35 void *kFileFormatBase::readfile(const char *pszFilename)
    36 {
    37     void *pvFile = NULL;
    38     FILE *phFile;
    39 
    40     phFile = fopen(pszFilename, "rb");
    41     if (phFile != NULL)
    42     {
    43         long int cbFile;
    44 
    45         if (ftell(phFile) < 0
    46             ||
    47             fseek(phFile, 0, SEEK_END) != 0
    48             ||
    49             (cbFile = ftell(phFile)) < 0
    50             ||
    51             fseek(phFile, 0, SEEK_SET) != 0
    52             )
    53             cbFile = -1;
    54 
    55         if (cbFile > 0)
    56         {
    57             pvFile = malloc((size_t)cbFile + 1);
    58             if (pvFile != NULL)
    59             {
    60                 memset(pvFile, 0, (size_t)cbFile + 1);
    61                 if (fread(pvFile, 1, (size_t)cbFile, phFile) == 0)
    62                 {   /* failed! */
    63                     free(pvFile);
    64                     pvFile = NULL;
    65                 }
    66             }
    67             else
    68                 fprintf(stderr, "warning/error: failed to open file %s\n", pszFilename);
    69         }
    70         fclose(phFile);
    71     }
    72     return pvFile;
    73 }
    7426
    7527/**
Note: See TracChangeset for help on using the changeset viewer.