home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / portar / unpar.c < prev   
Encoding:
C/C++ Source or Header  |  1986-11-30  |  807 b   |  40 lines

  1. /* unpack portable archives - written by Bill Welch */
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4.  
  5. char buf[512];
  6. main()
  7. {
  8.     char name[80];
  9.     struct utimbuf {
  10.         time_t actime;
  11.         time_t modtime;
  12.     } times;
  13.     long mtime;
  14.     int uid, gid, mode;
  15.     long len, i;
  16.     FILE *fp;
  17.  
  18.     while(gets(buf) != NULL){
  19.         if (buf[strlen(buf) - 1] == '`') {
  20.             printf("%s\n", buf);
  21.             sscanf(buf, "%s %ld %d %d %o %ld", name,&mtime,&uid,&gid,
  22.                     &mode, &len);
  23.             printf("%s %ld\n", name, len);
  24.             fp = fopen(name, "w");
  25.             for (i=0; i<len; i++) putc(getchar(), fp);
  26.             fclose(fp);
  27.             times.actime = times.modtime = mtime;
  28.             /* If you don't have utime, just remove next 4 lines */
  29.             if( utime(name,×) < 0 )
  30.             {
  31.                 perror("Can't modify date");
  32.             }
  33.             if( chmod(name,mode) < 0 )
  34.             {
  35.                 perror("Can't modify mode");
  36.             }
  37.         }
  38.     }
  39. }
  40.