12345678910111213141516171819202122232425262728293031323334353637 |
- static UA_INLINE UA_ByteString
- loadFile(const char *const path) {
- UA_ByteString fileContents = UA_STRING_NULL
-
- FILE *fp = fopen(path, "rb")
- if(!fp) {
- errno = 0
- return fileContents
- }
-
- fseek(fp, 0, SEEK_END)
- fileContents.length = (size_t)ftell(fp)
- fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte))
- if(fileContents.data) {
- fseek(fp, 0, SEEK_SET)
- size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp)
- if(read != fileContents.length)
- UA_ByteString_deleteMembers(&fileContents)
- } else {
- fileContents.length = 0
- }
- fclose(fp)
- return fileContents
- }
|