diff options
author | Thomas White <taw@physics.org> | 2016-03-24 16:18:18 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2016-03-24 16:18:18 +0100 |
commit | 77a17af9356581afc599e186e83d0b4c2aff48ca (patch) | |
tree | ed2be14c703b9684771f28bb6e149653f17c6845 /libcrystfel/src | |
parent | 4ae2329d5ecc58ab6fc3e2466c798c8fba4e9c32 (diff) |
event_path_placeholder_subst(): Simplify a bit
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/events.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c index 731f39f8..f1eda408 100644 --- a/libcrystfel/src/events.c +++ b/libcrystfel/src/events.c @@ -34,6 +34,7 @@ #include <hdf5.h> #include <string.h> #include <stdlib.h> +#include <assert.h> struct event *initialize_event() @@ -555,23 +556,27 @@ int pop_dim_entry_from_event(struct event *ev) } -char *event_path_placeholder_subst(const char *entry, - const char *data) +char *event_path_placeholder_subst(const char *entry, const char *data) { char *ph_loc; char *full_path; - int len_head, len_tail; + ptrdiff_t len_head; + size_t len_entry, len_data; - full_path = malloc((strlen(data) + strlen(entry)+1)*sizeof(char)); - ph_loc = strstr(data, "%"); - len_head = ph_loc-data; - len_tail = strlen(ph_loc); + len_entry = strlen(entry); + len_data = strlen(data); + full_path = malloc(len_data + len_entry + 1); + if ( full_path == NULL ) return NULL; + + ph_loc = strchr(data, '%'); + len_head = ph_loc - data; + assert(len_head >= 0); strncpy(full_path, data, len_head); - strncpy(full_path+len_head, entry, strlen(entry)); - strncpy(full_path+len_head+strlen(entry), ph_loc+1, len_tail); - strncpy(&full_path[strlen(data) + strlen(entry)],"\0",1); + strcat(full_path, entry); + strcat(full_path, ph_loc+1); + full_path[len_data + len_entry] = '\0'; return full_path; } |