編輯爲什麼我在使用zlib deflate的源文件中獲得一個恐怖?
// open output file for writing
if ((outfilefd = fopen(file_name, "w+t")) == NULL)
{
fprintf(stderr, "Unable to create file\n");
exit(1);
}
寫入文件,那麼就需要壓縮它。
打開.Z文件,然後調用DEF()
FILE *zipFile;
if ((zipFile = fopen("C:\\LOGS\\test.txt.z", "w+t")) == NULL)
{
fprintf(stderr, "Unable to create file\n");
exit(1);
}
int ret = def(outfilefd, zipFile, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK)
printf("ZLIB Error");
使用DEF(),從一site:
int def(FILE *source, FILE *dest, int level)
{
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
int g = ferror(source);//<---------------- EROR HERE returning 32?
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
zipFile
不爲空,strm.avail_in
= 16343,in
已數據但ferror(source)
返回32?
編輯 - 也strm.avail_in
= 16343引起了我的CHUNK
= 16384眼....行嗎?
任何想法或幫助表示讚賞。
謝謝。
我不知道是什麼32。嘗試[perror](http://www.opengroup.org/onlinepubs/000095399/functions/perror.html)以打印錯誤文本。 – 2010-07-16 01:03:23
在您的平臺上errno 32的含義是什麼,您可能會誤解(「」)嗎?在Linux上它說破管,這聽起來很奇怪,因爲你打開一個文件。 – mvds 2010-07-16 01:05:18
也許只是展示你如何打開源代碼,這是你的問題,爲什麼我們應該假設或猜測? – mvds 2010-07-16 01:06:16