Ignore:
Timestamp:
11/07/14 17:51:01 (9 years ago)
Author:
Maciej Komosinski
Message:

Sources support both 32-bit and 64-bit, and more compilers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/stl-util.cpp

    r246 r247  
    1010#include "framsg.h"
    1111#include <assert.h>
     12#ifdef USE_VIRTFILE
     13 #include <frams/virtfile/virtfile.h>
     14#endif
     15#ifdef __BORLANDC__
     16 #define va_copy(to,from) to=from //borland does not have va_copy() at all; va_list is just a pointer in borland
     17#endif
    1218
    1319string ssprintf_va(const char* format, va_list ap)
     
    1622        long size = 256;
    1723        char* buf;
     24        va_list ap_copy; // "va_list ap" can only by used once by printf-type functions as they advance the current argument pointer (crashed on linux x86_64)
     25        // (does not apply to SString::sprintf, it does not have the va_list variant)
    1826
    1927        //almost like SString::sprintf, but there is no common code to share because SString can use its directWrite to avoid double allocating/copying
    2028#ifdef USE_VSCPRINTF
    21         size = _vscprintf(format, ap) + 1; //+1 for terminating null character
     29        va_copy(ap_copy,ap);
     30        size = _vscprintf(format, ap_copy) + 1; //+1 for terminating null character
     31        va_end(ap_copy);
    2232#endif
    2333
     
    2636                buf = (char*)malloc(size);
    2737                assert(buf != NULL);
    28                 int n = vsnprintf(buf, size, format, ap);
     38                va_copy(ap_copy,ap);
     39                int n = vsnprintf(buf, size, format, ap_copy);
     40                va_end(ap_copy);
    2941                if (n > -1 && n < size)
    3042                {
     
    5466bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file)
    5567{
     68    bool ok=false;
     69#ifdef USE_VIRTFILE
     70        if (!isAbsolutePath(filename))
     71                {
     72                VirtFILE *f=Vfopen(filename,FOPEN_READ_BINARY);
     73                if (f)
     74                        {
     75                        int size=f->getSize();
     76                        data.resize(size);
     77                        int przeczytane = f->Vread(&data[0], size, 1);
     78                        ok = przeczytane == 1;
     79                        delete f;
     80                        }
     81                }
     82        else
     83#endif
     84        {
    5685        MFILE *f = mfopen(filename, FOPEN_READ_BINARY);
    57         bool ok = f != NULL;
    5886        if (f)
    5987        {
    60                 mfseek(f, 0, SEEK_END);
    61                 long size = mftell(f);
    62                 mfseek(f, 0, SEEK_SET);
     88                int size=getFileSize(f);
    6389                data.resize(size);
    6490                int przeczytane = mfread(&data[0], size, 1, f);
    6591                mfclose(f);
    66                 ok &= przeczytane == 1;
     92                ok = przeczytane == 1;
     93        }
    6794        }
    6895        if (warn_on_missing_file && !ok)
Note: See TracChangeset for help on using the changeset viewer.