From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/stripeof.c | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/stripeof.c (limited to 'reference/C/CONTRIB/SNIP/stripeof.c') diff --git a/reference/C/CONTRIB/SNIP/stripeof.c b/reference/C/CONTRIB/SNIP/stripeof.c new file mode 100755 index 0000000..f2a17ac --- /dev/null +++ b/reference/C/CONTRIB/SNIP/stripeof.c @@ -0,0 +1,61 @@ +/* +** STRIPEOF.C +** +** public domain demo by Bob Stout +*/ + +#include +#include +#include +#include + +#define BUFSIZE 16384 + +int main(int argc, char *argv[]) +{ + char *buf; + + if (2 > argc) + { + puts("Usage: STRIPEOF filename1 [...filenameN]"); + return EXIT_FAILURE; + } + if (NULL == (buf = malloc(BUFSIZE))) + { + puts("STRIPEOF internal failure"); + return EXIT_FAILURE; + } + while (--argc) + { + int fd; + size_t bytes; + int found = 0; + long zpos = 0L; + + if (-1 == (fd = open(*(++argv), O_RDWR | O_BINARY))) + { + printf("Couldn't open %s\n", *argv); + return EXIT_FAILURE; + } + while (0 < (bytes = read(fd, buf, BUFSIZE))) + { + int i; + + for (i = 0; i < (int)bytes; ++i) + { + if (('Z' - 64) == buf[i]) + { + found = 1; + zpos += i; + break; + } + } + if (found) + break; + zpos += bytes; + } + if (found) + chsize(fd, zpos); + } + return EXIT_SUCCESS; +} -- cgit v1.2.3-54-g00ecf