diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-07-08 12:06:47 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-07-08 12:06:47 -0700 |
commit | 462b26c1cc041a8fa26deb62cf12f1f351a5b2f6 (patch) | |
tree | de5a58f8d66d11c13b349448a970f84d57d16cad /src/upb_string.c | |
parent | c7ee14f8ef38a8bc90c0f1db1ad47b2e06612fa3 (diff) |
Directory restructuring.
Diffstat (limited to 'src/upb_string.c')
-rw-r--r-- | src/upb_string.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/upb_string.c b/src/upb_string.c new file mode 100644 index 0000000..733bafe --- /dev/null +++ b/src/upb_string.c @@ -0,0 +1,24 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2009 Joshua Haberman. See LICENSE for details. + */ + +#include "upb_string.h" + +bool upb_strreadfile(const char *filename, struct upb_string *data) { + FILE *f = fopen(filename, "rb"); + if(!f) return false; + if(fseek(f, 0, SEEK_END) != 0) return false; + long size = ftell(f); + if(size < 0) return false; + if(fseek(f, 0, SEEK_SET) != 0) return false; + data->ptr = (char*)malloc(size); + data->byte_len = size; + if(fread(data->ptr, size, 1, f) != 1) { + free(data->ptr); + return false; + } + fclose(f); + return true; +} |