From a2465bb8393f216ecb7a72604180cd9ec21c6fdb Mon Sep 17 00:00:00 2001 From: jonas Date: Thu, 25 Apr 2019 10:12:40 +0200 Subject: Changed filename string generation --- src/main.c | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 1f33825..75fc2de 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,8 @@ int strip_png(char *_filename); int strip_tiff(char *_filename); +char* strcmb(char *_str1, char *_str2); + int main(int argc, char* argv[]) { FILE *image; @@ -111,11 +113,7 @@ int strip_jpg(char *_filename) FILE *in; FILE *out; - int f__outfile_len = strlen(_filename); - char *f__outfile = malloc(f__outfile_len + 8); - - strncpy( f__outfile, "strip.", 6); - strcpy(&f__outfile[6], _filename); + char *f__outfile = strcmb("strip.", _filename); in = fopen(_filename, "r"); out = fopen(f__outfile, "w"); @@ -183,15 +181,12 @@ int strip_png(char *_filename) FILE *in; FILE *out; - int f__outfile_len = strlen(_filename); - char *f__outfile = malloc(f__outfile_len + 8); - - strncpy( f__outfile, "strip.", 6); - strcpy(&f__outfile[6], _filename); + char *f__outfile = strcmb("strip.", _filename); in = fopen(_filename, "r"); out = fopen(f__outfile, "w"); + if(!in) return 1; if(!out) { @@ -271,30 +266,17 @@ int strip_png(char *_filename) int strip_tiff(char *_filename) { - FILE *in; - FILE *out; - - int f__outfile_len = strlen(_filename); - char *f__outfile = malloc(f__outfile_len + 8); - - strncpy( f__outfile, "strip.", 6); - strcpy(&f__outfile[6], _filename); - - in = fopen(_filename, "r"); - out = fopen(f__outfile, "w"); + printf("TIFF Unimplemented.\n"); + return 1; - if(!in) - return 1; - if(!out) { - printf("Unable to open for writing %s: %i\n", f__outfile, errno); - return 1; - } +} - printf("Unimplemented\n"); +char* strcmb(char *_str1, char *_str2) +{ + char *f__return = malloc(strlen(_str1) + strlen(_str2) + 1); - fclose(in); - fclose(out); - free(f__outfile); + strcpy( f__return, _str1); + strcpy(&f__return[ strlen(_str1) ], _str2); - return 1; + return f__return; } -- cgit v1.2.3