diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-10-03 23:15:53 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-10-03 23:15:53 +0000 |
commit | 6c4cc88d5248507a3ce9970e1ed8eca60b60952a (patch) | |
tree | 83b1a1f4ab5846bfed8774f2091c76993dd9e0e5 /src/cache.c | |
parent | 2314f19f1502e713cf9aa54330273820e652e6f6 (diff) |
Alter the semantics of caching
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@152 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/src/cache.c b/src/cache.c index ad47ca2..8c328b3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -35,7 +35,7 @@ ReflectionList *cache_load(const char *filename) { ReflectionList *reflectionlist; size_t cachedreflection_size; int i; - + cachedreflection_size = sizeof(Reflection) - sizeof(Reflection *); reflectionlist = reflectionlist_new(); @@ -73,7 +73,7 @@ ReflectionList *cache_load(const char *filename) { return reflectionlist; } -int cache_save(const char *input_filename, ReflectionList *reflectionlist) { +int cache_save(ReflectionList *reflectionlist, char *cache_filename) { FILE *f; CacheHeader ch; @@ -81,11 +81,7 @@ int cache_save(const char *input_filename, ReflectionList *reflectionlist) { int count; const char top[16] = "DTRCACHE\0\0\0\0\0\0\0\0"; size_t cachedreflection_size; - char *cache_filename; - cache_filename = malloc(strlen(input_filename)+7); - strcpy(cache_filename, input_filename); - strcat(cache_filename, ".cache"); printf("Caching reflections to %s\n", cache_filename); cachedreflection_size = sizeof(Reflection) - sizeof(Reflection *); @@ -98,7 +94,7 @@ int cache_save(const char *input_filename, ReflectionList *reflectionlist) { }; f = fopen(cache_filename, "wb"); - free(cache_filename); + if ( f == NULL ) { printf("Couldn't save reflection cache\n"); return -1; @@ -122,28 +118,3 @@ int cache_save(const char *input_filename, ReflectionList *reflectionlist) { } -unsigned int cache_is_cachefile(const char *filename) { - - FILE *fh; - CacheHeader ch; - size_t nread; - - fh = fopen(filename, "rb"); - if ( !fh ) { - printf("Couldn't open file '%s'\n", filename); - return 0; - } - nread = fread(&ch, sizeof(CacheHeader), 1, fh); - fclose(fh); - - if ( nread != 1 ) { - return 0; - } - - if ( strncmp(ch.top, "DTRCACHE", 8) == 0 ) { - return 1; - } - - return 0; - -} |