Mercurial > pt1.oyama
diff recpt1/recpt1.c @ 61:f1553492e8bb
ensure path of destination file exists. imported Jonathan Leffler's mkpath.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 09 Oct 2009 11:04:36 +0900 |
parents | aeb885ed4e7e |
children | c6a5c844c7fd |
line wrap: on
line diff
--- a/recpt1/recpt1.c Sat Oct 03 13:25:13 2009 +0900 +++ b/recpt1/recpt1.c Fri Oct 09 11:04:36 2009 +0900 @@ -13,6 +13,7 @@ #include <errno.h> #include <sys/time.h> #include <ctype.h> +#include <libgen.h> #include <netdb.h> #include <arpa/inet.h> @@ -24,6 +25,7 @@ #include "recpt1.h" #include "decoder.h" #include "version.h" +#include "mkpath.h" /* maximum write length at once */ #define SIZE_CHANK 1316 @@ -783,6 +785,13 @@ } else { if(!fileless) { + int status; + char *dir = dirname(strdup(argv[optind + 2])); + status = mkpath(dir, 0777); + if(status == -1) + perror("mkpath"); + free(dir); + wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); if(wfd < 0) { fprintf(stderr, "Cannot open output file: %s\n",