diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-08 05:16:25 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-08 05:16:25 +0100 |
| commit | 3273cb68f82adb0347e3ad1810fc891ad3dbe217 (patch) | |
| tree | 03365172b672dad6a42337561a8d13660082e0be /src/vu-repeat.c | |
| parent | Add vu-set-alpha (diff) | |
| download | blind-3273cb68f82adb0347e3ad1810fc891ad3dbe217.tar.gz blind-3273cb68f82adb0347e3ad1810fc891ad3dbe217.tar.bz2 blind-3273cb68f82adb0347e3ad1810fc891ad3dbe217.tar.xz | |
Add vu-repeat
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/vu-repeat.c')
| -rw-r--r-- | src/vu-repeat.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/vu-repeat.c b/src/vu-repeat.c new file mode 100644 index 0000000..69ac8ce --- /dev/null +++ b/src/vu-repeat.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "arg.h" +#include "util.h" + +#include <fcntl.h> +#include <stdint.h> +#include <unistd.h> + +static void +usage(void) +{ + eprintf("usage: %s count file\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + struct stat st; + size_t count, ptr, n, ptw; + int fd; + ssize_t r; + char buf[BUFSIZ]; + + ARGBEGIN { + default: + usage(); + } ARGEND; + + if (argc != 2) + usage(); + + if (tozu(argv[0], 0, SIZE_MAX, &count)) + eprintf("the count must be an integer in [0, %zu]\n", SIZE_MAX); + + fd = open(argv[1], O_RDONLY); + if (fd < 0) + eprintf("open %s:", argv[1]); + + while (count--) { + posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); + for (ptr = 0;;) { + r = pread(fd, buf, sizeof(buf), ptr); + if (r < 0) + eprintf("pread %s:", argv[1]); + else if (r == 0) + break; + ptr += n = (size_t)r; + for (ptw = 0; ptw < n;) { + r = write(STDOUT_FILENO, buf + ptw, n - ptw); + if (r < 0) + eprintf("write <stdout>:"); + ptw += (size_t)r; + } + } + } + + close(fd); + return 0; +} |
