diff options
-rw-r--r-- | libcrystfel/src/detector.c | 39 | ||||
-rw-r--r-- | libcrystfel/src/utils.c | 39 | ||||
-rw-r--r-- | libcrystfel/src/utils.h | 1 |
3 files changed, 40 insertions, 39 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c index 629e13f0..5653f0f2 100644 --- a/libcrystfel/src/detector.c +++ b/libcrystfel/src/detector.c @@ -1739,45 +1739,6 @@ struct detector *get_detector_geometry_from_string(const char *string_in, } -char *load_entire_file(const char *filename) -{ - struct stat statbuf; - int r; - char *contents; - FILE *fh; - - r = stat(filename, &statbuf); - if ( r != 0 ) { - ERROR("File '%s' not found\n", filename); - return NULL; - } - - contents = malloc(statbuf.st_size+1); - if ( contents == NULL ) { - ERROR("Failed to allocate memory for file\n"); - return NULL; - } - - fh = fopen(filename, "r"); - if ( fh == NULL ) { - ERROR("Failed to open file '%s'\n", filename); - free(contents); - return NULL; - } - - if ( fread(contents, 1, statbuf.st_size, fh) != statbuf.st_size ) { - ERROR("Failed to read file '%s'\n", filename); - free(contents); - return NULL; - } - contents[statbuf.st_size] = '\0'; - - fclose(fh); - - return contents; -} - - struct detector *get_detector_geometry_2(const char *filename, struct beam_params *beam, char **hdf5_peak_path) diff --git a/libcrystfel/src/utils.c b/libcrystfel/src/utils.c index 4873b050..de1dc2f4 100644 --- a/libcrystfel/src/utils.c +++ b/libcrystfel/src/utils.c @@ -674,3 +674,42 @@ struct rvec quat_rot(struct rvec q, struct quaternion z) return res; } + + +char *load_entire_file(const char *filename) +{ + struct stat statbuf; + int r; + char *contents; + FILE *fh; + + r = stat(filename, &statbuf); + if ( r != 0 ) { + ERROR("File '%s' not found\n", filename); + return NULL; + } + + contents = malloc(statbuf.st_size+1); + if ( contents == NULL ) { + ERROR("Failed to allocate memory for file\n"); + return NULL; + } + + fh = fopen(filename, "r"); + if ( fh == NULL ) { + ERROR("Failed to open file '%s'\n", filename); + free(contents); + return NULL; + } + + if ( fread(contents, 1, statbuf.st_size, fh) != statbuf.st_size ) { + ERROR("Failed to read file '%s'\n", filename); + free(contents); + return NULL; + } + contents[statbuf.st_size] = '\0'; + + fclose(fh); + + return contents; +} diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h index beb05ee0..b2694f2a 100644 --- a/libcrystfel/src/utils.h +++ b/libcrystfel/src/utils.h @@ -223,6 +223,7 @@ extern pthread_mutex_t stderr_lock; extern char *check_prefix(char *prefix); extern char *safe_basename(const char *in); extern void strip_extension(char *bfn); +extern char *load_entire_file(const char *filename); /* ------------------------------ Useful stuff ------------------------------ */ |