1
1
mirror of https://github.com/jrbrtsn/ban2fail synced 2024-06-16 03:48:03 +00:00
ban2fail/ez_libz.c

240 lines
5.9 KiB
C
Raw Normal View History

2019-11-23 03:40:23 +00:00
/***************************************************************************
* Copyright (C) 2019 by John D. Robertson *
* john@rrci.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
2019-12-03 02:56:55 +00:00
#define _GNU_SOURCE
2019-11-23 03:40:23 +00:00
#include <stdlib.h>
2019-11-29 14:00:39 +00:00
#include "ez_libz.h"
2019-11-23 03:40:23 +00:00
#include "util.h"
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (gzFile, gzopen,
2019-11-23 03:40:23 +00:00
const char *path,
2020-09-15 15:31:27 +00:00
const char *mode)
2019-11-23 03:40:23 +00:00
{
gzFile rtn= gzopen(path, mode);
if(rtn) return rtn;
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzopen()");
2019-11-23 03:40:23 +00:00
abort();
}
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (int, gzclose, gzFile file)
2019-11-23 03:40:23 +00:00
{
int err= gzclose(file);
if(Z_OK == err) return Z_OK;
const char *msg="Unknow error";
switch(err) {
case Z_ERRNO:
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzclose()");
2019-11-23 03:40:23 +00:00
abort();
case Z_STREAM_ERROR:
msg= "File not valid";
break;
case Z_MEM_ERROR:
msg= "Out of memory";
break;
case Z_BUF_ERROR:
msg= "Read ended in middle of a stream";
break;
}
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gzclose() [ %s ]", msg);
2019-11-23 03:40:23 +00:00
abort();
}
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (int, gzwrite,
2019-11-23 03:40:23 +00:00
gzFile file,
voidpc buf,
2020-09-15 15:31:27 +00:00
unsigned len)
2019-11-23 03:40:23 +00:00
{
int n= gzwrite(file, buf, len);
if(n == len) return n;
int err;
const char *str= gzerror(file, &err);
if(Z_ERRNO == err) {
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzwrite()");
2019-11-23 03:40:23 +00:00
} else {
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gzwrite() [ %s ]", str);
2019-11-23 03:40:23 +00:00
}
abort();
}
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (int, gzread,
2019-11-23 03:40:23 +00:00
gzFile file,
voidp buf,
2020-09-15 15:31:27 +00:00
unsigned len)
2019-11-23 03:40:23 +00:00
{
int n= gzread(file, buf, len);
if(-1 != n) return n;
int err;
const char *str= gzerror(file, &err);
if(Z_ERRNO == err) {
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzread()");
2019-11-23 03:40:23 +00:00
} else {
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gzread() [ %s ]", str);
2019-11-23 03:40:23 +00:00
}
abort();
}
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (int, gzflush, gzFile file, int flush)
2019-11-23 03:40:23 +00:00
{
int err= gzflush(file, flush);
if(Z_OK == err) return Z_OK;
const char *str= gzerror(file, &err);
if(Z_ERRNO == err) {
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzflush()");
2019-11-23 03:40:23 +00:00
} else {
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gzflush() [ %s ]", str);
2019-11-23 03:40:23 +00:00
}
abort();
}
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (z_off_t, gzseek,
2019-11-23 03:40:23 +00:00
gzFile file,
z_off_t offset,
2020-09-15 15:31:27 +00:00
int whence)
2019-11-23 03:40:23 +00:00
{
z_off_t rtn= gzseek(file, offset, whence);
if(-1 != rtn) return rtn;
int err;
const char *str= gzerror(file, &err);
if(Z_ERRNO == err) {
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzseek()");
2019-11-23 03:40:23 +00:00
} else {
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gzseek() [ %s ]", str);
2019-11-23 03:40:23 +00:00
}
abort();
}
/***************************************************/
2020-09-15 15:31:27 +00:00
ez_proto (char*, gzgets,
2019-11-23 03:40:23 +00:00
gzFile file,
char *buf,
2020-09-15 15:31:27 +00:00
int len)
2019-11-23 03:40:23 +00:00
{
char *rtn= gzgets(file, buf, len);
if(!rtn) {
int err;
const char *str= gzerror(file, &err);
if(Z_OK != err && Z_STREAM_END != err) {
if(Z_ERRNO == err) {
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gzgets()");
2019-11-23 03:40:23 +00:00
} else {
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gzgets() [ %s ]", str);
2019-11-23 03:40:23 +00:00
}
abort();
}
}
return rtn;
}
2019-12-03 02:56:55 +00:00
/***************************************************/
2020-09-15 15:51:53 +00:00
ez_proto (z_off_t, gztell,
2020-09-15 15:31:27 +00:00
gzFile file)
2019-12-03 02:56:55 +00:00
{
z_off_t rtn= gztell(file);
if(-1 != rtn) return rtn;
int err;
const char *str= gzerror(file, &err);
if(Z_ERRNO == err) {
2019-12-04 14:11:39 +00:00
_sys_eprintf((const char*(*)(int))strerror
#ifdef DEBUG
, fileName, lineNo, funcName
#endif
, "ERROR: gztell()");
2019-12-03 02:56:55 +00:00
} else {
2019-12-04 14:11:39 +00:00
_eprintf(
#ifdef DEBUG
fileName, lineNo, funcName,
#endif
"ERROR: gztell() [ %s ]", str);
2019-12-03 02:56:55 +00:00
}
abort();
}