Mercurial > pt1
comparison 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 |
comparison
equal
deleted
inserted
replaced
60:181737b0533c | 61:f1553492e8bb |
---|---|
11 #include <getopt.h> | 11 #include <getopt.h> |
12 #include <signal.h> | 12 #include <signal.h> |
13 #include <errno.h> | 13 #include <errno.h> |
14 #include <sys/time.h> | 14 #include <sys/time.h> |
15 #include <ctype.h> | 15 #include <ctype.h> |
16 #include <libgen.h> | |
16 | 17 |
17 #include <netdb.h> | 18 #include <netdb.h> |
18 #include <arpa/inet.h> | 19 #include <arpa/inet.h> |
19 #include <netinet/in.h> | 20 #include <netinet/in.h> |
20 | 21 |
22 #include "pt1_ioctl.h" | 23 #include "pt1_ioctl.h" |
23 | 24 |
24 #include "recpt1.h" | 25 #include "recpt1.h" |
25 #include "decoder.h" | 26 #include "decoder.h" |
26 #include "version.h" | 27 #include "version.h" |
28 #include "mkpath.h" | |
27 | 29 |
28 /* maximum write length at once */ | 30 /* maximum write length at once */ |
29 #define SIZE_CHANK 1316 | 31 #define SIZE_CHANK 1316 |
30 | 32 |
31 /* globals */ | 33 /* globals */ |
781 use_stdout = TRUE; | 783 use_stdout = TRUE; |
782 wfd = 1; /* stdout */ | 784 wfd = 1; /* stdout */ |
783 } | 785 } |
784 else { | 786 else { |
785 if(!fileless) { | 787 if(!fileless) { |
788 int status; | |
789 char *dir = dirname(strdup(argv[optind + 2])); | |
790 status = mkpath(dir, 0777); | |
791 if(status == -1) | |
792 perror("mkpath"); | |
793 free(dir); | |
794 | |
786 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); | 795 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); |
787 if(wfd < 0) { | 796 if(wfd < 0) { |
788 fprintf(stderr, "Cannot open output file: %s\n", | 797 fprintf(stderr, "Cannot open output file: %s\n", |
789 argv[optind + 2]); | 798 argv[optind + 2]); |
790 return 1; | 799 return 1; |