diff options
| author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-19 14:35:16 +0300 | 
|---|---|---|
| committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-19 15:13:07 +0300 | 
| commit | 743fb001f3d381b14d48f3fdfc9ee648a7c0644c (patch) | |
| tree | e46f65bfac59427b1389a4fb5d8c13ca34ed1c69 /bintrim.c | |
| parent | 6cb8c44fef192f3f8e7164d9c3baccacc9db620c (diff) | |
Refactor project, offer uio variant of region-rw
Diffstat (limited to 'bintrim.c')
| -rw-r--r-- | bintrim.c | 44 | 
1 files changed, 0 insertions, 44 deletions
| diff --git a/bintrim.c b/bintrim.c deleted file mode 100644 index 2a2018e..0000000 --- a/bintrim.c +++ /dev/null @@ -1,44 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <stdbool.h> -#include <string.h> -#include <err.h> - -int -main(int argc, const char *argv[]) -{ -   unsigned char trim = 0; - -   if (argc > 1) -      trim = strtoul(argv[1], NULL, 10); - -   bool leading = true; -   size_t rd, out_sz = 0, out_allocated = 0; -   char buf[4096], *out = NULL; -   while ((rd = fread(buf, 1, sizeof(buf), stdin))) { -      for (const char *s = buf; s < buf + rd; ++s) { -         if (*s == trim && leading) -            continue; - -         if (out_sz >= out_allocated) { -            if (!(out = realloc(out, out_allocated += sizeof(buf)))) -               err(EXIT_FAILURE, "realloc"); -         } - -         out[out_sz++] = *s; -         leading = false; -      } - -      const char *s; -      for (s = out + (out_sz ? out_sz - 1 : 0); s > out && *s == trim; --s); - -      const size_t to_write = (size_t)(s - out); -      if (fwrite(out, 1, to_write, stdout) != to_write) -         err(EXIT_FAILURE, "fwrite"); - -      memmove(out, s, (out_sz = out_sz - to_write)); -   } - -   free(out); -   return EXIT_SUCCESS; -} | 
