From: short <> Date: Sun, 16 Jan 2000 16:40:01 +0000 (+0000) Subject: Altmost compilable, weak symbol definitions still missing. X-Git-Tag: ver1_0_0~2 X-Git-Url: http://git.jankratochvil.net/?p=vblib.git;a=commitdiff_plain;h=d57add44b5aaae22106f668f2e4194e40a1fb084 Altmost compilable, weak symbol definitions still missing. Commented 'configuration section'. PTHREAD dependency made configurable. --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2a0c8c8 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +CFLAGS=-Wall -Wstrict-prototypes -O2 + +all: vblib.o + +vblib.o: vblib.c vblib.h + $(CC) $(CFLAGS) -o $@ $< + +.PHONY: clean +clean: + $(RM) *.o diff --git a/vblib.c b/vblib.c index 61017c7..9bf8ea1 100644 --- a/vblib.c +++ b/vblib.c @@ -22,21 +22,20 @@ #include #include #include +#ifdef HAVE_PTHREAD #include +#endif -#include "common.h" -#include "dataserv.h" +#include "vblib.h" const int safesigs[]={SIGQUIT,SIGINT,SIGTERM,SIGIOT,SIGALRM,-1}; //SIGCHLD->childsignal anyway char vbnexact; -const char *upsc_sshpath="/usr/bin/ssh"; /* upsetupconn()... */ -const char *upsc_dstport=DS_PORT; void chk(const void *p) { vbsanity(); if (p) return; - FATAL(CRIT,"NULL-check failure, memory exhausted? FATAL: %m"); + VB_FATAL(CRIT,"NULL-check failure, memory exhausted? FATAL: %m"); } #ifndef NDEBUG @@ -48,12 +47,17 @@ static char vbcheckno; #else #define vbcheckno (0) #endif -pthread_mutex_t vbcheckmx=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +#ifdef HAVE_PTHREAD +static pthread_mutex_t vbcheckmx=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static void vbchecklock (void) -{ if (pthread_mutex_lock (&vbcheckmx)) FATAL(CRIT,"Mutex ""lock on vbcheck mx"); } +{ if (pthread_mutex_lock (&vbcheckmx)) VB_FATAL(CRIT,"Mutex ""lock on vbcheck mx"); } static void vbcheckunlock(void) -{ if (pthread_mutex_unlock(&vbcheckmx)) FATAL(CRIT,"Mutex unlock on vbcheck mx"); } +{ if (pthread_mutex_unlock(&vbcheckmx)) VB_FATAL(CRIT,"Mutex unlock on vbcheck mx"); } +#else +#define vbchecklock() +#define vbcheckunlock() +#endif static char vbchecklist(struct varbuf *vb) { @@ -415,8 +419,15 @@ unsigned tot=0; char *d; for (d=s;(d=memchr(d,'\0',s+len-d));) { *d++=' '; tot++; } - if (tot) logmsg((quiet_null?MYLOG_DEBUG:MYLOG_ERR), - "%s() replaced %u '\\0's by ' ' in: %.*s",fname,tot,(int)len,s); + if (!tot) return; +#define ARG "%s() replaced %u '\\0's by ' ' in: %.*s",fname,tot,(int)len,s +#define VB_LOG1(a,b) VB_LOG(a,b) + if (quiet_null) + VB_LOG1(DEBUG,ARG); + else + VB_LOG1(ERR,ARG); +#undef VB_LOG1 +#undef ARG } char *vbgetline(struct varbuf *vb,char term) @@ -507,7 +518,7 @@ void vbpstrputstring(struct varbuf *vb,const char *s) { size_t len=strlen(s); if (len>PSTR_MAX) { - LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); + VB_LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); len=PSTR_MAX; dbg("vbpstrputstring-longer than MAX: \"%s\"\n",s); } @@ -522,7 +533,7 @@ size_t size,was; else if ((size=vbsize(vbs,len))PSTR_MAX) { - LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); + VB_LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); len=PSTR_MAX; vbdebug(vbs,"vbpstrputstring-longer than MAX"); } @@ -542,7 +553,7 @@ int i; i=vsnprintf(buf,sizeof(buf),fmt,ap); va_end(ap); if (i==-1) { - LOG(CRIT,"Buffer overflow (max=%u) during PSTR printf",PSTR_MAX); + VB_LOG(CRIT,"Buffer overflow (max=%u) during PSTR printf",PSTR_MAX); i=PSTR_MAX; } assert(i>=0 && i<=PSTR_MAX && !buf[i]); @@ -567,7 +578,7 @@ size_t r; chgd++; } if (chgd) - LOG(CRIT,"'\\0's found (%u total) in read PSTR \"%s\", changed to '?'",chgd,buf); + VB_LOG(CRIT,"'\\0's found (%u total) in read PSTR \"%s\", changed to '?'",chgd,buf); return(buf); } @@ -723,7 +734,7 @@ char buf[LOGF_FGETS_BUF],*s; if (!fgets(buf,sizeof(buf),f)) { dbg("vbgetlinef: fgets=NULL\n"); if (feof(f)) return; - FATAL(ERR,"linereading fail: %m"); + VB_FATAL(ERR,"linereading fail: %m"); } dbg("vbgetlinef: fgets: %s\n",buf); if ((s=strchr(buf,'\n'))) break; @@ -792,8 +803,10 @@ static void chatfn_help(void); static const struct chat_cmdtab chat_cmdint[]={ {"help" ,0,chatfn_help ,"This help"}, +#if 0 {"quit" ,0,chatfn_quit ,"Close connection"}, {"exit" ,0,chatfn_quit ,"Close connection"}, +#endif }; static void chatfn_help(void) @@ -856,7 +869,7 @@ const struct chat_cmdtab *cmd,*cmdt; vbprintf(chat_vbout,"205 %d parameter%s found, %d expected!\n",chat_cmdpar,(chat_cmdpar==1?"":"s"),cmd->npars); else { vbprintf(chat_vbout,"001 Running command: %s\n",cmds); - LOG(DEBUG,"%s is executing user command \"%s\"",who,cmds); + VB_LOG(DEBUG,"%s is executing user command \"%s\"",who,cmds); (*cmd->fnc)(); } } diff --git a/vblib.h b/vblib.h index 8ee18bc..0b3e93c 100644 --- a/vblib.h +++ b/vblib.h @@ -14,19 +14,71 @@ * Configuration section follows */ +/* + * PSTR_16BIT: whether PSTR strings should be preceded + * by 16-bit or 8-bit length (thus also limiting the maximum + * allowed length of PSTR string) + */ //#define PSTR_16BIT + +/* + * INLINE_PUTGETCHAR: inline vb{put,get}char() + */ #define INLINE_PUTGETCHAR + +/* + * FATALSIG_INSANE: if defined, no vbcheck()s are done after some fatal + * signal has been caught as the data structures may be corrupted + * already thereafter + */ //#define FATALSIG_INSANE +/* + * HAVE_PTHREAD: vbcheck() serialization between threds + * Please note that VB library in general is NOT multithreading safe. + */ +//#define HAVE_PTHREAD + +/* + * VB_DEFSIZE: Default size of buffer of "vb" object. Large sizes may + * slow down vbcopy() significantly. + */ #define VB_DEFSIZE 256 //>=min of n in vsnprintf() + +/* + * LOGF_FGETS_BUF: Buffer size for vbgetlinef(), doesn't hard limit anything, + * it has only performance impact. + */ +#define LOGF_FGETS_BUF VB_DEFSIZE + +/* + * VB_MAXSIZE: Maximum size of one "vbn" segment to prevent circular + * use of "vb" to eat up the whole memory. It doesn't limit the maximum + * data storage of "vb" object in no way, it has only performance impact. + */ #define VB_MAXSIZE 128*1024 //recommended limit, not hard (probably) +/* + * CHAT_CMD_MAXPARS: Size of chat_cmdpars[] array, maximum # of parameters + * a user command can have during chat_proccmd() parse. + */ #define CHAT_CMD_MAXPARS 10 /* * Configuration section ends ****************************/ +#ifndef VB_LOG +#define VB_LOG(lev,msg...) fprintf(stderr,VB_LOG_##lev ##msg) +#endif +#ifndef VB_FATAL +#define VB_FATAL(lev,msg...) do { VB_LOG(lev, ##msg); exit(EXIT_FAILURE); } while (0) +#endif + +#define VB_LOG_DEBUG "VB_Debug: " +#define VB_LOG_ERR "VB_Error: " +#define VB_LOG_CRIT "VB_Critical: " + #define strncpydst(d,s) strncpy(d,s,sizeof(d)) #ifdef NDEBUG #undef DEBUG