* Copyright (c) 1993 Christoph M. Robitschko
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christoph M. Robitschko
* 4. The name of the author may not be used to endorse or promote products
* derived from this software withough specific prior written permission
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Misc. utility functions
* put an environment variable in a separate space
static int ienvalloc
= 0;
varlen
= strlen(var
) + 1; /* VAR= */
plaza
= malloc(varlen
+ strlen(val
) + 1);
return; /* fail miserably */
/* sprintf(plaza, "%s=%s", var, val); */
ienviron
= malloc(4*sizeof(char *));
/* Search ienviron if variable is already defined */
for (ienvcount
= 0, ienv
= ienviron
; *ienv
; ienv
++, ienvcount
++)
if (!strncmp(*ienv
, plaza
, varlen
)) {
/* Not found, create new environ entry */
if (ienvcount
>= ienvalloc
)
if (( ienviron
= realloc (ienviron
, (ienvalloc
+ 4)* sizeof (char *))))
for (ienv
= ienviron
; *ienv
; ienv
++);
* print a message if current debug level > log level
Debug(int level
, const char *format
, ...)
vsyslog(LOG_DEBUG
, format
, args
);
* see if s2 is the beginning of s1, ignoring case
strCcmp(s1
, s2
) /* strncasecmp(s1, s2, strlen(s1)) */
if (toupper(*s1
) != toupper(*s2
))
* allocate memory for a string and copy it.
s
= (char *)malloc(strlen(string
)+1);
* atoi with error handling. errors are signalled with a negative return value
res
= strtol(str
, &s
, 0);