Ignore:
Timestamp:
12/03/14 18:52:05 (9 years ago)
Author:
Maciej Komosinski
Message:
  • added strmove(): strcpy() for overlapping strings
  • ExtObject? operator== can handle NULL arguments
  • source formatting and improved genetic operator messages
File:
1 edited

Legend:

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

    r247 r257  
    1111#include <assert.h>
    1212#ifdef USE_VIRTFILE
    13  #include <frams/virtfile/virtfile.h>
     13#include <frams/virtfile/virtfile.h>
    1414#endif
    1515#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
     16#define va_copy(to,from) to=from //borland does not have va_copy() at all; va_list is just a pointer in borland
    1717#endif
    1818
     
    2727        //almost like SString::sprintf, but there is no common code to share because SString can use its directWrite to avoid double allocating/copying
    2828#ifdef USE_VSCPRINTF
    29         va_copy(ap_copy,ap);
     29        va_copy(ap_copy, ap);
    3030        size = _vscprintf(format, ap_copy) + 1; //+1 for terminating null character
    3131        va_end(ap_copy);
     
    3636                buf = (char*)malloc(size);
    3737                assert(buf != NULL);
    38                 va_copy(ap_copy,ap);
     38                va_copy(ap_copy, ap);
    3939                int n = vsnprintf(buf, size, format, ap_copy);
    4040                va_end(ap_copy);
     
    5555}
    5656
     57char* strmove(char *a, char *b) //strcpy that works well for overlapping strings ("Source and destination overlap")
     58{
     59        if (a == NULL || b == NULL)
     60                return NULL;
     61        memmove(a, b, strlen(b) + 1);
     62        return a;
     63}
     64
    5765string ssprintf(const char* format, ...)
    5866{
     
    6674bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file)
    6775{
    68     bool ok=false;
     76        bool ok = false;
    6977#ifdef USE_VIRTFILE
    7078        if (!isAbsolutePath(filename))
    71                 {
     79        {
    7280                VirtFILE *f=Vfopen(filename,FOPEN_READ_BINARY);
    7381                if (f)
    74                         {
     82                {
    7583                        int size=f->getSize();
    7684                        data.resize(size);
     
    7886                        ok = przeczytane == 1;
    7987                        delete f;
    80                         }
    8188                }
     89        }
    8290        else
    8391#endif
    8492        {
    85         MFILE *f = mfopen(filename, FOPEN_READ_BINARY);
    86         if (f)
    87         {
    88                 int size=getFileSize(f);
    89                 data.resize(size);
    90                 int przeczytane = mfread(&data[0], size, 1, f);
    91                 mfclose(f);
    92                 ok = przeczytane == 1;
    93         }
     93                MFILE *f = mfopen(filename, FOPEN_READ_BINARY);
     94                if (f)
     95                {
     96                        int size = getFileSize(f);
     97                        data.resize(size);
     98                        int przeczytane = mfread(&data[0], size, 1, f);
     99                        mfclose(f);
     100                        ok = przeczytane == 1;
     101                }
    94102        }
    95103        if (warn_on_missing_file && !ok)
Note: See TracChangeset for help on using the changeset viewer.