diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/CONTRIB/SNIP/stripeof.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/CONTRIB/SNIP/stripeof.c')
-rwxr-xr-x | reference/C/CONTRIB/SNIP/stripeof.c | 61 |
1 files changed, 61 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <io.h>
+#include <fcntl.h>
+
+#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;
+}
|