[BACK]Return to zopen.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / compress

Diff for /src/usr.bin/compress/zopen.c between version 1.11 and 1.12

version 1.11, 2003/06/22 15:22:43 version 1.12, 2003/07/11 02:31:18
Line 104 
Line 104 
         int zs_fd;                      /* File stream for I/O */          int zs_fd;                      /* File stream for I/O */
         char zs_mode;                   /* r or w */          char zs_mode;                   /* r or w */
         enum {          enum {
                 S_START, S_MIDDLE, S_EOF                  S_START, S_MAGIC, S_MIDDLE, S_EOF
         } zs_state;                     /* State of computation */          } zs_state;                     /* State of computation */
         int zs_n_bits;                  /* Number of bits/code. */          int zs_n_bits;                  /* Number of bits/code. */
         int zs_maxbits;                 /* User settable max # bits/code. */          int zs_maxbits;                 /* User settable max # bits/code. */
Line 227 
Line 227 
         count = num;          count = num;
         bp = (u_char *)wbp;          bp = (u_char *)wbp;
         switch (zs->zs_state) {          switch (zs->zs_state) {
           case S_MAGIC:
                   return -1;
         case S_EOF:          case S_EOF:
                 return 0;                  return 0;
         case S_START:          case S_START:
Line 468 
Line 470 
         case S_START:          case S_START:
                 zs->zs_state = S_MIDDLE;                  zs->zs_state = S_MIDDLE;
                 zs->zs_bp = zs->zs_buf;                  zs->zs_bp = zs->zs_buf;
                   header[0] = header[1] = header[2] = '\0';
                   read(zs->zs_fd, header, sizeof(header));
                 break;                  break;
           case S_MAGIC:
                   zs->zs_state = S_MIDDLE;
                   zs->zs_bp = zs->zs_buf;
                   header[0] = z_magic[0];
                   header[1] = z_magic[1];
                   header[2] = '\0';
                   read(zs->zs_fd, &header[2], 1);
                   break;
         case S_MIDDLE:          case S_MIDDLE:
                 goto middle;                  goto middle;
         case S_EOF:          case S_EOF:
Line 476 
Line 488 
         }          }
   
         /* Check the magic number */          /* Check the magic number */
         if (read(zs->zs_fd, header, sizeof(header)) != sizeof(header) ||          if (header[0] != z_magic[0] || header[1] != z_magic[1]) {
             memcmp(header, z_magic, sizeof(z_magic)) != 0) {  
                 errno = EFTYPE;                  errno = EFTYPE;
                 return (-1);                  return (-1);
         }          }
Line 706 
Line 717 
         if ((fd = open(name, (*mode=='r'? O_RDONLY:O_WRONLY|O_CREAT),          if ((fd = open(name, (*mode=='r'? O_RDONLY:O_WRONLY|O_CREAT),
             S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)              S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
                 return NULL;                  return NULL;
         if ((cookie = z_open(fd, mode, bits)) == NULL) {          if ((cookie = z_open(fd, mode, bits, 0)) == NULL) {
                 close(fd);                  close(fd);
                 return NULL;                  return NULL;
         }          }
Line 715 
Line 726 
 }  }
   
 void *  void *
 z_open(int fd, const char *mode, int bits)  z_open(int fd, const char *mode, int bits, int gotmagic)
 {  {
         struct s_zstate *zs;          struct s_zstate *zs;
   
Line 740 
Line 751 
         zs->zs_checkpoint = CHECK_GAP;          zs->zs_checkpoint = CHECK_GAP;
         zs->zs_in_count = 1;            /* Length of input. */          zs->zs_in_count = 1;            /* Length of input. */
         zs->zs_out_count = 0;           /* # of codes output (for debugging).*/          zs->zs_out_count = 0;           /* # of codes output (for debugging).*/
         zs->zs_state = S_START;          zs->zs_state = gotmagic ? S_MAGIC : S_START;
         zs->zs_offset = 0;          zs->zs_offset = 0;
         zs->zs_size = 0;          zs->zs_size = 0;
         zs->zs_mode = mode[0];          zs->zs_mode = mode[0];
Line 748 
Line 759 
   
         zs->zs_fd = fd;          zs->zs_fd = fd;
         return zs;          return zs;
 }  
   
 int  
 z_check_header(int fd, struct stat *sb, const char *ofn)  
 {  
         int f;  
         u_char buf[sizeof(z_magic)];  
         off_t off = lseek(fd, 0, SEEK_CUR);  
   
         f = (read(fd, buf, sizeof(buf)) == sizeof(buf) &&  
             !memcmp(buf, z_magic, sizeof(buf)));  
   
         lseek (fd, off, SEEK_SET);  
   
         return f;  
 }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12