- Timestamp:
- 10/01/21 22:38:58 (3 years ago)
- Location:
- cpp/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/util-file.cpp
r1124 r1153 10 10 #include <common/virtfile/virtfile.h> 11 11 #endif 12 #ifdef DEBUGGING_READWRITECOMPLETEFILE 13 #include <common/dirs.h> 14 #endif 12 15 13 16 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file) … … 15 18 bool ok = false; 16 19 #ifdef USE_VIRTFILE 20 #ifdef DEBUGGING_READWRITECOMPLETEFILE 21 logPrintf("","readCompleteFile",LOG_DEBUG,"virtfile: '%s'",filename); 22 #endif 17 23 // if (!isAbsolutePath(filename)) 18 24 { … … 30 36 #endif 31 37 { 38 #ifdef DEBUGGING_READWRITECOMPLETEFILE 39 if (isAbsolutePath(filename)) 40 logPrintf("","readCompleteFile",LOG_DEBUG,"mfopen absolute path: '%s'",filename); 41 else 42 logPrintf("","readCompleteFile",LOG_DEBUG,"mfopen: '%s' in current dir: '%s'",filename,getCurrentDirectory().c_str()); 43 #endif 32 44 MFILE *f = mfopen(filename, FOPEN_READ_BINARY); 45 #ifdef DEBUGGING_READWRITECOMPLETEFILE 46 logPrintf("", "readCompleteFile", LOG_DEBUG, "mfopen status: %s", f?"ok":"fail"); 47 #endif 33 48 if (f) 34 49 { … … 41 56 } 42 57 if (warn_on_missing_file && !ok) 43 logPrintf("stl-util", "readCompleteFile", LOG_WARN, "Couldn't open file '%s'", filename); 58 logPrintf("", "readCompleteFile", LOG_WARN, "Couldn't open file '%s'", filename); 59 #ifdef DEBUGGING_READWRITECOMPLETEFILE 60 logPrintf("", "readCompleteFile", LOG_DEBUG, "bytes:%d status: %s", data.size(), ok?"ok":"fail"); 61 #endif 44 62 return ok; 45 63 } … … 59 77 { 60 78 #ifdef USE_VIRTFILE 79 #ifdef DEBUGGING_READWRITECOMPLETEFILE 80 logPrintf("","writeCompleteFile",LOG_DEBUG,"virtfile: '%s'",filename); 81 #endif 61 82 VirtFILE *f = Vfopen(filename, FOPEN_WRITE_BINARY); 62 83 bool ok = f != NULL; … … 68 89 } 69 90 #else 91 #ifdef DEBUGGING_READWRITECOMPLETEFILE 92 if (isAbsolutePath(filename)) 93 logPrintf("","writeCompleteFile",LOG_DEBUG,"mfopen absolute path: '%s'",filename); 94 else 95 logPrintf("","writeCompleteFile",LOG_DEBUG,"mfopen: '%s' in current dir: '%s'",filename,getCurrentDirectory().c_str()); 96 #endif 70 97 MFILE *f = mfopen(filename, FOPEN_WRITE_BINARY); 71 98 bool ok = f != NULL; 99 #ifdef DEBUGGING_READWRITECOMPLETEFILE 100 logPrintf("", "writeCompleteFile", LOG_DEBUG, "mfopen status: %s", ok?"ok":"fail"); 101 #endif 72 102 if (f) 73 103 { … … 78 108 #endif 79 109 if (warn_on_fail && !ok) 80 logPrintf("stl-util", "writeCompleteFile", LOG_WARN, "Couldn't write file '%s'", filename); 110 logPrintf("", "writeCompleteFile", LOG_WARN, "Couldn't write file '%s'", filename); 111 #ifdef DEBUGGING_READWRITECOMPLETEFILE 112 logPrintf("", "writeCompleteFile", LOG_DEBUG, "status: %s", ok?"ok":"fail"); 113 #endif 81 114 return ok; 82 115 } … … 89 122 90 123 // Just like fgets(), but string length is unlimited and does not store trailing \r \n 124 #ifdef USE_VIRTFILE 91 125 string readUntilEOL(VirtFILE *f) 126 #else 127 string readUntilEOL(FILE *f) 128 #endif 92 129 { 93 130 char buf[100]; … … 95 132 std::string ret; 96 133 bool endofline; 97 while ((line = f->Vgets(buf, sizeof(buf)))) 134 while ((line = 135 #ifdef USE_VIRTFILE 136 f->Vgets(buf, sizeof(buf)) 137 #else 138 fgets(buf, sizeof(buf), f) 139 #endif 140 )) 98 141 { 99 142 char* end = line + strlen(line); -
cpp/common/util-file.h
r1124 r1153 7 7 8 8 #include "nonstd_stl.h" 9 #ifdef USE_VIRTFILE 9 10 #include "virtfile/virtfile.h" 11 #else 12 #include <stdio.h> 13 #endif 10 14 11 15 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file = true); … … 13 17 bool writeCompleteFile(const char* filename, const std::string& text, bool warn_on_fail = true); 14 18 bool writeCompleteFile(const char* filename, vector<char>& data, bool warn_on_fail = true); 19 #ifdef USE_VIRTFILE 15 20 string readUntilEOL(VirtFILE *f); 21 #else 22 string readUntilEOL(FILE *f); 23 #endif 16 24 17 25 #endif
Note: See TracChangeset
for help on using the changeset viewer.