Changeset 247 for cpp/common/stl-util.cpp
- Timestamp:
- 11/07/14 17:51:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/stl-util.cpp
r246 r247 10 10 #include "framsg.h" 11 11 #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 12 18 13 19 string ssprintf_va(const char* format, va_list ap) … … 16 22 long size = 256; 17 23 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) 18 26 19 27 //almost like SString::sprintf, but there is no common code to share because SString can use its directWrite to avoid double allocating/copying 20 28 #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); 22 32 #endif 23 33 … … 26 36 buf = (char*)malloc(size); 27 37 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); 29 41 if (n > -1 && n < size) 30 42 { … … 54 66 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file) 55 67 { 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 { 56 85 MFILE *f = mfopen(filename, FOPEN_READ_BINARY); 57 bool ok = f != NULL;58 86 if (f) 59 87 { 60 mfseek(f, 0, SEEK_END); 61 long size = mftell(f); 62 mfseek(f, 0, SEEK_SET); 88 int size=getFileSize(f); 63 89 data.resize(size); 64 90 int przeczytane = mfread(&data[0], size, 1, f); 65 91 mfclose(f); 66 ok &= przeczytane == 1; 92 ok = przeczytane == 1; 93 } 67 94 } 68 95 if (warn_on_missing_file && !ok)
Note: See TracChangeset
for help on using the changeset viewer.