| 1080 | } |
| 1081 | |
| 1082 | bool ReadFile(const Path &inPath, void *&outData, U32 &outSize, bool inNullTerminate ) |
| 1083 | { |
| 1084 | FileRef fileR = OpenFile( inPath, File::Read ); |
| 1085 | |
| 1086 | outData = NULL; |
| 1087 | outSize = 0; |
| 1088 | |
| 1089 | // We'll get a NULL file reference if |
| 1090 | // the file failed to open. |
| 1091 | if ( fileR == NULL ) |
| 1092 | return false; |
| 1093 | |
| 1094 | outSize = fileR->getSize(); |
| 1095 | |
| 1096 | // Its not a failure to read an empty |
| 1097 | // file... but we can exit early. |
| 1098 | if ( outSize == 0 ) |
| 1099 | return true; |
| 1100 | |
| 1101 | U32 sizeRead = 0; |
| 1102 | |
| 1103 | if ( inNullTerminate ) |
| 1104 | { |
| 1105 | outData = new char [outSize+1]; |
| 1106 | if( !outData ) |
| 1107 | { |
| 1108 | // out of memory |
| 1109 | return false; |
| 1110 | } |
| 1111 | sizeRead = fileR->read(outData, outSize); |
| 1112 | static_cast<char *>(outData)[outSize] = '\0'; |
| 1113 | } |
| 1114 | else |
| 1115 | { |
| 1116 | outData = new char [outSize]; |
| 1117 | if( !outData ) |
| 1118 | { |
| 1119 | // out of memory |
| 1120 | return false; |
| 1121 | } |
| 1122 | sizeRead = fileR->read(outData, outSize); |
| 1123 | } |
| 1124 | |
| 1125 | if ( sizeRead != outSize ) |
| 1126 | { |
| 1127 | delete static_cast<char *>(outData); |
| 1128 | outData = NULL; |
| 1129 | outSize = 0; |
| 1130 | return false; |
| 1131 | } |
| 1132 | |
| 1133 | return true; |
| 1134 | } |
| 1135 | |
| 1136 | DirectoryRef OpenDirectory(const Path &path) |
| 1137 | { |
no test coverage detected