12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #ifdef UA_ENABLE_AMALGAMATION
- # include <open62541.h>
- #else
- # include "ua_types.h"
- # include "ua_types_generated_handling.h"
- #endif
- 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;
- }
|