From: Jonathan Dieter Date: Thu, 26 Jul 2018 13:54:58 +0000 (+0100) Subject: Use _GNU_SOURCE so we can use easy basename() function X-Git-Tag: archive/raspbian/1.1.9+ds1-1+rpi1~1^2~166 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9e857b957545c1a59073badb3d05bd62da4fd076;p=zchunk.git Use _GNU_SOURCE so we can use easy basename() function Signed-off-by: Jonathan Dieter --- diff --git a/src/unzck.c b/src/unzck.c index ee71f5e..efafb53 100644 --- a/src/unzck.c +++ b/src/unzck.c @@ -24,6 +24,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include #include #include @@ -111,9 +113,9 @@ int main (int argc, char *argv[]) { perror(""); exit(1); } - - char *out_name = malloc(strlen(arguments.args[0]) - 3); - snprintf(out_name, strlen(arguments.args[0]) - 3, "%s", arguments.args[0]); + char *base_name = basename(arguments.args[0]); + char *out_name = malloc(strlen(base_name) - 3); + snprintf(out_name, strlen(base_name) - 3, "%s", base_name); int dst_fd = STDOUT_FILENO; if(!arguments.stdout) { diff --git a/src/zck.c b/src/zck.c index cf48ab9..92a0e2a 100644 --- a/src/zck.c +++ b/src/zck.c @@ -24,6 +24,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include #include #include @@ -118,10 +120,9 @@ int main (int argc, char *argv[]) { zck_set_log_level(arguments.log_level); - char *out_name; - out_name = malloc(strlen(arguments.args[0]) + 5); - snprintf(out_name, strlen(arguments.args[0]) + 5, "%s.zck", - arguments.args[0]); + char *base_name = basename(arguments.args[0]); + char *out_name = malloc(strlen(base_name) + 5); + snprintf(out_name, strlen(base_name) + 5, "%s.zck", base_name); /* Set dictionary if available */ char *dict = NULL; diff --git a/src/zck_dl.c b/src/zck_dl.c index d2bc20f..93bdc5a 100644 --- a/src/zck_dl.c +++ b/src/zck_dl.c @@ -24,6 +24,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include #include #include @@ -32,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -300,13 +301,10 @@ int main (int argc, char *argv[]) { exit(10); } - char *outname_full = calloc(1, strlen(arguments.args[0])+1); - memcpy(outname_full, arguments.args[0], strlen(arguments.args[0])); - char *outname = basename(outname_full); + char *outname = basename(arguments.args[0]); int dst_fd = open(outname, O_RDWR | O_CREAT, 0644); if(dst_fd < 0) { printf("Unable to open %s: %s\n", outname, strerror(errno)); - free(outname_full); exit(10); } zckCtx *zck_tgt = zck_create(); @@ -447,7 +445,6 @@ int main (int argc, char *argv[]) { break; } out: - free(outname_full); zck_dl_free(&dl); zck_free(&zck_tgt); zck_free(&zck_src);