home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / STRIPEOF.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  64 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  STRIPEOF.C
  5. **
  6. **  public domain demo by Bob Stout
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <io.h>
  12. #include <fcntl.h>
  13.  
  14. #define BUFSIZE 16384
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.       char *buf;
  19.  
  20.       if (2 > argc)
  21.       {
  22.             puts("Usage: STRIPEOF filename1 [...filenameN]");
  23.             return EXIT_FAILURE;
  24.       }
  25.       if (NULL == (buf = malloc(BUFSIZE)))
  26.       {
  27.             puts("STRIPEOF internal failure");
  28.             return EXIT_FAILURE;
  29.       }
  30.       while (--argc)
  31.       {
  32.             int fd;
  33.             size_t bytes;
  34.             int found = 0;
  35.             long zpos = 0L;
  36.  
  37.             if (-1 == (fd = open(*(++argv), O_RDWR | O_BINARY)))
  38.             {
  39.                   printf("Couldn't open %s\n", *argv);
  40.                   return EXIT_FAILURE;
  41.             }
  42.             while (0 < (bytes = read(fd, buf, BUFSIZE)))
  43.             {
  44.                   int i;
  45.  
  46.                   for (i = 0; i < (int)bytes; ++i)
  47.                   {
  48.                         if (('Z' - 64) == buf[i])
  49.                         {
  50.                               found = 1;
  51.                               zpos += i;
  52.                               break;
  53.                         }
  54.                   }
  55.                   if (found)
  56.                         break;
  57.                   zpos += bytes;
  58.             }
  59.             if (found)
  60.                   chsize(fd, zpos);
  61.       }
  62.       return EXIT_SUCCESS;
  63. }
  64.