diff options
author | Ben Brewer <ben.brewer@codethink.co.uk> | 2014-05-30 16:45:53 +0100 |
---|---|---|
committer | Ben Brewer <ben.brewer@codethink.co.uk> | 2014-06-04 12:44:01 +0100 |
commit | 0398b8bca477daf22f549fa3152a04abdc8da947 (patch) | |
tree | b5cd3e1399ba42fd5a07785f8b6c5589638c65d9 /tbdiff-create | |
parent | 56bb60f7e0a4b79ec8da62dccd054b87d7469fb6 (diff) | |
download | tbdiff-0398b8bca477daf22f549fa3152a04abdc8da947.tar.gz |
Use POSIX file functions for tbdiff-create stream
POSIX file functions are more consistent and simple, originally
stdio was used to make the code as portable as possible, however
since it now relies on POSIX functionality anyway there's no need
for the inconsistency.
Diffstat (limited to 'tbdiff-create')
-rw-r--r-- | tbdiff-create/main.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tbdiff-create/main.c b/tbdiff-create/main.c index 79b35e2..c8df2bf 100644 --- a/tbdiff-create/main.c +++ b/tbdiff-create/main.c @@ -18,7 +18,9 @@ #include <stdlib.h> #include <stdio.h> #include <stdint.h> +#include <errno.h> +#include <fcntl.h> #include <unistd.h> #include <tbdiff/tbdiff.h> @@ -62,15 +64,17 @@ main(int argc, return EXIT_FAILURE; } - FILE *fp = fopen(argv[1], "wb"); - if(fp == NULL) { - fprintf(stderr, "ERROR: Unable to open patch for writing.\n"); + int fd = open(argv[1], + O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if(fd < 0) { + fprintf(stderr, "Error(%d): Unable to open patch for writing.\n", errno); return EXIT_FAILURE; } int err; - if((err = tbd_create(fp, tstat[0], tstat[1])) != 0) { - fclose(fp); + if((err = tbd_create(fd, tstat[0], tstat[1])) != 0) { + close(fd); tbd_stat_free(tstat[0]); tbd_stat_free(tstat[1]); @@ -89,7 +93,7 @@ main(int argc, return EXIT_FAILURE; } - fclose(fp); + close(fd); tbd_stat_free(tstat[0]); tbd_stat_free(tstat[1]); |