summaryrefslogtreecommitdiff
path: root/upb_string.h
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-05 17:54:49 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-05 17:54:49 -0700
commit7f871401c77bcda18e8f41e457ee55388773d183 (patch)
tree2996509ed66b4056789a09fb7b81c418e7a3af57 /upb_string.h
parent421f276086dfc4d1df7411820f9d56f3ae78472e (diff)
More work on upbc.
Diffstat (limited to 'upb_string.h')
-rw-r--r--upb_string.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/upb_string.h b/upb_string.h
index d91fa69..2520caa 100644
--- a/upb_string.h
+++ b/upb_string.h
@@ -59,6 +59,23 @@ INLINE void upb_strfree(struct upb_string s) {
free(s.ptr);
}
+INLINE 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;
+}
+
#define UPB_STRLIT(strlit) {.ptr=strlit, .byte_len=sizeof(strlit)-1}
#define UPB_STRARG(str) (str).byte_len, (str).ptr
#define UPB_STRFMT "%.*s"
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback