1234567891011121314151617181920212223242526272829303132333435363738 |
- 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_clear(&fileContents)
- } else {
- fileContents.length = 0
- }
- fclose(fp)
- return fileContents
- }
|