home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / MISC / howfrag.lzh / HOWFRAG.C next >
C/C++ Source or Header  |  1991-11-09  |  942b  |  51 lines

  1. #include <modes.h>
  2. #include <stdio.h>
  3. #include <strings.h>
  4. #include <direct.h>
  5. #include <errno.h>
  6.  
  7. main (argc,argv)
  8. int argc;
  9. char **argv;
  10. {
  11.     int i,j,path,segs;
  12.     struct fildes filbuf;
  13.      
  14.     if (argc <2 || (strcmp (argv[1],"-?")==0))
  15.     {
  16.         fprintf(stderr,"Syntax:   %s <filename> [<filenames> ... ]\n",argv[0]);
  17.         fprintf(stderr,"Function: determine number of fragments in a file.\n");
  18.         exit(0);
  19.     }
  20.      
  21.     for (i=1; i<argc; i++)
  22.     {
  23.         path=open(argv[i],S_IREAD);
  24.         if (path==-1)
  25.         {
  26.             fprintf(stderr,"%s: error opening %s\n",argv[0],argv[i]);
  27.             exit(errno);
  28.         }
  29.          
  30.         if((_gs_gfd(path,&filbuf,sizeof(filbuf)))==-1)
  31.         {
  32.             fprintf(stderr,"%s: Error #%3d\n",argv[i],errno);
  33.         }
  34.         else
  35.         {
  36.             segs=0;
  37.             for (j=0; j<48; j++)
  38.             {
  39.                 if (filbuf.fdseg[j].addr[0]!='\0' ||
  40.                 filbuf.fdseg[j].addr[1]!='\0' ||
  41.                 filbuf.fdseg[j].addr[2]!='\0')
  42.                 {
  43.                     segs++;
  44.                 }
  45.             }
  46.             printf("%s: %d segments, 48 max\n",argv[i],segs);
  47.         }
  48.         close(path);
  49.     }
  50. }
  51.