untgz.c
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:11k
- /*
- * untgz.c -- Display contents and/or extract file from
- * a gzip'd TAR file
- * written by "Pedro A. Aranda Gutiirrez" <paag@tid.es>
- * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org>
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <errno.h>
- #include <fcntl.h>
- #ifdef unix
- # include <unistd.h>
- #else
- # include <direct.h>
- # include <io.h>
- #endif
- #include "zlib.h"
- #ifdef WIN32
- # ifndef F_OK
- # define F_OK (0)
- # endif
- # ifdef _MSC_VER
- # define mkdir(dirname,mode) _mkdir(dirname)
- # define strdup(str) _strdup(str)
- # define unlink(fn) _unlink(fn)
- # define access(path,mode) _access(path,mode)
- # else
- # define mkdir(dirname,mode) _mkdir(dirname)
- # endif
- #else
- # include <utime.h>
- #endif
- /* Values used in typeflag field. */
- #define REGTYPE '0' /* regular file */
- #define AREGTYPE ' ' /* regular file */
- #define LNKTYPE '1' /* link */
- #define SYMTYPE '2' /* reserved */
- #define CHRTYPE '3' /* character special */
- #define BLKTYPE '4' /* block special */
- #define DIRTYPE '5' /* directory */
- #define FIFOTYPE '6' /* FIFO special */
- #define CONTTYPE '7' /* reserved */
- #define BLOCKSIZE 512
- struct tar_header
- { /* byte offset */
- char name[100]; /* 0 */
- char mode[8]; /* 100 */
- char uid[8]; /* 108 */
- char gid[8]; /* 116 */
- char size[12]; /* 124 */
- char mtime[12]; /* 136 */
- char chksum[8]; /* 148 */
- char typeflag; /* 156 */
- char linkname[100]; /* 157 */
- char magic[6]; /* 257 */
- char version[2]; /* 263 */
- char uname[32]; /* 265 */
- char gname[32]; /* 297 */
- char devmajor[8]; /* 329 */
- char devminor[8]; /* 337 */
- char prefix[155]; /* 345 */
- /* 500 */
- };
- union tar_buffer {
- char buffer[BLOCKSIZE];
- struct tar_header header;
- };
- enum { TGZ_EXTRACT = 0, TGZ_LIST };
- static char *TGZfname OF((const char *));
- void TGZnotfound OF((const char *));
- int getoct OF((char *, int));
- char *strtime OF((time_t *));
- int ExprMatch OF((char *,char *));
- int makedir OF((char *));
- int matchname OF((int,int,char **,char *));
- void error OF((const char *));
- int tar OF((gzFile, int, int, int, char **));
- void help OF((int));
- int main OF((int, char **));
- char *prog;
- /* This will give a benign warning */
- static char *TGZprefix[] = { "