diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-04 16:15:55 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-04 16:15:55 -0400 |
commit | 56367b8a61ba71c3d86bc4e5ff2cd0e688d59d84 (patch) | |
tree | 945f97d50d117951fce943d98f3a8809bcc82c60 /dd.c | |
parent | f3ca5c68f0ffe213527893a70aa441ca8255eee3 (diff) |
Diffstat (limited to 'dd.c')
-rw-r--r-- | dd.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -24,6 +24,7 @@ #define _XOPEN_SOURCE 700 #include <errno.h> +#include <fcntl.h> #include <inttypes.h> #include <locale.h> #include <stdlib.h> @@ -292,14 +293,17 @@ int main(int argc, char *argv[]) return 1; } - FILE *in = opts[IF].isset ? fopen(opts[IF].value.s, "rb") : stdin; - if (in == NULL) { + unsigned char ibuf[opts[IBS].value.i]; + unsigned char obuf[opts[OBS].value.i]; + + int in = opts[IF].isset ? open(opts[IF].value.s, O_RDONLY) : STDIN_FILENO; + if (in == -1) { fprintf(stderr, "dd: %s: %s\n", opts[IF].value.s, strerror(errno)); return 1; } - FILE *out = opts[OF].isset ? fopen(opts[OF].value.s, "wb") : stdout; - if (out == NULL) { + int out = opts[OF].isset ? open(opts[OF].value.s, O_WRONLY) : STDIN_FILENO; + if (out == -1) { fprintf(stderr, "dd: %s: %s\n", opts[OF].value.s, strerror(errno)); return 1; } @@ -311,6 +315,15 @@ int main(int argc, char *argv[]) size_t truncated = 0; /* TODO */ + for (size_t block = 0; opts[COUNT].isset == 0 || block < opts[COUNT].value.i; block++) { + ssize_t nread = read(in, ibuf, sizeof(ibuf)); + if (nread == sizeof(ibuf)) { + wholein++; + } else { + partialin++; + } + + } fprintf(stderr, "%zu+%zu records in\n", wholein, partialin); fprintf(stderr, "%zu+%zu records out\n", wholeout, partialout); |