mirror of https://github.com/jrbrtsn/ban2fail
update ez files
This commit is contained in:
parent
9594faef04
commit
4ad2ea2af9
277
es.c
277
es.c
|
@ -1,3 +1,4 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -6,11 +7,11 @@
|
|||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "msgqueue.h"
|
||||
#include "ez_es.h"
|
||||
#include "map.h"
|
||||
#include "es.h"
|
||||
#include "ez_libpthread.h"
|
||||
#include "map.h"
|
||||
#include "msgqueue.h"
|
||||
#include "util.h"
|
||||
|
||||
/* Types of registered callbacks */
|
||||
enum ES_type {
|
||||
|
@ -79,9 +80,14 @@ static _Thread_local struct _TS {
|
|||
*/
|
||||
pthread_t tid;
|
||||
|
||||
enum {
|
||||
TS_PROCESSING_FLG= 1<<0
|
||||
} flags;
|
||||
|
||||
/* Vectors of Cb by type, for fast processing */
|
||||
PTRVEC fd_vec,
|
||||
timer_vec;
|
||||
timer_vec,
|
||||
deleted_vec;
|
||||
PTRVEC sig_vec_arr[NUMSIGS]; // One vector for each Unix signal
|
||||
|
||||
/* Hash table to quickly find Cb's */
|
||||
|
@ -98,6 +104,7 @@ static _Thread_local struct _TS {
|
|||
MAP cb_map;
|
||||
} vsig;
|
||||
|
||||
|
||||
} TS;
|
||||
|
||||
static void
|
||||
|
@ -115,6 +122,10 @@ UnixSignalHandler (int signo)
|
|||
/******************************************************************/
|
||||
typedef struct {
|
||||
|
||||
enum {
|
||||
CB_DELETED_FLG=1<<31
|
||||
} flags;
|
||||
|
||||
int64_t lastActivity_ms;
|
||||
|
||||
/* Process-wide unique integer */
|
||||
|
@ -188,6 +199,7 @@ Cb_FdConstructor(
|
|||
*/
|
||||
{
|
||||
assert(self);
|
||||
memset(self, 0, sizeof(*self));
|
||||
self->key= ++S.keySrc;
|
||||
self->type= ES_FD_TYPE;
|
||||
self->un.fd.fd= fd;
|
||||
|
@ -213,6 +225,7 @@ Cb_SignalConstructor(
|
|||
*/
|
||||
{
|
||||
assert(self);
|
||||
memset(self, 0, sizeof(*self));
|
||||
self->key= ++S.keySrc;
|
||||
self->type= ES_SIG_TYPE;
|
||||
self->un.sig.signum= signum;
|
||||
|
@ -235,6 +248,7 @@ Cb_VSignalConstructor(
|
|||
*/
|
||||
{
|
||||
assert(self);
|
||||
memset(self, 0, sizeof(*self));
|
||||
self->key= ++S.keySrc;
|
||||
self->type= ES_VSIG_TYPE;
|
||||
self->un.sig.signum= signum;
|
||||
|
@ -258,6 +272,7 @@ Cb_TimerConstructor(
|
|||
*/
|
||||
{
|
||||
assert(self);
|
||||
memset(self, 0, sizeof(*self));
|
||||
self->key= ++S.keySrc;
|
||||
self->type= ES_TIMER_TYPE;
|
||||
#if ! (defined (_WIN32) || defined (__CYGWIN__))
|
||||
|
@ -337,7 +352,8 @@ initialize()
|
|||
if(!(S.flags & GLOBAL_INIT_FLG)) {
|
||||
|
||||
S.flags |= GLOBAL_INIT_FLG;
|
||||
if(-1 == sigemptyset(&S.dflt_sa.set)) assert(0);
|
||||
if(-1 == sigemptyset(&S.dflt_sa.set))
|
||||
assert(0);
|
||||
MAP_constructor(&S.vsig.thrd_ts_map, 10, 10);
|
||||
}
|
||||
/* Release the global mutex */
|
||||
|
@ -346,10 +362,12 @@ initialize()
|
|||
/* Per-thread static data */
|
||||
PTRVEC_constructor(&TS.fd_vec, 10);
|
||||
PTRVEC_constructor(&TS.timer_vec, 10);
|
||||
PTRVEC_constructor(&TS.deleted_vec, 10);
|
||||
for(int i= 0; i < NUMSIGS; ++i) {
|
||||
PTRVEC_constructor(&TS.sig_vec_arr[i], 10);
|
||||
}
|
||||
if(-1 == sigemptyset(&TS.sigsRaised)) assert(0);
|
||||
if(-1 == sigemptyset(&TS.sigsRaised))
|
||||
assert(0);
|
||||
|
||||
MAP_constructor(&TS.key_map, 10, 10);
|
||||
|
||||
|
@ -411,16 +429,19 @@ ES_registerSignal (
|
|||
|
||||
sigaddset(&S.dflt_sa.set, signum);
|
||||
|
||||
if (sigaction (signum, &act, &S.dflt_sa.arr[ndx])) assert (0);
|
||||
if (sigaction (signum, &act, &S.dflt_sa.arr[ndx]))
|
||||
assert (0);
|
||||
|
||||
} else {
|
||||
|
||||
if (sigaction (signum, &act, NULL)) assert (0);
|
||||
if (sigaction (signum, &act, NULL))
|
||||
assert (0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!Cb_SignalCreate(cb, signum, callback_f, ctxt)) assert(0);
|
||||
if(!Cb_SignalCreate(cb, signum, callback_f, ctxt))
|
||||
assert(0);
|
||||
|
||||
/* All callbacks are put in the key table */
|
||||
MAP_addTypedKey(&TS.key_map, cb->key, cb);
|
||||
|
@ -455,7 +476,8 @@ ES_registerVSignal (
|
|||
|
||||
Cb *cb;
|
||||
|
||||
if(!Cb_VSignalCreate(cb, signum, callback_f, ctxt)) assert(0);
|
||||
if(!Cb_VSignalCreate(cb, signum, callback_f, ctxt))
|
||||
assert(0);
|
||||
|
||||
/* Place in the virtual signal map indexed on signum */
|
||||
MAP_addTypedKey(&TS.vsig.cb_map, cb->un.sig.signum, cb);
|
||||
|
@ -481,7 +503,8 @@ ES_registerFd (
|
|||
if(TS.tid != pthread_self()) initialize();
|
||||
|
||||
Cb *cb;
|
||||
if(!Cb_FdCreate(cb, fd, events, callback_f, ctxt)) assert(0);
|
||||
if(!Cb_FdCreate(cb, fd, events, callback_f, ctxt))
|
||||
assert(0);
|
||||
|
||||
/* Index to vector for quick processing */
|
||||
PTRVEC_addTail(&TS.fd_vec, cb);
|
||||
|
@ -505,7 +528,8 @@ ES_registerTimer (
|
|||
if(TS.tid != pthread_self()) initialize();
|
||||
|
||||
Cb *cb;
|
||||
if(!Cb_TimerCreate(cb, pause_ms, interval_ms, callback_f, ctxt)) assert(0);
|
||||
if(!Cb_TimerCreate(cb, pause_ms, interval_ms, callback_f, ctxt))
|
||||
assert(0);
|
||||
|
||||
/* Add to the timer vector */
|
||||
PTRVEC_addTail(&TS.timer_vec, cb);
|
||||
|
@ -525,17 +549,33 @@ ES_unregister (int key)
|
|||
if(TS.tid != pthread_self()) initialize();
|
||||
|
||||
Cb *cb = MAP_findTypedItem(&TS.key_map, key);
|
||||
if(!cb) return -1;
|
||||
if(!cb) {
|
||||
#ifdef qqDEBUG
|
||||
eprintf("WARNING: could not find callback with key= %d", key);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the callback processing is currently active, do not delete it */
|
||||
if(TS.flags & TS_PROCESSING_FLG) {
|
||||
if(!(cb->flags & CB_DELETED_FLG)) {
|
||||
cb->flags |= CB_DELETED_FLG;
|
||||
PTRVEC_addTail(&TS.deleted_vec, cb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remove from key table */
|
||||
if(!MAP_removeTypedItem(&TS.key_map, key)) assert(0);;
|
||||
if(!MAP_removeTypedItem(&TS.key_map, key))
|
||||
assert(0);
|
||||
|
||||
/* Different operations needed based on type */
|
||||
switch(cb->type) {
|
||||
|
||||
case ES_FD_TYPE:
|
||||
/* Remove from file descriptor vector */
|
||||
if(!PTRVEC_remove(&TS.fd_vec, cb)) assert(0);
|
||||
if(!PTRVEC_remove(&TS.fd_vec, cb))
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
case ES_SIG_TYPE:
|
||||
|
@ -543,7 +583,8 @@ ES_unregister (int key)
|
|||
unsigned ndx= signum2dflt_sa_ndx(cb->un.sig.signum);
|
||||
|
||||
/* Remove from appropriate signals vector */
|
||||
if(!PTRVEC_remove(&TS.sig_vec_arr[ndx], cb)) assert(0);
|
||||
if(!PTRVEC_remove(&TS.sig_vec_arr[ndx], cb))
|
||||
assert(0);
|
||||
|
||||
/* If there are no more signals in this vector */
|
||||
if(!PTRVEC_numItems(&TS.sig_vec_arr[ndx])) {
|
||||
|
@ -551,17 +592,20 @@ ES_unregister (int key)
|
|||
assert(sigismember(&S.dflt_sa.set, cb->un.sig.signum));
|
||||
|
||||
/* Restore default signal handling */
|
||||
if (sigaction (cb->un.sig.signum, &S.dflt_sa.arr[ndx], NULL)) assert (0);
|
||||
if (sigaction (cb->un.sig.signum, &S.dflt_sa.arr[ndx], NULL))
|
||||
assert (0);
|
||||
}
|
||||
} break;
|
||||
|
||||
case ES_VSIG_TYPE:
|
||||
if(!MAP_removeSpecificTypedItem(&TS.vsig.cb_map, cb->un.sig.signum, cb)) assert(0);
|
||||
if(!MAP_removeSpecificTypedItem(&TS.vsig.cb_map, cb->un.sig.signum, cb))
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
case ES_TIMER_TYPE:
|
||||
/* Remove from timer vector */
|
||||
if(!PTRVEC_remove(&TS.timer_vec, cb)) assert(0);
|
||||
if(!PTRVEC_remove(&TS.timer_vec, cb))
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -612,22 +656,23 @@ ES_run (void)
|
|||
* Whatever nonzero value one of the callbacks() returned.
|
||||
*/
|
||||
{
|
||||
int rtn= -1;
|
||||
|
||||
if(TS.tid != pthread_self())
|
||||
initialize();
|
||||
|
||||
/* Loop forever */
|
||||
for(;;) {
|
||||
TS.flags |= TS_PROCESSING_FLG;
|
||||
|
||||
int numFds= PTRVEC_numItems(&TS.fd_vec);
|
||||
struct pollfd pollItemArr[numFds];
|
||||
Cb *cbArr[numFds];
|
||||
|
||||
|
||||
/* This sort provides fair queuing */
|
||||
PTRVEC_sort(&TS.fd_vec, lastActivity_cmp);
|
||||
|
||||
/****** Load up the ZeroMQ pollItemArr *****/
|
||||
/****** Load up the pollItemArr *****/
|
||||
unsigned i;
|
||||
Cb *cb;
|
||||
PTRVEC_loopFwd(&TS.fd_vec, i, cb) {
|
||||
|
@ -694,8 +739,8 @@ ES_run (void)
|
|||
switch(errno) {
|
||||
|
||||
case EFAULT:
|
||||
eprintf("\tpoll() failed");
|
||||
return -1;
|
||||
eprintf("ERROR: poll() failed");
|
||||
goto abort;
|
||||
|
||||
case EINTR:
|
||||
/* Signal caused poll() to return, which is OK */
|
||||
|
@ -725,10 +770,14 @@ ES_run (void)
|
|||
|
||||
assert(ES_SIG_TYPE == cb->type);
|
||||
|
||||
/* Call the callback function */
|
||||
int error= (* cb->un.sig.callback_f)(cb->ctxt, signum);
|
||||
if(cb->flags & CB_DELETED_FLG)
|
||||
continue;
|
||||
|
||||
if(error) return error;
|
||||
/* Call the callback function */
|
||||
rtn= (* cb->un.sig.callback_f)(cb->ctxt, signum);
|
||||
|
||||
if(rtn)
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -747,6 +796,9 @@ ES_run (void)
|
|||
|
||||
PTRVEC_loopFwd(&TS.timer_vec, i, cb) {
|
||||
|
||||
if(cb->flags & CB_DELETED_FLG)
|
||||
continue;
|
||||
|
||||
/* See how much time remains for this callback */
|
||||
remaining_ms= msec2timeout(cb, time_ms);
|
||||
|
||||
|
@ -757,7 +809,7 @@ ES_run (void)
|
|||
++cb->un.timer.count;
|
||||
|
||||
/* Call the callback function */
|
||||
int error= (* cb->un.timer.callback_f)(cb->ctxt);
|
||||
rtn= (* cb->un.timer.callback_f)(cb->ctxt);
|
||||
|
||||
/* If this is a single-shot timer, get rid of it now */
|
||||
if(!cb->un.timer.interval_ms) {
|
||||
|
@ -767,9 +819,11 @@ ES_run (void)
|
|||
}
|
||||
|
||||
/* If the callback returned non-zero, bail out */
|
||||
if(error) return error;
|
||||
if(rtn)
|
||||
goto abort;
|
||||
|
||||
} else break; /* time remaining will increase from here on out */
|
||||
} else
|
||||
break; /* time remaining will increase from here on out */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,31 +837,36 @@ ES_run (void)
|
|||
|
||||
Cb *cb= cbArr[i];
|
||||
|
||||
if(cb->flags & CB_DELETED_FLG)
|
||||
continue;
|
||||
|
||||
#if ! (defined (_WIN32) || defined (__CYGWIN__))
|
||||
cb->lastActivity_ms= clock_gettime_ms(CLOCK_MONOTONIC_COARSE);
|
||||
#else
|
||||
cb->lastActivity_ms= clock_gettime_ms(CLOCK_MONOTONIC);
|
||||
#endif
|
||||
|
||||
int error;
|
||||
switch(cb->type) {
|
||||
assert(ES_FD_TYPE == cb->type);
|
||||
|
||||
case ES_FD_TYPE:
|
||||
/* Call the callback function */
|
||||
error= (* cb->un.fd.callback_f)(cb->ctxt, item->fd, item->revents);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
rtn= (* cb->un.fd.callback_f)(cb->ctxt, item->fd, item->revents);
|
||||
|
||||
/* If the callback returned non-zero, bail out */
|
||||
if(error) return error;
|
||||
if(rtn)
|
||||
goto abort;
|
||||
}
|
||||
|
||||
{ /*--- Free any callbacks marked for deletion ---*/
|
||||
Cb *cb;
|
||||
TS.flags &= ~TS_PROCESSING_FLG;
|
||||
while((cb= PTRVEC_remTail(&TS.deleted_vec))) {
|
||||
if(ES_unregister(cb->key))
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Shouldn't ever get to here */
|
||||
assert(0);
|
||||
abort:
|
||||
return rtn;
|
||||
}
|
||||
|
||||
pthread_t
|
||||
|
@ -979,3 +1038,135 @@ abort:
|
|||
ez_pthread_mutex_unlock(&S.vsig.mtx);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/*=====================================================================================*/
|
||||
/*===================== ez_xxx() ======================================================*/
|
||||
/*=====================================================================================*/
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, ES_registerFd,
|
||||
int fd,
|
||||
short events,
|
||||
int (*callback_f)(void *ctxt, int fd, short events),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerFd(fd, events, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerFd() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
|
||||
ez_proto (int, ES_registerSignal,
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt, int signo),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerSignal(signum, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerSignal() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
|
||||
ez_proto (int, ES_registerVSignal,
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt,int signo),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerVSignal(signum, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerVSignal() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, ES_VSignal,
|
||||
pthread_t tid,
|
||||
int signum)
|
||||
{
|
||||
int rtn= ES_VSignal(tid, signum);
|
||||
if(rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_VSignal() returned %d.", rtn);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, ES_registerTimer,
|
||||
int64_t pause_ms,
|
||||
int64_t interval_ms,
|
||||
int (*callback_f)(void *ctxt),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerTimer(pause_ms, interval_ms, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerTimer() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto ( int, ES_unregister, int key)
|
||||
{
|
||||
int rtn= ES_unregister(key);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_unregister() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, ES_run)
|
||||
{
|
||||
int rtn= ES_run();
|
||||
if(rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_run() returned %d", rtn);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
|
90
es.h
90
es.h
|
@ -7,20 +7,23 @@
|
|||
* timers.
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ez.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
ES_registerFd (
|
||||
ez_hdr_proto (int, ES_registerFd,
|
||||
int fd,
|
||||
short events,
|
||||
int (*callback_f)(void *ctxt, int fd, short events),
|
||||
void *ctxt
|
||||
);
|
||||
void *ctxt);
|
||||
/**********************************************************************
|
||||
* Register a function to be called when there is activity on the
|
||||
* file descriptor (which may be a file, socket, pipe, etc. under Unix).
|
||||
|
@ -34,13 +37,18 @@ ES_registerFd (
|
|||
* If successful, a positive integer which can be used to unregister the callback.
|
||||
* On failure, -1 is returned.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerFd(...) \
|
||||
_ez_ES_registerFd(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_registerFd(...) \
|
||||
_ez_ES_registerFd(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
int
|
||||
ES_registerSignal (
|
||||
ez_hdr_proto (int, ES_registerSignal,
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt, int signo),
|
||||
void *ctxt
|
||||
);
|
||||
void *ctxt);
|
||||
/**********************************************************************
|
||||
* Register a function to be called when a particular Unix signal is
|
||||
* raised. Note: callback_f() is not called from a Unix signal handler,
|
||||
|
@ -54,13 +62,18 @@ ES_registerSignal (
|
|||
* If successful, a positive integer which can be used to unregister the callback.
|
||||
* On failure, -1 is returned.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerSignal(...) \
|
||||
_ez_ES_registerSignal(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_registerSignal(...) \
|
||||
_ez_ES_registerSignal(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
int
|
||||
ES_registerVSignal (
|
||||
ez_hdr_proto (int, ES_registerVSignal,
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt,int signo),
|
||||
void *ctxt
|
||||
);
|
||||
void *ctxt);
|
||||
/**********************************************************************
|
||||
* Register a function to be called when a particular virtual signal is
|
||||
* raised. Virtual signals are implemented on top of the Unix signal, SIGUSR2.
|
||||
|
@ -73,9 +86,17 @@ ES_registerVSignal (
|
|||
* If successful, a positive integer which can be used to unregister the callback.
|
||||
* On failure, -1 is returned.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerVSignal(...) \
|
||||
_ez_ES_registerVSignal(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_registerVSignal(...) \
|
||||
_ez_ES_registerVSignal(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
int
|
||||
ES_VSignal (pthread_t tid, int signum);
|
||||
ez_hdr_proto (int, ES_VSignal,
|
||||
pthread_t tid,
|
||||
int signum);
|
||||
/**********************************************************************
|
||||
* Send a virtual signal to tid, which is multiplexed on SIGUSR2.
|
||||
*
|
||||
|
@ -86,9 +107,15 @@ ES_VSignal (pthread_t tid, int signum);
|
|||
* 0: successful
|
||||
* -1: failures.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_VSignal(...) \
|
||||
_ez_ES_VSignal(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_VSignal(...) \
|
||||
_ez_ES_VSignal(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
int
|
||||
ES_registerTimer (
|
||||
ez_hdr_proto (int, ES_registerTimer,
|
||||
int64_t pause_ms,
|
||||
int64_t interval_ms,
|
||||
int (*callback_f)(void *ctxt),
|
||||
|
@ -109,11 +136,16 @@ ES_registerTimer (
|
|||
* If successful, a positive integer which can be used to unregister the callback.
|
||||
* On failure, -1 is returned.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerTimer(...) \
|
||||
_ez_ES_registerTimer(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_registerTimer(...) \
|
||||
_ez_ES_registerTimer(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int
|
||||
ES_unregister (int key);
|
||||
ez_hdr_proto (int, ES_unregister,
|
||||
int key);
|
||||
/**********************************************************************
|
||||
* Unegister a previously registered callback.
|
||||
*
|
||||
|
@ -123,10 +155,15 @@ ES_unregister (int key);
|
|||
* 0 for success.
|
||||
* -1 for failure (key not found)
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_unregister(...) \
|
||||
_ez_ES_unregister(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_unregister(...) \
|
||||
_ez_ES_unregister(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
ES_run (void);
|
||||
ez_hdr_proto (int, ES_run);
|
||||
/**********************************************************************
|
||||
* For this thread, use poll() to process socket activity until one
|
||||
* of the registered callback_f() returns non-zero.
|
||||
|
@ -134,6 +171,13 @@ ES_run (void);
|
|||
* RETURNS:
|
||||
* Whatever nonzero value callback_f() returned.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_run(...) \
|
||||
_ez_ES_run(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_ES_run(...) \
|
||||
_ez_ES_run(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
pthread_t
|
||||
ES_spawn_thread_sched(
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/*****************************************************************************
|
||||
* In an effort to make C programming both easier and more secure, I present
|
||||
* the EZ method.
|
||||
*
|
||||
* Reasoning for this is simple; Many function calls can fail for a variety of
|
||||
* reasons, some or even most of which are obscure. However, it is both
|
||||
* insecure and counterproductive not to check for said failures. Unfortunately
|
||||
* coding proper checks and/or recovery from failures will involve (often
|
||||
* complex) logic constructs, and detracts from understanding the primary logic
|
||||
* of your source code.
|
||||
*
|
||||
* Sometimes your app needs to recover, and so you must supply this code, but
|
||||
* more often than not a "boilplate" approach is sufficient. The EZ method is a
|
||||
* consistent convention to supply centralized and reusable "boilerplate" error
|
||||
* handling on an _optional_ basis, both for existing library functions and
|
||||
* your own.
|
||||
*
|
||||
* Modern programming languages address this problem by throwing "exceptions",
|
||||
* which by default result in your program getting terminated. To avoid
|
||||
* termination you must write code to "catch" such exceptions, but this code
|
||||
* exists separated in source code from the function call, and tends to be both
|
||||
* confusing to read and hideous to look at. If you thought "goto" statements
|
||||
* were in poor taste, then this will make you vomit.
|
||||
*
|
||||
* Enter the EZ method; from a practical coding standpoint you merely prepend
|
||||
* "ez_" to any function call for which you desire default error handling. When
|
||||
* an error occurs a very helpful error message is printed (in DEBUG mode this
|
||||
* includes the source code location from which the function was called), and
|
||||
* your program is terminated. If your app needs to recover from such an error,
|
||||
* simply erase the "ez_" prefix from the function call and supply the recovery
|
||||
* code, where God intended it to be - right where you made the function call!
|
||||
*
|
||||
* In effect the EZ method provides the utility of throwing exceptions, but
|
||||
* without the catch - Woohoo!
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef EZ_H
|
||||
#define EZ_H
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* These macros ease the drudgery of writing prototypes for the _ez_XXX()
|
||||
* wrappers of functions, and reduce the liklihood of bugs due to typing
|
||||
* errors.
|
||||
*
|
||||
* The elipses is for your function's argument list.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define ez_proto(rtn, funcname, ...) \
|
||||
rtn _ez_##funcname( \
|
||||
const char *fileName, \
|
||||
int lineNo, \
|
||||
const char *funcName, \
|
||||
##__VA_ARGS__ \
|
||||
)
|
||||
|
||||
#define ez_hdr_proto(rtn, funcname, ...) \
|
||||
ez_proto(rtn, funcname, ##__VA_ARGS__); \
|
||||
rtn funcname(__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define ez_proto(rtn, funcname, ...) \
|
||||
rtn _ez_##funcname(__VA_ARGS__)
|
||||
|
||||
#define ez_hdr_proto(rtn, funcname, ...) \
|
||||
ez_proto(rtn, funcname, ##__VA_ARGS__); \
|
||||
rtn funcname(__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* For example, if you have the following function prototype:
|
||||
*
|
||||
* int myfunc (struct foo *f, double bar)
|
||||
*
|
||||
* In the header file where the function prototype goes,
|
||||
* you will need this:
|
||||
*
|
||||
* ez_hdr_proto (int, myfunc, struct foo *f, double bar);
|
||||
*
|
||||
* #ifdef DEBUG
|
||||
* # define ez_myfunc(...) \
|
||||
* _ez_myfunc(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
* #else
|
||||
* # define ez_myfunc(...) \
|
||||
* _ez_myfunc(__VA_ARGS__)
|
||||
* #endif
|
||||
*
|
||||
* This will expand to the standard function prototype as listed above, as well
|
||||
* as the _ez_myfunc() prototype correct for either DEBUG version or production
|
||||
* version, depending on whether or not DEBUG is #define'd. Also, there is now
|
||||
* a macro ez_myfunc() which will expand to the correct _ez_myfunc()
|
||||
* function call.
|
||||
*
|
||||
* In the implmentation (*.c) file, you will need to supply code for
|
||||
* _ez_myfunc(), which looks like so:
|
||||
*
|
||||
* ez_proto(int, myfunc, struct foo *f, double bar)
|
||||
* {
|
||||
* // implementation goes here
|
||||
* }
|
||||
*
|
||||
* Notice that the prototype section is is the same as what you placed in the
|
||||
* corresponding header file, minus "_hdr" in the ez_hdr_proto() macro.
|
||||
*
|
||||
* For the case where you are supplying only the ez_XXX() version of an
|
||||
* existing function found in some library 'liba2z', you can place the
|
||||
* following in your own header file, "ez_liba2z.h":
|
||||
*
|
||||
* ez_proto(struct rtnType*, liba2z_funcname, struct foo *f, double bar);
|
||||
*
|
||||
* Everything else works similar to the previous examples.
|
||||
* Now you can use the EZ error handling like so:
|
||||
*
|
||||
* #include "ez_liba2z.h"
|
||||
* int main(int argc, char **argv)
|
||||
* {
|
||||
* struct foo Foo;
|
||||
* double bar;
|
||||
* struct rtnType *rtn= ez_liba2z_funcname(&Foo, bar);
|
||||
* }
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#endif
|
171
ez_es.c
171
ez_es.c
|
@ -1,171 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "ez_es.h"
|
||||
|
||||
/***************************************************/
|
||||
int _ez_ES_registerFd (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int fd,
|
||||
short events,
|
||||
int (*callback_f)(void *ctxt, int fd, short events),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerFd(fd, events, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerFd() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
|
||||
int _ez_ES_registerSignal (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt, int signo),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerSignal(signum, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerSignal() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
|
||||
int _ez_ES_registerVSignal (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt, int signo),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerVSignal(signum, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerVSignal() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_ES_VSignal (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_t tid,
|
||||
int signum
|
||||
)
|
||||
{
|
||||
int rtn= ES_VSignal(tid, signum);
|
||||
if(rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_VSignal() returned %d.", rtn);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_ES_registerTimer (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int64_t pause_ms,
|
||||
int64_t interval_ms,
|
||||
int (*callback_f)(void *ctxt),
|
||||
void *ctxt
|
||||
)
|
||||
{
|
||||
int rtn= ES_registerTimer(pause_ms, interval_ms, callback_f, ctxt);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_registerTimer() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_ES_unregister (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int key
|
||||
)
|
||||
{
|
||||
int rtn= ES_unregister(key);
|
||||
if(-1 == rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_unregister() failed.");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_ES_run (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int rtn= ES_run();
|
||||
if(rtn) {
|
||||
_eprintf(
|
||||
#ifdef DEBUG
|
||||
fileName, lineNo, funcName,
|
||||
#endif
|
||||
"ES_run() returned %d", rtn);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
144
ez_es.h
144
ez_es.h
|
@ -1,144 +0,0 @@
|
|||
/****************************************************************************************************************************
|
||||
* NOTE: look in "es.h" for function documentation. The ez_XXX() macros here only wrap the ES_XXX() functions
|
||||
* for the purpose of boilerplate error handling.
|
||||
*/
|
||||
|
||||
#ifndef EZ_ES_H
|
||||
#define EZ_ES_H
|
||||
|
||||
#include "es.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerFd(fd, events, callback_f, ctxt) \
|
||||
_ez_ES_registerFd(__FILE__, __LINE__, __FUNCTION__, fd, events, callback_f, ctxt)
|
||||
#else
|
||||
# define ez_ES_registerFd(fd, events, callback_f, ctxt) \
|
||||
_ez_ES_registerFd(fd, events, callback_f, ctxt)
|
||||
#endif
|
||||
int _ez_ES_registerFd (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int fd,
|
||||
short events,
|
||||
int (*callback_f)(void *ctxt, int fd, short events),
|
||||
void *ctxt
|
||||
);
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerSignal(signum, callback_f, ctxt) \
|
||||
_ez_ES_registerSignal(__FILE__, __LINE__, __FUNCTION__, signum, callback_f, ctxt)
|
||||
#else
|
||||
# define ez_ES_registerSignal(signum, callback_f, ctxt) \
|
||||
_ez_ES_registerSignal(signum, callback_f, ctxt)
|
||||
#endif
|
||||
int _ez_ES_registerSignal (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt, int signo),
|
||||
void *ctxt
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerVSignal(signum, callback_f, ctxt) \
|
||||
_ez_ES_registerVSignal(__FILE__, __LINE__, __FUNCTION__, signum, callback_f, ctxt)
|
||||
#else
|
||||
# define ez_ES_registerVSignal(signum, callback_f, ctxt) \
|
||||
_ez_ES_registerVSignal(signum, callback_f, ctxt)
|
||||
#endif
|
||||
int _ez_ES_registerVSignal (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int signum,
|
||||
int (*callback_f)(void *ctxt, int signo),
|
||||
void *ctxt
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_VSignal(tid, signum) \
|
||||
_ez_ES_VSignal(__FILE__, __LINE__, __FUNCTION__, tid, signum)
|
||||
#else
|
||||
# define ez_ES_VSignal(tid, signum) \
|
||||
_ez_ES_VSignal(tid, signum)
|
||||
#endif
|
||||
int _ez_ES_VSignal (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_t tid,
|
||||
int signum
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_registerTimer(pause_ms, interval_ms, callback_f, ctxt) \
|
||||
_ez_ES_registerTimer(__FILE__, __LINE__, __FUNCTION__, pause_ms, interval_ms, callback_f, ctxt)
|
||||
#else
|
||||
# define ez_ES_registerTimer(pause_ms, interval_ms, callback_f, ctxt) \
|
||||
_ez_ES_registerTimer(pause_ms, interval_ms, callback_f, ctxt)
|
||||
#endif
|
||||
int _ez_ES_registerTimer (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int64_t pause_ms,
|
||||
int64_t interval_ms,
|
||||
int (*callback_f)(void *ctxt),
|
||||
void *ctxt
|
||||
);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_unregister(key) \
|
||||
{_ez_ES_unregister(__FILE__, __LINE__, __FUNCTION__, key); (key)= 0;}
|
||||
#else
|
||||
# define ez_ES_unregister(key) \
|
||||
{_ez_ES_unregister(key); (key)= 0;}
|
||||
#endif
|
||||
int _ez_ES_unregister (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int key
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_ES_run() \
|
||||
_ez_ES_run(__FILE__, __LINE__, __FUNCTION__)
|
||||
#else
|
||||
# define ez_ES_run() \
|
||||
_ez_ES_run()
|
||||
#endif
|
||||
int _ez_ES_run (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName
|
||||
#endif
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
49
ez_libanl.h
49
ez_libanl.h
|
@ -20,49 +20,40 @@
|
|||
#define EZ_LIBANL_H
|
||||
|
||||
/* Simplified interface to libanl functions */
|
||||
#define _GNU_SOURCE
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include "ez.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_getaddrinfo_a(mode, list, nItems, sevp) \
|
||||
_ez_getaddrinfo_a(__FILE__, __LINE__, __FUNCTION__, mode, list, nItems, sevp)
|
||||
#else
|
||||
# define ez_getaddrinfo_a(mode, list, nItems, sevp) \
|
||||
_ez_getaddrinfo_a(mode, list, nItems, sevp)
|
||||
#endif
|
||||
int _ez_getaddrinfo_a(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto(int, getaddrinfo_a,
|
||||
int mode,
|
||||
struct gaicb *list[],
|
||||
int nitems,
|
||||
struct sigevent *sevp
|
||||
);
|
||||
|
||||
struct sigevent *sevp);
|
||||
#ifdef DEBUG
|
||||
# define ez_gai_suspend(list, nItems, timeout) \
|
||||
_ez_gai_suspend(__FILE__, __LINE__, __FUNCTION__, list, nItems, timeout)
|
||||
# define ez_getaddrinfo_a(...) \
|
||||
_ez_getaddrinfo_a(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gai_suspend(list, nItems, timeout) \
|
||||
_ez_gai_suspend(list, nItems, timeout)
|
||||
#endif
|
||||
int _ez_gai_suspend(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_getaddrinfo_a(...) \
|
||||
_ez_getaddrinfo_a(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, gai_suspend,
|
||||
const struct gaicb * const list[],
|
||||
int nitems,
|
||||
const struct timespec *timeout
|
||||
);
|
||||
const struct timespec *timeout);
|
||||
#ifdef DEBUG
|
||||
# define ez_gai_suspend(...) \
|
||||
_ez_gai_suspend(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gai_suspend(...) \
|
||||
_ez_gai_suspend(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
507
ez_libc.c
507
ez_libc.c
|
@ -25,15 +25,9 @@
|
|||
#include "ez_libc.h"
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fputs (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, fputs,
|
||||
const char *s,
|
||||
FILE *stream
|
||||
)
|
||||
FILE *stream)
|
||||
{
|
||||
int rtn= fputs (s, stream);
|
||||
if (EOF == rtn) {
|
||||
|
@ -48,15 +42,9 @@ int _ez_fputs (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fputc (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, fputc,
|
||||
int c,
|
||||
FILE *stream
|
||||
)
|
||||
FILE *stream)
|
||||
{
|
||||
int rtn= fputc (c, stream);
|
||||
if (EOF == rtn) {
|
||||
|
@ -71,16 +59,10 @@ int _ez_fputc (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fprintf (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, fprintf,
|
||||
FILE *stream,
|
||||
const char *fmt,
|
||||
...
|
||||
)
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
@ -94,7 +76,7 @@ int _ez_fprintf (
|
|||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "vfprintf() failed");
|
||||
, "vfprintf() failed returning %d", rtn);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -102,15 +84,9 @@ int _ez_fprintf (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
FILE* _ez_popen (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (FILE*, popen,
|
||||
const char *command,
|
||||
const char *type
|
||||
)
|
||||
const char *type)
|
||||
{
|
||||
errno= 0;
|
||||
FILE *rtn= popen (command, type);
|
||||
|
@ -126,15 +102,27 @@ FILE* _ez_popen (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
FILE* _ez_fopen (
|
||||
ez_proto (FILE*, fdopen,
|
||||
int fd,
|
||||
const char *mode)
|
||||
{
|
||||
FILE *rtn= fdopen (fd, mode);
|
||||
if (!rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "fdopen(%d, \"%s\") failed", fd, mode);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (FILE*, fopen,
|
||||
const char *pathname,
|
||||
const char *mode
|
||||
)
|
||||
const char *mode)
|
||||
{
|
||||
FILE *rtn= fopen (pathname, mode);
|
||||
if (!rtn) {
|
||||
|
@ -149,14 +137,23 @@ FILE* _ez_fopen (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fclose (
|
||||
ez_proto (pid_t, fork)
|
||||
{
|
||||
int rtn= fork ();
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
FILE *stream
|
||||
)
|
||||
, "fork() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, fclose,
|
||||
FILE *stream)
|
||||
{
|
||||
int rtn= fclose (stream);
|
||||
if (EOF == rtn) {
|
||||
|
@ -171,14 +168,8 @@ int _ez_fclose (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fflush (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
FILE *stream
|
||||
)
|
||||
ez_proto (int, fflush,
|
||||
FILE *stream)
|
||||
{
|
||||
int rtn= fflush (stream);
|
||||
if (EOF == rtn) {
|
||||
|
@ -193,17 +184,11 @@ int _ez_fflush (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
size_t _ez_fread (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (size_t, fread,
|
||||
void *ptr,
|
||||
size_t size,
|
||||
size_t nmemb,
|
||||
FILE *stream
|
||||
)
|
||||
FILE *stream)
|
||||
{
|
||||
size_t rtn= fread (ptr, size, nmemb, stream);
|
||||
if (ferror(stream)) {
|
||||
|
@ -218,17 +203,11 @@ size_t _ez_fread (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
size_t _ez_fwrite (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (size_t, fwrite,
|
||||
const void *ptr,
|
||||
size_t size,
|
||||
size_t nmemb,
|
||||
FILE *stream
|
||||
)
|
||||
FILE *stream)
|
||||
{
|
||||
size_t rtn= fwrite (ptr, size, nmemb, stream);
|
||||
if (ferror(stream)) {
|
||||
|
@ -243,14 +222,8 @@ size_t _ez_fwrite (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pclose (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
FILE *stream
|
||||
)
|
||||
ez_proto (int, pclose,
|
||||
FILE *stream)
|
||||
{
|
||||
int rtn= pclose (stream);
|
||||
if (-1 == rtn) {
|
||||
|
@ -265,16 +238,25 @@ int _ez_pclose (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
char* _ez_fgets (
|
||||
ez_proto (int, pipe, int pipefd[2])
|
||||
{
|
||||
int rtn= pipe (pipefd);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "pipe() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (char*, fgets,
|
||||
char *s,
|
||||
int size,
|
||||
FILE *stream
|
||||
)
|
||||
FILE *stream)
|
||||
{
|
||||
char *rtn= fgets (s, size, stream);
|
||||
if (!rtn && !feof(stream)) {
|
||||
|
@ -289,14 +271,8 @@ char* _ez_fgets (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_remove (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
const char *pathname
|
||||
)
|
||||
ez_proto (int, remove,
|
||||
const char *pathname)
|
||||
{
|
||||
int rtn= remove (pathname);
|
||||
if (-1 == rtn) {
|
||||
|
@ -311,15 +287,9 @@ int _ez_remove (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_rename (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, rename,
|
||||
const char *oldpath,
|
||||
const char *newpath
|
||||
)
|
||||
const char *newpath)
|
||||
{
|
||||
int rtn= rename (oldpath, newpath);
|
||||
if (-1 == rtn) {
|
||||
|
@ -334,14 +304,8 @@ int _ez_rename (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
DIR* _ez_opendir (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
const char *name
|
||||
)
|
||||
ez_proto (DIR*, opendir,
|
||||
const char *name)
|
||||
{
|
||||
DIR *rtn= opendir (name);
|
||||
if (!rtn) {
|
||||
|
@ -356,14 +320,8 @@ DIR* _ez_opendir (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_closedir (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
DIR *dirp
|
||||
)
|
||||
ez_proto (int, closedir,
|
||||
DIR *dirp)
|
||||
{
|
||||
int rtn= closedir (dirp);
|
||||
if (-1 == rtn) {
|
||||
|
@ -378,14 +336,40 @@ int _ez_closedir (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
struct dirent* _ez_readdir (
|
||||
ez_proto (int, dup2, int oldfd, int newfd)
|
||||
{
|
||||
int rtn= dup2 (oldfd, newfd);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
DIR *dirp
|
||||
)
|
||||
, "dup2() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, execve,
|
||||
const char *filename,
|
||||
char *const argv[],
|
||||
char *const envp[])
|
||||
{
|
||||
int rtn= execve(filename, argv, envp);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "execve() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (struct dirent*, readdir, DIR *dirp)
|
||||
{
|
||||
|
||||
/* Pass on doctored format string and varargs to vfprintf() */
|
||||
|
@ -405,14 +389,7 @@ struct dirent* _ez_readdir (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_close (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int fd
|
||||
)
|
||||
ez_proto (int, close, int fd)
|
||||
{
|
||||
int rtn= close (fd);
|
||||
if (-1 == rtn) {
|
||||
|
@ -427,16 +404,10 @@ int _ez_close (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
ssize_t _ez_write (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (ssize_t, write,
|
||||
int fd,
|
||||
const void *buf,
|
||||
size_t count
|
||||
)
|
||||
size_t count)
|
||||
{
|
||||
ssize_t rtn= write (fd, buf, count);
|
||||
if (-1 == rtn) {
|
||||
|
@ -451,15 +422,9 @@ ssize_t _ez_write (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_stat (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
const char *pathname,
|
||||
struct stat *statbuf
|
||||
)
|
||||
ez_proto (int, stat,
|
||||
const char *pathname,
|
||||
struct stat *statbuf)
|
||||
{
|
||||
int rtn= stat (pathname, statbuf);
|
||||
if (-1 == rtn) {
|
||||
|
@ -474,15 +439,9 @@ int _ez_stat (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_mkdir (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, mkdir,
|
||||
const char *pathname,
|
||||
mode_t mode
|
||||
)
|
||||
mode_t mode)
|
||||
{
|
||||
int rtn= mkdir (pathname, mode);
|
||||
if (-1 == rtn) {
|
||||
|
@ -497,14 +456,8 @@ int _ez_mkdir (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_rmdir (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
const char *pathname
|
||||
)
|
||||
ez_proto (int, rmdir,
|
||||
const char *pathname)
|
||||
{
|
||||
int rtn= rmdir (pathname);
|
||||
if (-1 == rtn) {
|
||||
|
@ -519,14 +472,8 @@ int _ez_rmdir (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_unlink (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
const char *pathname
|
||||
)
|
||||
ez_proto (int, unlink,
|
||||
const char *pathname)
|
||||
{
|
||||
int rtn= unlink (pathname);
|
||||
if (-1 == rtn) {
|
||||
|
@ -541,17 +488,11 @@ int _ez_unlink (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_getaddrinfo(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, getaddrinfo,
|
||||
const char *node,
|
||||
const char *service,
|
||||
const struct addrinfo *hints,
|
||||
struct addrinfo **res
|
||||
)
|
||||
struct addrinfo **res)
|
||||
{
|
||||
errno= 0;
|
||||
int rtn= getaddrinfo (node, service, hints, res);
|
||||
|
@ -583,20 +524,14 @@ int _ez_getaddrinfo(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_getnameinfo(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, getnameinfo,
|
||||
const struct sockaddr *addr,
|
||||
socklen_t addrlen,
|
||||
char *host,
|
||||
socklen_t hostlen,
|
||||
char *serv,
|
||||
socklen_t servlen,
|
||||
int flags
|
||||
)
|
||||
int flags)
|
||||
{
|
||||
errno= 0;
|
||||
int rtn= getnameinfo (addr, addrlen, host, hostlen, serv, servlen, flags);
|
||||
|
@ -622,20 +557,14 @@ int _ez_getnameinfo(
|
|||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "getnameinfo() failed", rtn);
|
||||
, "getnameinfo() failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_flock (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, flock,
|
||||
int fd,
|
||||
int operation
|
||||
)
|
||||
int operation)
|
||||
{
|
||||
errno= 0;
|
||||
int rtn= flock (fd, operation);
|
||||
|
@ -658,16 +587,10 @@ int _ez_flock (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_open(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, open,
|
||||
const char *pathname,
|
||||
int flags,
|
||||
mode_t mode
|
||||
)
|
||||
mode_t mode)
|
||||
{
|
||||
errno= 0;
|
||||
int rtn= open (pathname, flags, mode);
|
||||
|
@ -690,15 +613,9 @@ int _ez_open(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_access(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, access,
|
||||
const char *pathname,
|
||||
int mode
|
||||
)
|
||||
int mode)
|
||||
{
|
||||
errno= 0;
|
||||
int rtn= access (pathname, mode);
|
||||
|
@ -720,16 +637,10 @@ int _ez_access(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
char *_ez_strptime(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (char*, strptime,
|
||||
const char *s,
|
||||
const char *format,
|
||||
struct tm *tm
|
||||
)
|
||||
struct tm *tm)
|
||||
{
|
||||
char *rtn= strptime (s, format, tm);
|
||||
if(rtn) return rtn;
|
||||
|
@ -744,14 +655,7 @@ char *_ez_strptime(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_seteuid(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
uid_t euid
|
||||
)
|
||||
ez_proto (int, seteuid, uid_t euid)
|
||||
{
|
||||
int rtn= seteuid (euid);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -765,14 +669,7 @@ int _ez_seteuid(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_setegid(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gid_t egid
|
||||
)
|
||||
ez_proto (int, setegid, gid_t egid)
|
||||
{
|
||||
int rtn= setegid (egid);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -786,14 +683,7 @@ int _ez_setegid(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
struct group* _ez_getgrnam(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
const char *name
|
||||
)
|
||||
ez_proto (struct group*, getgrnam, const char *name)
|
||||
{
|
||||
errno= 0;
|
||||
struct group *rtn= getgrnam (name);
|
||||
|
@ -821,16 +711,10 @@ struct group* _ez_getgrnam(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_chown(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, chown,
|
||||
const char *pathname,
|
||||
uid_t owner,
|
||||
gid_t group
|
||||
)
|
||||
gid_t group)
|
||||
{
|
||||
int rtn= chown (pathname, owner, group);
|
||||
if(0 == rtn) return rtn;
|
||||
|
@ -844,16 +728,10 @@ int _ez_chown(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fchown(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, fchown,
|
||||
int fd,
|
||||
uid_t owner,
|
||||
gid_t group
|
||||
)
|
||||
gid_t group)
|
||||
{
|
||||
int rtn= fchown (fd, owner, group);
|
||||
if(0 == rtn) return rtn;
|
||||
|
@ -867,15 +745,7 @@ int _ez_fchown(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fchmod(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
int fd,
|
||||
mode_t mode
|
||||
)
|
||||
ez_proto (int, fchmod, int fd, mode_t mode)
|
||||
{
|
||||
int rtn= fchmod (fd, mode);
|
||||
if(0 == rtn) return rtn;
|
||||
|
@ -889,14 +759,7 @@ int _ez_fchmod(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_setuid(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
uid_t uid
|
||||
)
|
||||
ez_proto (int, setuid, uid_t uid)
|
||||
{
|
||||
int rtn= setuid (uid);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -910,14 +773,7 @@ int _ez_setuid(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_setgid(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gid_t gid
|
||||
)
|
||||
ez_proto (int, setgid, gid_t gid)
|
||||
{
|
||||
int rtn= setgid (gid);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -929,3 +785,86 @@ int _ez_setgid(
|
|||
, "setgid(%d) failed", (int)gid);
|
||||
abort();
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, atexit,
|
||||
void(*function)(void))
|
||||
{
|
||||
int rtn= atexit (function);
|
||||
if(0 == rtn) return 0;
|
||||
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "atexit() failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, chdir,
|
||||
const char *path)
|
||||
{
|
||||
int rtn= chdir (path);
|
||||
if(0 == rtn) return 0;
|
||||
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "chdir(\"%s\") failed", path);
|
||||
abort();
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, mkstemp,
|
||||
char *template)
|
||||
{
|
||||
int rtn= mkstemp (template);
|
||||
if(-1 != rtn) return rtn;
|
||||
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "mkstemp(\"%s\") failed", template);
|
||||
abort();
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, mkstemps,
|
||||
char *template,
|
||||
int suffixlen)
|
||||
{
|
||||
int rtn= mkstemps (template, suffixlen);
|
||||
if(-1 != rtn) return rtn;
|
||||
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "mkstemps(\"%s\") failed", template);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************/
|
||||
ez_proto (int, vfprintf,
|
||||
FILE *stream,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
{
|
||||
va_list arglist;
|
||||
va_copy(arglist, ap);
|
||||
int rtn= vfprintf (stream, fmt, arglist);
|
||||
if (0 > rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror
|
||||
#ifdef DEBUG
|
||||
, fileName, lineNo, funcName
|
||||
#endif
|
||||
, "vfprintf() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
|
70
ez_libdb.c
70
ez_libdb.c
|
@ -23,16 +23,10 @@
|
|||
#include "ez_libdb.h"
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_create(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, create,
|
||||
DB **dbp,
|
||||
DB_ENV *dbenv,
|
||||
u_int32_t flags
|
||||
)
|
||||
u_int32_t flags)
|
||||
{
|
||||
int rtn= db_create (dbp, dbenv, flags);
|
||||
|
||||
|
@ -49,20 +43,14 @@ int _ez_db_create(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_open(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, db_open,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
const char *file,
|
||||
const char *database,
|
||||
DBTYPE type,
|
||||
u_int32_t flags,
|
||||
int mode
|
||||
)
|
||||
int mode)
|
||||
{
|
||||
int rtn= db->open(db, txnid, file, database, type, flags, mode);
|
||||
|
||||
|
@ -79,18 +67,12 @@ int _ez_db_open(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_put(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, db_put,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
DBT *key,
|
||||
DBT *data,
|
||||
u_int32_t flags
|
||||
)
|
||||
u_int32_t flags)
|
||||
{
|
||||
int rtn= db->put(db, txnid, key, data, flags);
|
||||
|
||||
|
@ -107,18 +89,12 @@ int _ez_db_put(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_get(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, db_get,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
DBT *key,
|
||||
DBT *data,
|
||||
u_int32_t flags
|
||||
)
|
||||
u_int32_t flags)
|
||||
{
|
||||
int rtn= db->get(db, txnid, key, data, flags);
|
||||
|
||||
|
@ -139,17 +115,11 @@ int _ez_db_get(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_del(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, db_del,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
DBT *key,
|
||||
u_int32_t flags
|
||||
)
|
||||
u_int32_t flags)
|
||||
{
|
||||
int rtn= db->del(db, txnid, key, flags);
|
||||
|
||||
|
@ -166,15 +136,7 @@ int _ez_db_del(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_close(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
DB *db,
|
||||
u_int32_t flags
|
||||
)
|
||||
ez_proto (int, db_close, DB *db, u_int32_t flags)
|
||||
{
|
||||
int rtn= db->close(db, flags);
|
||||
|
||||
|
@ -191,15 +153,7 @@ int _ez_db_close(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_db_fd(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
DB *db,
|
||||
int *fdp
|
||||
)
|
||||
ez_proto (int, db_fd, DB *db, int *fdp)
|
||||
{
|
||||
int rtn= db->fd(db, fdp);
|
||||
|
||||
|
|
156
ez_libdb.h
156
ez_libdb.h
|
@ -20,145 +20,107 @@
|
|||
#define EZ_LIBDB_H
|
||||
|
||||
/* Simplified interface to libanl functions */
|
||||
#define _GNU_SOURCE
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <db.h>
|
||||
|
||||
#include "ez.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_db_create(dbp, dbenv, flags) \
|
||||
_ez_db_create(__FILE__, __LINE__, __FUNCTION__, dbp, dbenv, flags)
|
||||
#else
|
||||
# define ez_db_create(dbp, dbenv, flags) \
|
||||
_ez_db_create(dbp, dbenv, flags)
|
||||
#endif
|
||||
int _ez_db_create(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, create,
|
||||
DB **dbp,
|
||||
DB_ENV *dbenv,
|
||||
u_int32_t flags
|
||||
);
|
||||
|
||||
u_int32_t flags);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_open(db, txnid, file, database, type, flags, mode ) \
|
||||
_ez_db_open(__FILE__, __LINE__, __FUNCTION__, db, txnid, file, database, type, flags, mode)
|
||||
# define ez_db_create(...) \
|
||||
_ez_db_create(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_open(db, txnid, file, database, type, flags, mode ) \
|
||||
_ez_db_open(db, txnid, file, database, type, flags, mode)
|
||||
#endif
|
||||
int _ez_db_open(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_db_create(...) \
|
||||
_ez_db_create(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, db_open,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
const char *file,
|
||||
const char *database,
|
||||
DBTYPE type,
|
||||
u_int32_t flags,
|
||||
int mode
|
||||
);
|
||||
|
||||
int mode);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_put(db, txnid, key, data, flags) \
|
||||
_ez_db_put(__FILE__, __LINE__, __FUNCTION__, db, txnid, key, data, flags)
|
||||
# define ez_db_open(...) \
|
||||
_ez_db_open(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_put(db, txnid, key, data, flags) \
|
||||
_ez_db_put(db, txnid, key, data, flags)
|
||||
#endif
|
||||
int _ez_db_put(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_db_open(...) \
|
||||
_ez_db_open(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, db_put,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
DBT *key,
|
||||
DBT *data,
|
||||
u_int32_t flags
|
||||
);
|
||||
|
||||
u_int32_t flags);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_get(db, txnid, key, data, flags) \
|
||||
_ez_db_get(__FILE__, __LINE__, __FUNCTION__, db, txnid, key, data, flags)
|
||||
# define ez_db_put(...) \
|
||||
_ez_db_put(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_get(db, txnid, key, data, flags) \
|
||||
_ez_db_get(db, txnid, key, data, flags)
|
||||
#endif
|
||||
int _ez_db_get(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_db_put(...) \
|
||||
_ez_db_put(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, db_get,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
DBT *key,
|
||||
DBT *data,
|
||||
u_int32_t flags
|
||||
);
|
||||
|
||||
u_int32_t flags);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_del(db, txnid, key, flags) \
|
||||
_ez_db_del(__FILE__, __LINE__, __FUNCTION__, db, txnid, key, flags)
|
||||
# define ez_db_get(...) \
|
||||
_ez_db_get(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_del(db, txnid, key, flags) \
|
||||
_ez_db_del(db, txnid, key, flags)
|
||||
#endif
|
||||
int _ez_db_del(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_db_get(...) \
|
||||
_ez_db_get(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, db_del,
|
||||
DB *db,
|
||||
DB_TXN *txnid,
|
||||
DBT *key,
|
||||
u_int32_t flags
|
||||
);
|
||||
|
||||
u_int32_t flags);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_close(db, flags) \
|
||||
_ez_db_close(__FILE__, __LINE__, __FUNCTION__, db, flags)
|
||||
# define ez_db_del(...) \
|
||||
_ez_db_del(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_close(db, flags) \
|
||||
_ez_db_close(db, flags)
|
||||
# define ez_db_del(...) \
|
||||
_ez_db_del(__VA_ARGS__)
|
||||
#endif
|
||||
int _ez_db_close(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
DB *db,
|
||||
u_int32_t flags
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_db_fd(db, fdp) \
|
||||
_ez_db_fd(__FILE__, __LINE__, __FUNCTION__, db, fdp)
|
||||
#else
|
||||
# define ez_db_fd(db, fdp) \
|
||||
_ez_db_fd(db, fdp)
|
||||
#endif
|
||||
int _ez_db_fd(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, db_close,
|
||||
DB *db,
|
||||
int *fdp
|
||||
);
|
||||
u_int32_t flags);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_close(...) \
|
||||
_ez_db_close(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_close(...) \
|
||||
_ez_db_close(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, db_fd,
|
||||
DB *db,
|
||||
int *fdp);
|
||||
#ifdef DEBUG
|
||||
# define ez_db_fd(...) \
|
||||
_ez_db_fd(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_db_fd(...) \
|
||||
_ez_db_fd(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -25,14 +25,7 @@
|
|||
#include "util.h"
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pthread_mutex_lock(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_mutex_t *mutex
|
||||
)
|
||||
ez_proto (int, pthread_mutex_lock, pthread_mutex_t *mutex)
|
||||
{
|
||||
int rtn= pthread_mutex_lock (mutex);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -47,14 +40,7 @@ int _ez_pthread_mutex_lock(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pthread_mutex_unlock(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_mutex_t *mutex
|
||||
)
|
||||
ez_proto (int, pthread_mutex_unlock, pthread_mutex_t *mutex)
|
||||
{
|
||||
int rtn= pthread_mutex_unlock (mutex);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -69,17 +55,11 @@ int _ez_pthread_mutex_unlock(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pthread_create(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, pthread_create,
|
||||
pthread_t *thread,
|
||||
const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *),
|
||||
void *arg
|
||||
)
|
||||
void *arg)
|
||||
{
|
||||
int rtn= pthread_create (thread, attr, start_routine, arg);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -94,14 +74,7 @@ int _ez_pthread_create(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pthread_cond_signal(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_cond_t *cond
|
||||
)
|
||||
ez_proto (int, pthread_cond_signal, pthread_cond_t *cond)
|
||||
{
|
||||
int rtn= pthread_cond_signal (cond);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -116,15 +89,9 @@ int _ez_pthread_cond_signal(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pthread_cond_wait(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, pthread_cond_wait,
|
||||
pthread_cond_t *cond,
|
||||
pthread_mutex_t *mutex
|
||||
)
|
||||
pthread_mutex_t *mutex)
|
||||
{
|
||||
int rtn= pthread_cond_wait (cond, mutex);
|
||||
if(0 == rtn) return 0;
|
||||
|
@ -139,15 +106,9 @@ int _ez_pthread_cond_wait(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_pthread_join(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, pthread_join,
|
||||
pthread_t thread,
|
||||
void **retval
|
||||
)
|
||||
void **retval)
|
||||
{
|
||||
int rtn= pthread_join (thread, retval);
|
||||
if(0 == rtn) return 0;
|
||||
|
|
124
ez_libpthread.h
124
ez_libpthread.h
|
@ -20,113 +20,81 @@
|
|||
#define EZ_LIBPTHREAD_H
|
||||
|
||||
/* Simplified interface to libpthread functions */
|
||||
#define _GNU_SOURCE
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
|
||||
#include "ez.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ez_proto (int, pthread_mutex_lock,
|
||||
pthread_mutex_t *mutex);
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_mutex_lock(mutex) \
|
||||
_ez_pthread_mutex_lock(__FILE__, __LINE__, __FUNCTION__, mutex)
|
||||
# define ez_pthread_mutex_lock(...) \
|
||||
_ez_pthread_mutex_lock(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_pthread_mutex_lock(mutex) \
|
||||
_ez_pthread_mutex_lock(mutex)
|
||||
# define ez_pthread_mutex_lock(...) \
|
||||
_ez_pthread_mutex_lock(__VA_ARGS__)
|
||||
#endif
|
||||
int _ez_pthread_mutex_lock(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_mutex_t *mutex
|
||||
);
|
||||
|
||||
ez_proto (int, pthread_mutex_unlock,
|
||||
pthread_mutex_t *mutex);
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_mutex_unlock(mutex) \
|
||||
_ez_pthread_mutex_unlock(__FILE__, __LINE__, __FUNCTION__, mutex)
|
||||
# define ez_pthread_mutex_unlock(...) \
|
||||
_ez_pthread_mutex_unlock(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_pthread_mutex_unlock(mutex) \
|
||||
_ez_pthread_mutex_unlock(mutex)
|
||||
# define ez_pthread_mutex_unlock(...) \
|
||||
_ez_pthread_mutex_unlock(__VA_ARGS__)
|
||||
#endif
|
||||
int _ez_pthread_mutex_unlock(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_mutex_t *mutex
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_create(thread, addr, start_routine, arg) \
|
||||
_ez_pthread_create(__FILE__, __LINE__, __FUNCTION__, thread, addr, start_routine, arg)
|
||||
#else
|
||||
# define ez_pthread_create(thread, addr, start_routine, arg) \
|
||||
_ez_pthread_create(thread, addr, start_routine, arg)
|
||||
#endif
|
||||
int _ez_pthread_create(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, pthread_create,
|
||||
pthread_t *thread,
|
||||
const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *),
|
||||
void *arg
|
||||
);
|
||||
|
||||
void *arg);
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_cond_signal(cond) \
|
||||
_ez_pthread_cond_signal(__FILE__, __LINE__, __FUNCTION__, cond)
|
||||
# define ez_pthread_create(...) \
|
||||
_ez_pthread_create(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_pthread_cond_signal(cond) \
|
||||
_ez_pthread_cond_signal(cond)
|
||||
# define ez_pthread_create(...) \
|
||||
_ez_pthread_create(__VA_ARGS__)
|
||||
#endif
|
||||
int _ez_pthread_cond_signal(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
pthread_cond_t *cond
|
||||
);
|
||||
|
||||
ez_proto (int, pthread_cond_signal,
|
||||
pthread_cond_t *cond);
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_cond_wait(cond, mutex) \
|
||||
_ez_pthread_cond_wait(__FILE__, __LINE__, __FUNCTION__, cond, mutex)
|
||||
# define ez_pthread_cond_signal(...) \
|
||||
_ez_pthread_cond_signal(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_pthread_cond_wait(cond, mutex) \
|
||||
_ez_pthread_cond_wait(cond, mutex)
|
||||
#endif
|
||||
int _ez_pthread_cond_wait(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_pthread_cond_signal(...) \
|
||||
_ez_pthread_cond_signal(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, pthread_cond_wait,
|
||||
pthread_cond_t *cond,
|
||||
pthread_mutex_t *mutex
|
||||
);
|
||||
|
||||
pthread_mutex_t *mutex);
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_join(thread, retval) \
|
||||
_ez_pthread_join(__FILE__, __LINE__, __FUNCTION__, thread, retval)
|
||||
# define ez_pthread_cond_wait(...) \
|
||||
_ez_pthread_cond_wait(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_pthread_join(thread, retval) \
|
||||
_ez_pthread_join(thread, retval)
|
||||
#endif
|
||||
int _ez_pthread_join(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_pthread_cond_wait(...) \
|
||||
_ez_pthread_cond_wait(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, pthread_join,
|
||||
pthread_t thread,
|
||||
void **retval
|
||||
);
|
||||
void **retval);
|
||||
#ifdef DEBUG
|
||||
# define ez_pthread_join(...) \
|
||||
_ez_pthread_join(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_pthread_join(...) \
|
||||
_ez_pthread_join(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
79
ez_libz.c
79
ez_libz.c
|
@ -23,15 +23,9 @@
|
|||
#include "util.h"
|
||||
|
||||
/***************************************************/
|
||||
gzFile _ez_gzopen(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (gzFile, gzopen,
|
||||
const char *path,
|
||||
const char *mode
|
||||
)
|
||||
const char *mode)
|
||||
{
|
||||
gzFile rtn= gzopen(path, mode);
|
||||
if(rtn) return rtn;
|
||||
|
@ -45,14 +39,7 @@ gzFile _ez_gzopen(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_gzclose(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gzFile file
|
||||
)
|
||||
ez_proto (int, gzclose, gzFile file)
|
||||
{
|
||||
int err= gzclose(file);
|
||||
if(Z_OK == err) return Z_OK;
|
||||
|
@ -91,16 +78,10 @@ int _ez_gzclose(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_gzwrite(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, gzwrite,
|
||||
gzFile file,
|
||||
voidpc buf,
|
||||
unsigned len
|
||||
)
|
||||
unsigned len)
|
||||
{
|
||||
int n= gzwrite(file, buf, len);
|
||||
if(n == len) return n;
|
||||
|
@ -124,16 +105,10 @@ int _ez_gzwrite(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_gzread(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (int, gzread,
|
||||
gzFile file,
|
||||
voidp buf,
|
||||
unsigned len
|
||||
)
|
||||
unsigned len)
|
||||
{
|
||||
int n= gzread(file, buf, len);
|
||||
if(-1 != n) return n;
|
||||
|
@ -157,15 +132,7 @@ int _ez_gzread(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_gzflush(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gzFile file,
|
||||
int flush
|
||||
)
|
||||
ez_proto (int, gzflush, gzFile file, int flush)
|
||||
{
|
||||
int err= gzflush(file, flush);
|
||||
if(Z_OK == err) return Z_OK;
|
||||
|
@ -188,16 +155,10 @@ int _ez_gzflush(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
z_off_t _ez_gzseek(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (z_off_t, gzseek,
|
||||
gzFile file,
|
||||
z_off_t offset,
|
||||
int whence
|
||||
)
|
||||
int whence)
|
||||
{
|
||||
z_off_t rtn= gzseek(file, offset, whence);
|
||||
if(-1 != rtn) return rtn;
|
||||
|
@ -221,16 +182,10 @@ z_off_t _ez_gzseek(
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
char* _ez_gzgets (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (char*, gzgets,
|
||||
gzFile file,
|
||||
char *buf,
|
||||
int len
|
||||
)
|
||||
int len)
|
||||
{
|
||||
char *rtn= gzgets(file, buf, len);
|
||||
|
||||
|
@ -259,14 +214,8 @@ char* _ez_gzgets (
|
|||
}
|
||||
|
||||
/***************************************************/
|
||||
z_off_t _ez_gztell(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gzFile file
|
||||
)
|
||||
ez_proto (z_off_t, _ez_gztell,
|
||||
gzFile file)
|
||||
{
|
||||
z_off_t rtn= gztell(file);
|
||||
if(-1 != rtn) return rtn;
|
||||
|
|
166
ez_libz.h
166
ez_libz.h
|
@ -20,150 +20,106 @@
|
|||
#define EZ_GZFILE_H
|
||||
|
||||
/* Simplified interface to libz file functions */
|
||||
#define _GNU_SOURCE
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <zlib.h>
|
||||
|
||||
#include "ez.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ez_gzopen(path, mode) \
|
||||
_ez_gzopen(__FILE__, __LINE__, __FUNCTION__, path, mode)
|
||||
#else
|
||||
# define ez_gzopen(path, mode) \
|
||||
_ez_gzopen(path, mode)
|
||||
#endif
|
||||
gzFile _ez_gzopen(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
ez_proto (gzFile, gzopen,
|
||||
const char *path,
|
||||
const char *mode
|
||||
);
|
||||
|
||||
const char *mode);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzclose(file) \
|
||||
_ez_gzclose(__FILE__, __LINE__, __FUNCTION__, file)
|
||||
# define ez_gzopen(...) \
|
||||
_ez_gzopen(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzclose(file) \
|
||||
_ez_gzclose(file)
|
||||
# define ez_gzopen(...) \
|
||||
_ez_gzopen(__VA_ARGS__)
|
||||
#endif
|
||||
int _ez_gzclose(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gzFile file
|
||||
);
|
||||
|
||||
ez_proto (int, gzclose,
|
||||
gzFile file);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzwrite(file, buf, len) \
|
||||
_ez_gzwrite(__FILE__, __LINE__, __FUNCTION__, file, buf, len)
|
||||
# define ez_gzclose(...) \
|
||||
_ez_gzclose(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzwrite(file, buf, len) \
|
||||
_ez_gzwrite(file, buf, len)
|
||||
#endif
|
||||
int _ez_gzwrite(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_gzclose(...) \
|
||||
_ez_gzclose(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, gzwrite,
|
||||
gzFile file,
|
||||
voidpc buf,
|
||||
unsigned len
|
||||
);
|
||||
|
||||
unsigned len);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzread(file, buf, len) \
|
||||
_ez_gzread(__FILE__, __LINE__, __FUNCTION__, file, buf, len)
|
||||
# define ez_gzwrite(...) \
|
||||
_ez_gzwrite(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzread(file, buf, len) \
|
||||
_ez_gzread(file, buf, len)
|
||||
#endif
|
||||
int _ez_gzread(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_gzwrite(...) \
|
||||
_ez_gzwrite(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, gzread,
|
||||
gzFile file,
|
||||
voidp buf,
|
||||
unsigned len
|
||||
);
|
||||
|
||||
unsigned len);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzflush(file, flush) \
|
||||
_ez_gzflush(__FILE__, __LINE__, __FUNCTION__, file, flush)
|
||||
# define ez_gzread(...) \
|
||||
_ez_gzread(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzflush(file, flush) \
|
||||
_ez_gzflush(file, flush)
|
||||
#endif
|
||||
int _ez_gzflush(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_gzread(...) \
|
||||
_ez_gzread(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (int, gzflush,
|
||||
gzFile file,
|
||||
int flush
|
||||
);
|
||||
|
||||
int flush);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzseek(file, offset, whence) \
|
||||
_ez_gzseek(__FILE__, __LINE__, __FUNCTION__, file, offset, whence)
|
||||
# define ez_gzflush(...) \
|
||||
_ez_gzflush(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzseek(file, offset, whence) \
|
||||
_ez_gzseek(file, offset, whence)
|
||||
#endif
|
||||
z_off_t _ez_gzseek(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_gzflush(...) \
|
||||
_ez_gzflush(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (z_off_t, gzseek,
|
||||
gzFile file,
|
||||
z_off_t offset,
|
||||
int whence
|
||||
);
|
||||
|
||||
int whence);
|
||||
#ifdef DEBUG
|
||||
# define ez_gztell(file) \
|
||||
_ez_gztell(__FILE__, __LINE__, __FUNCTION__, file)
|
||||
# define ez_gzseek(...) \
|
||||
_ez_gzseek(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gztell(file) \
|
||||
_ez_gztell(file)
|
||||
# define ez_gzseek(...) \
|
||||
_ez_gzseek(__VA_ARGS__)
|
||||
#endif
|
||||
z_off_t _ez_gztell(
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
#endif
|
||||
gzFile file
|
||||
);
|
||||
|
||||
ez_proto (z_off_t, _ez_gztell,
|
||||
gzFile file);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzgets(file, buf, len) \
|
||||
_ez_gzgets(__FILE__, __LINE__, __FUNCTION__, file, buf, len)
|
||||
# define ez_gztell(...) \
|
||||
_ez_gztell(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzgets(file, buf, len) \
|
||||
_ez_gzgets(file, buf, len)
|
||||
#endif
|
||||
char* _ez_gzgets (
|
||||
#ifdef DEBUG
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
# define ez_gztell(...) \
|
||||
_ez_gztell(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
ez_proto (char*, gzgets,
|
||||
gzFile file,
|
||||
char *buf,
|
||||
int len
|
||||
);
|
||||
int len);
|
||||
#ifdef DEBUG
|
||||
# define ez_gzgets(...) \
|
||||
_ez_gzgets(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
# define ez_gzgets(...) \
|
||||
_ez_gzgets(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue