| 921 | } |
| 922 | |
| 923 | bool ReadFile(const Path &inPath, void *&outData, U32 &outSize, bool inNullTerminate ) |
| 924 | { |
| 925 | FileRef fileR = OpenFile( inPath, File::Read ); |
| 926 | |
| 927 | outData = NULL; |
| 928 | outSize = 0; |
| 929 | |
| 930 | // We'll get a NULL file reference if |
| 931 | // the file failed to open. |
| 932 | if ( fileR == NULL ) |
| 933 | return false; |
| 934 | |
| 935 | outSize = fileR->getSize(); |
| 936 | |
| 937 | // Its not a failure to read an empty |
| 938 | // file... but we can exit early. |
| 939 | if ( outSize == 0 ) |
| 940 | return true; |
| 941 | |
| 942 | U32 sizeRead = 0; |
| 943 | |
| 944 | if ( inNullTerminate ) |
| 945 | { |
| 946 | outData = new char [outSize+1]; |
| 947 | if( !outData ) |
| 948 | { |
| 949 | // out of memory |
| 950 | return false; |
| 951 | } |
| 952 | sizeRead = fileR->read(outData, outSize); |
| 953 | static_cast<char *>(outData)[outSize] = '\0'; |
| 954 | } |
| 955 | else |
| 956 | { |
| 957 | outData = new char [outSize]; |
| 958 | if( !outData ) |
| 959 | { |
| 960 | // out of memory |
| 961 | return false; |
| 962 | } |
| 963 | sizeRead = fileR->read(outData, outSize); |
| 964 | } |
| 965 | |
| 966 | if ( sizeRead != outSize ) |
| 967 | { |
| 968 | delete static_cast<char *>(outData); |
| 969 | outData = NULL; |
| 970 | outSize = 0; |
| 971 | return false; |
| 972 | } |
| 973 | |
| 974 | return true; |
| 975 | } |
| 976 | |
| 977 | DirectoryRef OpenDirectory(const Path &path) |
| 978 | { |
no test coverage detected