00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <errno.h>
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025 #include <fcntl.h>
00026 #include <unistd.h>
00027 #include "gunzip.h"
00028
00029 int gunzip_module(const char *name, const char *tmp)
00030 {
00031 gzFile file = gzopen(name, "rb");
00032 if (!file) {
00033 if (errno == 0) {
00034 return Z_MEM_ERROR;
00035 }
00036 return Z_ERRNO;
00037 }
00038
00039 int dest = open(tmp, O_WRONLY | O_CREAT, 0666);
00040 if (dest == -1) {
00041 gzclose(file);
00042 return Z_ERRNO;
00043 }
00044
00045
00046
00047 do {
00048 char buf[8192];
00049 int read = gzread(file, buf, sizeof(buf));
00050
00051 if (read == 0) {
00052 gzclose(file);
00053 close(dest);
00054 return Z_OK;
00055
00056 } else if (read == -1) {
00057 int err;
00058 gzerror(file, &err);
00059 return err;
00060
00061 } else {
00062 write(dest, buf, read);
00063 }
00064
00065 } while (1);
00066 }