home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ARC521-2.ZIP / ARCTST.C < prev    next >
C/C++ Source or Header  |  1989-12-29  |  1KB  |  57 lines

  1. /*
  2.  * $Header: arctst.c,v 1.4 88/04/19 01:40:28 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCTST
  7.  *
  8.  * Version 2.12, created on 02/03/86 at 23:00:40
  9.  *
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  *
  12.  * By:  Thom Henderson
  13.  *
  14.  * Description: This file contains the routines used to test archive integrity.
  15.  *
  16.  * Language: Computer Innovations Optimizing C86
  17.  */
  18. #include <stdio.h>
  19. #include "arc.h"
  20.  
  21. void    openarc();
  22. int    readhdr(), unpack();
  23.  
  24. void
  25. tstarc()
  26. {                /* test integrity of an archive */
  27.     struct heads    hdr;    /* file header */
  28.     long            arcsize, ftell();    /* archive size */
  29.  
  30.     openarc(0);        /* open archive for reading */
  31.     fseek(arc, 0L, 2);    /* move to end of archive */
  32.     arcsize = ftell(arc);    /* see how big it is */
  33.     fseek(arc, 0L, 0);    /* return to top of archive */
  34.  
  35.     while (readhdr(&hdr, arc)) {
  36.         if (ftell(arc) + hdr.size > arcsize) {
  37.             printf("Archive truncated in file %s\n", hdr.name);
  38.             nerrs++;
  39.             break;
  40.         } else {
  41.             printf("Testing file: %-12s  ", hdr.name);
  42.             fflush(stdout);
  43.             if (unpack(arc, NULL, &hdr))
  44.                 nerrs++;
  45.             else
  46.                 printf("okay\n");
  47.         }
  48.     }
  49.  
  50.     if (nerrs < 1)
  51.         printf("No errors detected\n");
  52.     else if (nerrs == 1)
  53.         printf("One error detected\n");
  54.     else
  55.         printf("%d errors detected\n", nerrs);
  56. }
  57.