diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2019-07-01 15:08:41 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2019-07-01 15:08:41 +0200 |
commit | 198cb2c9fd72b5f02646c742790f2d69f1444617 (patch) | |
tree | 9a68ac9e1cb9848167bfcfae1cb2eed730ae8cd2 | |
parent | f9becf4962007ed2594e022b85eecd811c5f9566 (diff) | |
download | headstripper-198cb2c9fd72b5f02646c742790f2d69f1444617.tar.gz |
Changed name generation to use base- and dirname
-rw-r--r-- | src/main.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -66,6 +66,8 @@ int strip_png(char *_filename); int strip_tiff(char *_filename); +char* gen_filename(char *_filename); + //String combine char* strcmb(char *_str1, char *_str2); @@ -138,7 +140,7 @@ int strip_jpg(char *_filename) FILE *in; FILE *out; - char *f__outfile = strcmb("strip.", _filename); + char *f__outfile = gen_filename(_filename); in = fopen(_filename, "rb"); out = fopen(f__outfile, "wb"); @@ -237,7 +239,7 @@ int strip_png(char *_filename) FILE *in; FILE *out; - char *f__outfile = strcmb("strip.", _filename); + char *f__outfile = gen_filename(_filename); in = fopen(_filename, "rb"); out = fopen(f__outfile, "wb"); @@ -336,3 +338,22 @@ char* strcmb(char *_str1, char *_str2) return f__return; } + +char* gen_filename(char *_filename) +{ + char *filename1 = strdup(_filename); + char *filename2 = strdup(_filename); + char *bsename = strdup(basename(filename1)); + char *drname = strdup(dirname(filename2)); + int len = strlen(_filename) + 20; + char* ret = malloc ( len ); + + snprintf(ret, len - 1, "%s/strip.%s", drname, bsename); + + free(filename1); + free(filename2); + free(bsename); + free(drname); + + return ret; +} |