home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 14 / CD_ASCQ_14_0694.iso / maj / 653 / stripeof.c < prev    next >
C/C++ Source or Header  |  1994-04-03  |  1KB  |  62 lines

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