From 198cb2c9fd72b5f02646c742790f2d69f1444617 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 1 Jul 2019 15:08:41 +0200 Subject: Changed name generation to use base- and dirname --- src/main.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 080b1e2..aa57200 100644 --- a/src/main.c +++ b/src/main.c @@ -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; +} -- cgit v1.2.3