mirror of
https://git.openafs.org/openafs.git
synced 2025-01-19 15:30:14 +00:00
Import of code from heimdal
This commit updates the code imported from heimdal to a3afa695ee3eb1ff5ad8de3e80c20d5049fce934 (switch-from-svn-to-git-1619-ga3afa69) Change-Id: I57e56bbad5811d47194459618ffc6e361f01a876 Reviewed-on: http://gerrit.openafs.org/3190 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@dementia.org> Tested-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
parent
88e2a2f266
commit
0a87f5852a
80
src/external/heimdal/roken/daemon.c
vendored
Normal file
80
src/external/heimdal/roken/daemon.c
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 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. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_PATHS_H
|
||||
#include <paths.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
daemon(int nochdir, int noclose)
|
||||
{
|
||||
int fd;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
return (-1);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
if (setsid() == -1)
|
||||
return (-1);
|
||||
|
||||
if (!nochdir)
|
||||
chdir("/");
|
||||
|
||||
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
if (fd > 2)
|
||||
close (fd);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* HAVE_DAEMON */
|
53
src/external/heimdal/roken/ecalloc.c
vendored
Normal file
53
src/external/heimdal/roken/ecalloc.c
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like calloc but never fails.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
ecalloc (size_t number, size_t size)
|
||||
{
|
||||
void *tmp = calloc (number, size);
|
||||
|
||||
if (tmp == NULL && number * size != 0)
|
||||
errx (1, "calloc %lu failed", (unsigned long)number * size);
|
||||
return tmp;
|
||||
}
|
53
src/external/heimdal/roken/emalloc.c
vendored
Normal file
53
src/external/heimdal/roken/emalloc.c
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like malloc but never fails.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
emalloc (size_t sz)
|
||||
{
|
||||
void *tmp = malloc (sz);
|
||||
|
||||
if (tmp == NULL && sz != 0)
|
||||
errx (1, "malloc %lu failed", (unsigned long)sz);
|
||||
return tmp;
|
||||
}
|
53
src/external/heimdal/roken/erealloc.c
vendored
Normal file
53
src/external/heimdal/roken/erealloc.c
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like realloc but never fails.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
erealloc (void *ptr, size_t sz)
|
||||
{
|
||||
void *tmp = realloc (ptr, sz);
|
||||
|
||||
if (tmp == NULL && sz != 0)
|
||||
errx (1, "realloc %lu failed", (unsigned long)sz);
|
||||
return tmp;
|
||||
}
|
124
src/external/heimdal/roken/getopt.c
vendored
Normal file
124
src/external/heimdal/roken/getopt.c
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 1987, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 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. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getopt.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#ifndef __STDC__
|
||||
#define const
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* get option letter from argument vector
|
||||
*/
|
||||
int opterr = 1, /* if error message should be printed */
|
||||
optind = 1, /* index into parent argv vector */
|
||||
optopt, /* character checked for validity */
|
||||
optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG (int)':'
|
||||
#define EMSG ""
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getopt(nargc, nargv, ostr)
|
||||
int nargc;
|
||||
char * const *nargv;
|
||||
const char *ostr;
|
||||
{
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
char *p;
|
||||
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return(-1);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return(-1);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int)*place++) == (int)':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1 (EOF).
|
||||
*/
|
||||
if (optopt == (int)'-')
|
||||
return(-1);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr && *ostr != ':') {
|
||||
if (!(p = strrchr(*nargv, '/')))
|
||||
p = *nargv;
|
||||
else
|
||||
++p;
|
||||
fprintf(stderr, "%s: illegal option -- %c\n",
|
||||
p, optopt);
|
||||
}
|
||||
return(BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
}
|
||||
else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (!(p = strrchr(*nargv, '/')))
|
||||
p = *nargv;
|
||||
else
|
||||
++p;
|
||||
if (*ostr == ':')
|
||||
return(BADARG);
|
||||
if (opterr)
|
||||
fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
p, optopt);
|
||||
return(BADCH);
|
||||
}
|
||||
else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
return(optopt); /* dump back option letter */
|
||||
}
|
57
src/external/heimdal/roken/hex.h
vendored
Normal file
57
src/external/heimdal/roken/hex.h
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2005 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef _rk_HEX_H_
|
||||
#define _rk_HEX_H_ 1
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define hex_encode rk_hex_encode
|
||||
#define hex_decode rk_hex_decode
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_encode(const void *, size_t, char **);
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_decode(const char *, void *, size_t);
|
||||
|
||||
#endif /* _rk_HEX_H_ */
|
54
src/external/heimdal/roken/localtime_r.c
vendored
Normal file
54
src/external/heimdal/roken/localtime_r.c
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "roken.h"
|
||||
|
||||
#ifndef HAVE_LOCALTIME_R
|
||||
|
||||
ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
|
||||
localtime_r(const time_t *timer, struct tm *result)
|
||||
{
|
||||
struct tm *tm;
|
||||
|
||||
tm = localtime((time_t *)timer);
|
||||
if (tm == NULL)
|
||||
return NULL;
|
||||
*result = *tm;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
491
src/external/heimdal/roken/roken-common.h
vendored
Normal file
491
src/external/heimdal/roken/roken-common.h
vendored
Normal file
@ -0,0 +1,491 @@
|
||||
/*
|
||||
* Copyright (c) 1995 - 2005 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef __ROKEN_COMMON_H__
|
||||
#define __ROKEN_COMMON_H__
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define ROKEN_CPP_START extern "C" {
|
||||
#define ROKEN_CPP_END }
|
||||
#else
|
||||
#define ROKEN_CPP_START
|
||||
#define ROKEN_CPP_END
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_LOOPBACK
|
||||
#define INADDR_LOOPBACK 0x7f000001
|
||||
#endif
|
||||
|
||||
#ifndef SOMAXCONN
|
||||
#define SOMAXCONN 5
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a)<(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef LOG_DAEMON
|
||||
#define openlog(id,option,facility) openlog((id),(option))
|
||||
#define LOG_DAEMON 0
|
||||
#endif
|
||||
#ifndef LOG_ODELAY
|
||||
#define LOG_ODELAY 0
|
||||
#endif
|
||||
#ifndef LOG_NDELAY
|
||||
#define LOG_NDELAY 0x08
|
||||
#endif
|
||||
#ifndef LOG_CONS
|
||||
#define LOG_CONS 0
|
||||
#endif
|
||||
#ifndef LOG_AUTH
|
||||
#define LOG_AUTH 0
|
||||
#endif
|
||||
#ifndef LOG_AUTHPRIV
|
||||
#define LOG_AUTHPRIV LOG_AUTH
|
||||
#endif
|
||||
|
||||
#ifndef F_OK
|
||||
#define F_OK 0
|
||||
#endif
|
||||
|
||||
#ifndef O_ACCMODE
|
||||
#define O_ACCMODE 003
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#ifndef _PATH_DEV
|
||||
#define _PATH_DEV "/dev/"
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_DEVNULL
|
||||
#define _PATH_DEVNULL "/dev/null"
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_HEQUIV
|
||||
#define _PATH_HEQUIV "/etc/hosts.equiv"
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_VARRUN
|
||||
#define _PATH_VARRUN "/var/run/"
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_BSHELL
|
||||
#define _PATH_BSHELL "/bin/sh"
|
||||
#endif
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#define MAXPATHLEN (1024+4)
|
||||
#endif
|
||||
|
||||
#endif /* !_WIN32 */
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX MAX_PATH
|
||||
#endif
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
#define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
#ifndef SIG_ERR
|
||||
#define SIG_ERR ((RETSIGTYPE (*)(int))-1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* error code for getipnodeby{name,addr}
|
||||
*/
|
||||
|
||||
#ifndef HOST_NOT_FOUND
|
||||
#define HOST_NOT_FOUND 1
|
||||
#endif
|
||||
|
||||
#ifndef TRY_AGAIN
|
||||
#define TRY_AGAIN 2
|
||||
#endif
|
||||
|
||||
#ifndef NO_RECOVERY
|
||||
#define NO_RECOVERY 3
|
||||
#endif
|
||||
|
||||
#ifndef NO_DATA
|
||||
#define NO_DATA 4
|
||||
#endif
|
||||
|
||||
#ifndef NO_ADDRESS
|
||||
#define NO_ADDRESS NO_DATA
|
||||
#endif
|
||||
|
||||
/*
|
||||
* error code for getaddrinfo
|
||||
*/
|
||||
|
||||
#ifndef EAI_NOERROR
|
||||
#define EAI_NOERROR 0 /* no error */
|
||||
#endif
|
||||
|
||||
#ifndef EAI_NONAME
|
||||
|
||||
#define EAI_ADDRFAMILY 1 /* address family for nodename not supported */
|
||||
#define EAI_AGAIN 2 /* temporary failure in name resolution */
|
||||
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
|
||||
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
|
||||
#define EAI_FAMILY 5 /* ai_family not supported */
|
||||
#define EAI_MEMORY 6 /* memory allocation failure */
|
||||
#define EAI_NODATA 7 /* no address associated with nodename */
|
||||
#define EAI_NONAME 8 /* nodename nor servname provided, or not known */
|
||||
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
|
||||
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
|
||||
#define EAI_SYSTEM 11 /* system error returned in errno */
|
||||
|
||||
#endif /* EAI_NONAME */
|
||||
|
||||
/* flags for getaddrinfo() */
|
||||
|
||||
#ifndef AI_PASSIVE
|
||||
#define AI_PASSIVE 0x01
|
||||
#define AI_CANONNAME 0x02
|
||||
#endif /* AI_PASSIVE */
|
||||
|
||||
#ifndef AI_NUMERICHOST
|
||||
#define AI_NUMERICHOST 0x04
|
||||
#endif
|
||||
|
||||
/* flags for getnameinfo() */
|
||||
|
||||
#ifndef NI_DGRAM
|
||||
#define NI_DGRAM 0x01
|
||||
#define NI_NAMEREQD 0x02
|
||||
#define NI_NOFQDN 0x04
|
||||
#define NI_NUMERICHOST 0x08
|
||||
#define NI_NUMERICSERV 0x10
|
||||
#endif
|
||||
|
||||
/*
|
||||
* constants for getnameinfo
|
||||
*/
|
||||
|
||||
#ifndef NI_MAXHOST
|
||||
#define NI_MAXHOST 1025
|
||||
#define NI_MAXSERV 32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* constants for inet_ntop
|
||||
*/
|
||||
|
||||
#ifndef INET_ADDRSTRLEN
|
||||
#define INET_ADDRSTRLEN 16
|
||||
#endif
|
||||
|
||||
#ifndef INET6_ADDRSTRLEN
|
||||
#define INET6_ADDRSTRLEN 46
|
||||
#endif
|
||||
|
||||
/*
|
||||
* for shutdown(2)
|
||||
*/
|
||||
|
||||
#ifndef SHUT_RD
|
||||
#define SHUT_RD 0
|
||||
#endif
|
||||
|
||||
#ifndef SHUT_WR
|
||||
#define SHUT_WR 1
|
||||
#endif
|
||||
|
||||
#ifndef SHUT_RDWR
|
||||
#define SHUT_RDWR 2
|
||||
#endif
|
||||
|
||||
#ifndef HAVE___ATTRIBUTE__
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
ROKEN_CPP_START
|
||||
|
||||
#ifndef IRIX4 /* fix for compiler bug */
|
||||
#ifndef _WIN32
|
||||
#ifdef RETSIGTYPE
|
||||
typedef RETSIGTYPE (*SigAction)(int);
|
||||
SigAction signal(int iSig, SigAction pAction); /* BSD compatible */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SE_E_UNSPECIFIED (-1)
|
||||
#define SE_E_FORKFAILED (-2)
|
||||
#define SE_E_WAITPIDFAILED (-3)
|
||||
#define SE_E_EXECTIMEOUT (-4)
|
||||
#define SE_E_NOEXEC 126
|
||||
#define SE_E_NOTFOUND 127
|
||||
|
||||
#define SE_PROCSTATUS(st) (((st) >= 0 && (st) < 126)? st: -1)
|
||||
#define SE_PROCSIGNAL(st) (((st) >= 128)? (st) - 128: -1)
|
||||
#define SE_IS_ERROR(st) ((st) < 0 || (st) >= 126)
|
||||
|
||||
|
||||
#define simple_execve rk_simple_execve
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
simple_execve(const char*, char*const[], char*const[]);
|
||||
|
||||
#define simple_execve_timed rk_simple_execve_timed
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
simple_execve_timed(const char *, char *const[],
|
||||
char *const [], time_t (*)(void *),
|
||||
void *, time_t);
|
||||
|
||||
#define simple_execvp rk_simple_execvp
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
simple_execvp(const char*, char *const[]);
|
||||
|
||||
#define simple_execvp_timed rk_simple_execvp_timed
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
simple_execvp_timed(const char *, char *const[],
|
||||
time_t (*)(void *), void *, time_t);
|
||||
|
||||
#define simple_execlp rk_simple_execlp
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
simple_execlp(const char*, ...);
|
||||
|
||||
#define simple_execle rk_simple_execle
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
simple_execle(const char*, ...);
|
||||
|
||||
#define wait_for_process rk_wait_for_process
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
wait_for_process(pid_t);
|
||||
|
||||
#define wait_for_process_timed rk_wait_for_process_timed
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
wait_for_process_timed(pid_t, time_t (*)(void *),
|
||||
void *, time_t);
|
||||
|
||||
#define pipe_execv rk_pipe_execv
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
pipe_execv(FILE**, FILE**, FILE**, const char*, ...);
|
||||
|
||||
#define print_version rk_print_version
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_version(const char *);
|
||||
|
||||
#define eread rk_eread
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
eread (int fd, void *buf, size_t nbytes);
|
||||
|
||||
#define ewrite rk_ewrite
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
ewrite (int fd, const void *buf, size_t nbytes);
|
||||
|
||||
struct hostent;
|
||||
|
||||
#define hostent_find_fqdn rk_hostent_find_fqdn
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
hostent_find_fqdn (const struct hostent *);
|
||||
|
||||
#define esetenv rk_esetenv
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
esetenv(const char *, const char *, int);
|
||||
|
||||
#define socket_set_address_and_port rk_socket_set_address_and_port
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_address_and_port (struct sockaddr *, const void *, int);
|
||||
|
||||
#define socket_addr_size rk_socket_addr_size
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
socket_addr_size (const struct sockaddr *);
|
||||
|
||||
#define socket_set_any rk_socket_set_any
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_any (struct sockaddr *, int);
|
||||
|
||||
#define socket_sockaddr_size rk_socket_sockaddr_size
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
socket_sockaddr_size (const struct sockaddr *);
|
||||
|
||||
#define socket_get_address rk_socket_get_address
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
socket_get_address (const struct sockaddr *);
|
||||
|
||||
#define socket_get_port rk_socket_get_port
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
socket_get_port (const struct sockaddr *);
|
||||
|
||||
#define socket_set_port rk_socket_set_port
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_port (struct sockaddr *, int);
|
||||
|
||||
#define socket_set_portrange rk_socket_set_portrange
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_portrange (rk_socket_t, int, int);
|
||||
|
||||
#define socket_set_debug rk_socket_set_debug
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_debug (rk_socket_t);
|
||||
|
||||
#define socket_set_tos rk_socket_set_tos
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_tos (rk_socket_t, int);
|
||||
|
||||
#define socket_set_reuseaddr rk_socket_set_reuseaddr
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_reuseaddr (rk_socket_t, int);
|
||||
|
||||
#define socket_set_ipv6only rk_socket_set_ipv6only
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_ipv6only (rk_socket_t, int);
|
||||
|
||||
#define socket_to_fd rk_socket_to_fd
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
socket_to_fd(rk_socket_t, int);
|
||||
|
||||
#define vstrcollect rk_vstrcollect
|
||||
ROKEN_LIB_FUNCTION char ** ROKEN_LIB_CALL
|
||||
vstrcollect(va_list *ap);
|
||||
|
||||
#define strcollect rk_strcollect
|
||||
ROKEN_LIB_FUNCTION char ** ROKEN_LIB_CALL
|
||||
strcollect(char *first, ...);
|
||||
|
||||
#define timevalfix rk_timevalfix
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
timevalfix(struct timeval *t1);
|
||||
|
||||
#define timevaladd rk_timevaladd
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
timevaladd(struct timeval *t1, const struct timeval *t2);
|
||||
|
||||
#define timevalsub rk_timevalsub
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
timevalsub(struct timeval *t1, const struct timeval *t2);
|
||||
|
||||
#define pid_file_write rk_pid_file_write
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
pid_file_write (const char *progname);
|
||||
|
||||
#define pid_file_delete rk_pid_file_delete
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
pid_file_delete (char **);
|
||||
|
||||
#define read_environment rk_read_environment
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
read_environment(const char *file, char ***env);
|
||||
|
||||
#define free_environment rk_free_environment
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
free_environment(char **);
|
||||
|
||||
#define warnerr rk_warnerr
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_warnerr(int doerrno, const char *fmt, va_list ap)
|
||||
__attribute__ ((format (printf, 2, 0)));
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
rk_realloc(void *, size_t);
|
||||
|
||||
struct rk_strpool;
|
||||
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
rk_strpoolcollect(struct rk_strpool *);
|
||||
|
||||
ROKEN_LIB_FUNCTION struct rk_strpool * ROKEN_LIB_CALL
|
||||
rk_strpoolprintf(struct rk_strpool *, const char *, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_strpoolfree(struct rk_strpool *);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_dumpdata (const char *, const void *, size_t);
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_undumpdata (const char *, void **, size_t *);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_xfree (void *);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_cloexec(int);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_cloexec_file(FILE *);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_cloexec_dir(DIR *);
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
ct_memcmp(const void *, const void *, size_t);
|
||||
|
||||
ROKEN_CPP_END
|
||||
|
||||
#endif /* __ROKEN_COMMON_H__ */
|
1085
src/external/heimdal/roken/roken.h.in
vendored
Normal file
1085
src/external/heimdal/roken/roken.h.in
vendored
Normal file
File diff suppressed because it is too large
Load Diff
696
src/external/heimdal/roken/snprintf.c
vendored
Normal file
696
src/external/heimdal/roken/snprintf.c
vendored
Normal file
@ -0,0 +1,696 @@
|
||||
/*
|
||||
* Copyright (c) 1995-2003 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "roken.h"
|
||||
#include <assert.h>
|
||||
|
||||
enum format_flags {
|
||||
minus_flag = 1,
|
||||
plus_flag = 2,
|
||||
space_flag = 4,
|
||||
alternate_flag = 8,
|
||||
zero_flag = 16
|
||||
};
|
||||
|
||||
/*
|
||||
* Common state
|
||||
*/
|
||||
|
||||
struct snprintf_state {
|
||||
unsigned char *str;
|
||||
unsigned char *s;
|
||||
unsigned char *theend;
|
||||
size_t sz;
|
||||
size_t max_sz;
|
||||
void (*append_char)(struct snprintf_state *, unsigned char);
|
||||
/* XXX - methods */
|
||||
};
|
||||
|
||||
#if !defined(HAVE_VSNPRINTF) || defined(TEST_SNPRINTF)
|
||||
static int
|
||||
sn_reserve (struct snprintf_state *state, size_t n)
|
||||
{
|
||||
return state->s + n > state->theend;
|
||||
}
|
||||
|
||||
static void
|
||||
sn_append_char (struct snprintf_state *state, unsigned char c)
|
||||
{
|
||||
if (!sn_reserve (state, 1))
|
||||
*state->s++ = c;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
as_reserve (struct snprintf_state *state, size_t n)
|
||||
{
|
||||
if (state->s + n > state->theend) {
|
||||
int off = state->s - state->str;
|
||||
unsigned char *tmp;
|
||||
|
||||
if (state->max_sz && state->sz >= state->max_sz)
|
||||
return 1;
|
||||
|
||||
state->sz = max(state->sz * 2, state->sz + n);
|
||||
if (state->max_sz)
|
||||
state->sz = min(state->sz, state->max_sz);
|
||||
tmp = realloc (state->str, state->sz);
|
||||
if (tmp == NULL)
|
||||
return 1;
|
||||
state->str = tmp;
|
||||
state->s = state->str + off;
|
||||
state->theend = state->str + state->sz - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
as_append_char (struct snprintf_state *state, unsigned char c)
|
||||
{
|
||||
if(!as_reserve (state, 1))
|
||||
*state->s++ = c;
|
||||
}
|
||||
|
||||
/* longest integer types */
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
typedef unsigned long long u_longest;
|
||||
typedef long long longest;
|
||||
#else
|
||||
typedef unsigned long u_longest;
|
||||
typedef long longest;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static size_t
|
||||
pad(struct snprintf_state *state, int width, char c)
|
||||
{
|
||||
size_t len = 0;
|
||||
while(width-- > 0){
|
||||
(*state->append_char)(state, c);
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/* return true if we should use alternatve hex form */
|
||||
static int
|
||||
use_alternative (int flags, u_longest num, unsigned base)
|
||||
{
|
||||
return (flags & alternate_flag) && base == 16 && num != 0;
|
||||
}
|
||||
|
||||
static int
|
||||
append_number(struct snprintf_state *state,
|
||||
u_longest num, unsigned base, const char *rep,
|
||||
int width, int prec, int flags, int minusp)
|
||||
{
|
||||
int len = 0;
|
||||
u_longest n = num;
|
||||
char nstr[64]; /* enough for <192 bit octal integers */
|
||||
int nstart, nlen;
|
||||
char signchar;
|
||||
|
||||
/* given precision, ignore zero flag */
|
||||
if(prec != -1)
|
||||
flags &= ~zero_flag;
|
||||
else
|
||||
prec = 1;
|
||||
|
||||
/* format number as string */
|
||||
nstart = sizeof(nstr);
|
||||
nlen = 0;
|
||||
nstr[--nstart] = '\0';
|
||||
do {
|
||||
assert(nstart > 0);
|
||||
nstr[--nstart] = rep[n % base];
|
||||
++nlen;
|
||||
n /= base;
|
||||
} while(n);
|
||||
|
||||
/* zero value with zero precision should produce no digits */
|
||||
if(prec == 0 && num == 0) {
|
||||
nlen--;
|
||||
nstart++;
|
||||
}
|
||||
|
||||
/* figure out what char to use for sign */
|
||||
if(minusp)
|
||||
signchar = '-';
|
||||
else if((flags & plus_flag))
|
||||
signchar = '+';
|
||||
else if((flags & space_flag))
|
||||
signchar = ' ';
|
||||
else
|
||||
signchar = '\0';
|
||||
|
||||
if((flags & alternate_flag) && base == 8) {
|
||||
/* if necessary, increase the precision to
|
||||
make first digit a zero */
|
||||
|
||||
/* XXX C99 claims (regarding # and %o) that "if the value and
|
||||
precision are both 0, a single 0 is printed", but there is
|
||||
no such wording for %x. This would mean that %#.o would
|
||||
output "0", but %#.x "". This does not make sense, and is
|
||||
also not what other printf implementations are doing. */
|
||||
|
||||
if(prec <= nlen && nstr[nstart] != '0' && nstr[nstart] != '\0')
|
||||
prec = nlen + 1;
|
||||
}
|
||||
|
||||
/* possible formats:
|
||||
pad | sign | alt | zero | digits
|
||||
sign | alt | zero | digits | pad minus_flag
|
||||
sign | alt | zero | digits zero_flag */
|
||||
|
||||
/* if not right justifying or padding with zeros, we need to
|
||||
compute the length of the rest of the string, and then pad with
|
||||
spaces */
|
||||
if(!(flags & (minus_flag | zero_flag))) {
|
||||
if(prec > nlen)
|
||||
width -= prec;
|
||||
else
|
||||
width -= nlen;
|
||||
|
||||
if(use_alternative(flags, num, base))
|
||||
width -= 2;
|
||||
|
||||
if(signchar != '\0')
|
||||
width--;
|
||||
|
||||
/* pad to width */
|
||||
len += pad(state, width, ' ');
|
||||
}
|
||||
if(signchar != '\0') {
|
||||
(*state->append_char)(state, signchar);
|
||||
++len;
|
||||
}
|
||||
if(use_alternative(flags, num, base)) {
|
||||
(*state->append_char)(state, '0');
|
||||
(*state->append_char)(state, rep[10] + 23); /* XXX */
|
||||
len += 2;
|
||||
}
|
||||
if(flags & zero_flag) {
|
||||
/* pad to width with zeros */
|
||||
if(prec - nlen > width - len - nlen)
|
||||
len += pad(state, prec - nlen, '0');
|
||||
else
|
||||
len += pad(state, width - len - nlen, '0');
|
||||
} else
|
||||
/* pad to prec with zeros */
|
||||
len += pad(state, prec - nlen, '0');
|
||||
|
||||
while(nstr[nstart] != '\0') {
|
||||
(*state->append_char)(state, nstr[nstart++]);
|
||||
++len;
|
||||
}
|
||||
|
||||
if(flags & minus_flag)
|
||||
len += pad(state, width - len, ' ');
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
* return length
|
||||
*/
|
||||
|
||||
static size_t
|
||||
append_string (struct snprintf_state *state,
|
||||
const unsigned char *arg,
|
||||
int width,
|
||||
int prec,
|
||||
int flags)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
if(arg == NULL)
|
||||
arg = (const unsigned char*)"(null)";
|
||||
|
||||
if(prec != -1)
|
||||
width -= prec;
|
||||
else
|
||||
width -= strlen((const char *)arg);
|
||||
if(!(flags & minus_flag))
|
||||
len += pad(state, width, ' ');
|
||||
|
||||
if (prec != -1) {
|
||||
while (*arg && prec--) {
|
||||
(*state->append_char) (state, *arg++);
|
||||
++len;
|
||||
}
|
||||
} else {
|
||||
while (*arg) {
|
||||
(*state->append_char) (state, *arg++);
|
||||
++len;
|
||||
}
|
||||
}
|
||||
if(flags & minus_flag)
|
||||
len += pad(state, width, ' ');
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
append_char(struct snprintf_state *state,
|
||||
unsigned char arg,
|
||||
int width,
|
||||
int flags)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
while(!(flags & minus_flag) && --width > 0) {
|
||||
(*state->append_char) (state, ' ') ;
|
||||
++len;
|
||||
}
|
||||
(*state->append_char) (state, arg);
|
||||
++len;
|
||||
while((flags & minus_flag) && --width > 0) {
|
||||
(*state->append_char) (state, ' ');
|
||||
++len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This can't be made into a function...
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
|
||||
#define PARSE_INT_FORMAT(res, arg, unsig) \
|
||||
if (long_long_flag) \
|
||||
res = (unsig long long)va_arg(arg, unsig long long); \
|
||||
else if (long_flag) \
|
||||
res = (unsig long)va_arg(arg, unsig long); \
|
||||
else if (size_t_flag) \
|
||||
res = (unsig long)va_arg(arg, size_t); \
|
||||
else if (short_flag) \
|
||||
res = (unsig short)va_arg(arg, unsig int); \
|
||||
else \
|
||||
res = (unsig int)va_arg(arg, unsig int)
|
||||
|
||||
#else
|
||||
|
||||
#define PARSE_INT_FORMAT(res, arg, unsig) \
|
||||
if (long_flag) \
|
||||
res = (unsig long)va_arg(arg, unsig long); \
|
||||
else if (size_t_flag) \
|
||||
res = (unsig long)va_arg(arg, size_t); \
|
||||
else if (short_flag) \
|
||||
res = (unsig short)va_arg(arg, unsig int); \
|
||||
else \
|
||||
res = (unsig int)va_arg(arg, unsig int)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* zyxprintf - return length, as snprintf
|
||||
*/
|
||||
|
||||
static size_t
|
||||
xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap)
|
||||
{
|
||||
const unsigned char *format = (const unsigned char *)char_format;
|
||||
unsigned char c;
|
||||
size_t len = 0;
|
||||
|
||||
while((c = *format++)) {
|
||||
if (c == '%') {
|
||||
int flags = 0;
|
||||
int width = 0;
|
||||
int prec = -1;
|
||||
int size_t_flag = 0;
|
||||
int long_long_flag = 0;
|
||||
int long_flag = 0;
|
||||
int short_flag = 0;
|
||||
|
||||
/* flags */
|
||||
while((c = *format++)){
|
||||
if(c == '-')
|
||||
flags |= minus_flag;
|
||||
else if(c == '+')
|
||||
flags |= plus_flag;
|
||||
else if(c == ' ')
|
||||
flags |= space_flag;
|
||||
else if(c == '#')
|
||||
flags |= alternate_flag;
|
||||
else if(c == '0')
|
||||
flags |= zero_flag;
|
||||
else if(c == '\'')
|
||||
; /* just ignore */
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if((flags & space_flag) && (flags & plus_flag))
|
||||
flags ^= space_flag;
|
||||
|
||||
if((flags & minus_flag) && (flags & zero_flag))
|
||||
flags ^= zero_flag;
|
||||
|
||||
/* width */
|
||||
if (isdigit(c))
|
||||
do {
|
||||
width = width * 10 + c - '0';
|
||||
c = *format++;
|
||||
} while(isdigit(c));
|
||||
else if(c == '*') {
|
||||
width = va_arg(ap, int);
|
||||
c = *format++;
|
||||
}
|
||||
|
||||
/* precision */
|
||||
if (c == '.') {
|
||||
prec = 0;
|
||||
c = *format++;
|
||||
if (isdigit(c))
|
||||
do {
|
||||
prec = prec * 10 + c - '0';
|
||||
c = *format++;
|
||||
} while(isdigit(c));
|
||||
else if (c == '*') {
|
||||
prec = va_arg(ap, int);
|
||||
c = *format++;
|
||||
}
|
||||
}
|
||||
|
||||
/* size */
|
||||
|
||||
if (c == 'h') {
|
||||
short_flag = 1;
|
||||
c = *format++;
|
||||
} else if (c == 'z') {
|
||||
size_t_flag = 1;
|
||||
c = *format++;
|
||||
} else if (c == 'l') {
|
||||
long_flag = 1;
|
||||
c = *format++;
|
||||
if (c == 'l') {
|
||||
long_long_flag = 1;
|
||||
c = *format++;
|
||||
}
|
||||
}
|
||||
|
||||
if(c != 'd' && c != 'i')
|
||||
flags &= ~(plus_flag | space_flag);
|
||||
|
||||
switch (c) {
|
||||
case 'c' :
|
||||
append_char(state, va_arg(ap, int), width, flags);
|
||||
++len;
|
||||
break;
|
||||
case 's' :
|
||||
len += append_string(state,
|
||||
va_arg(ap, unsigned char*),
|
||||
width,
|
||||
prec,
|
||||
flags);
|
||||
break;
|
||||
case 'd' :
|
||||
case 'i' : {
|
||||
longest arg;
|
||||
u_longest num;
|
||||
int minusp = 0;
|
||||
|
||||
PARSE_INT_FORMAT(arg, ap, signed);
|
||||
|
||||
if (arg < 0) {
|
||||
minusp = 1;
|
||||
num = -arg;
|
||||
} else
|
||||
num = arg;
|
||||
|
||||
len += append_number (state, num, 10, "0123456789",
|
||||
width, prec, flags, minusp);
|
||||
break;
|
||||
}
|
||||
case 'u' : {
|
||||
u_longest arg;
|
||||
|
||||
PARSE_INT_FORMAT(arg, ap, unsigned);
|
||||
|
||||
len += append_number (state, arg, 10, "0123456789",
|
||||
width, prec, flags, 0);
|
||||
break;
|
||||
}
|
||||
case 'o' : {
|
||||
u_longest arg;
|
||||
|
||||
PARSE_INT_FORMAT(arg, ap, unsigned);
|
||||
|
||||
len += append_number (state, arg, 010, "01234567",
|
||||
width, prec, flags, 0);
|
||||
break;
|
||||
}
|
||||
case 'x' : {
|
||||
u_longest arg;
|
||||
|
||||
PARSE_INT_FORMAT(arg, ap, unsigned);
|
||||
|
||||
len += append_number (state, arg, 0x10, "0123456789abcdef",
|
||||
width, prec, flags, 0);
|
||||
break;
|
||||
}
|
||||
case 'X' :{
|
||||
u_longest arg;
|
||||
|
||||
PARSE_INT_FORMAT(arg, ap, unsigned);
|
||||
|
||||
len += append_number (state, arg, 0x10, "0123456789ABCDEF",
|
||||
width, prec, flags, 0);
|
||||
break;
|
||||
}
|
||||
case 'p' : {
|
||||
u_longest arg = (u_longest)va_arg(ap, void*);
|
||||
|
||||
len += append_number (state, arg, 0x10, "0123456789ABCDEF",
|
||||
width, prec, flags, 0);
|
||||
break;
|
||||
}
|
||||
case 'n' : {
|
||||
int *arg = va_arg(ap, int*);
|
||||
*arg = state->s - state->str;
|
||||
break;
|
||||
}
|
||||
case '\0' :
|
||||
--format;
|
||||
/* FALLTHROUGH */
|
||||
case '%' :
|
||||
(*state->append_char)(state, c);
|
||||
++len;
|
||||
break;
|
||||
default :
|
||||
(*state->append_char)(state, '%');
|
||||
(*state->append_char)(state, c);
|
||||
len += 2;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
(*state->append_char) (state, c);
|
||||
++len;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
#if !defined(HAVE_SNPRINTF) || defined(TEST_SNPRINTF)
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_snprintf (char *str, size_t sz, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
va_start(args, format);
|
||||
ret = vsnprintf (str, sz, format, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef PARANOIA
|
||||
{
|
||||
int ret2;
|
||||
char *tmp;
|
||||
|
||||
tmp = malloc (sz);
|
||||
if (tmp == NULL)
|
||||
abort ();
|
||||
|
||||
va_start(args, format);
|
||||
ret2 = vsprintf (tmp, format, args);
|
||||
va_end(args);
|
||||
if (ret != ret2 || strcmp(str, tmp))
|
||||
abort ();
|
||||
free (tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_ASPRINTF) || defined(TEST_SNPRINTF)
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_asprintf (char **ret, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int val;
|
||||
|
||||
va_start(args, format);
|
||||
val = vasprintf (ret, format, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef PARANOIA
|
||||
{
|
||||
int ret2;
|
||||
char *tmp;
|
||||
tmp = malloc (val + 1);
|
||||
if (tmp == NULL)
|
||||
abort ();
|
||||
|
||||
va_start(args, format);
|
||||
ret2 = vsprintf (tmp, format, args);
|
||||
va_end(args);
|
||||
if (val != ret2 || strcmp(*ret, tmp))
|
||||
abort ();
|
||||
free (tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
return val;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_ASNPRINTF) || defined(TEST_SNPRINTF)
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_asnprintf (char **ret, size_t max_sz, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int val;
|
||||
|
||||
va_start(args, format);
|
||||
val = vasnprintf (ret, max_sz, format, args);
|
||||
|
||||
#ifdef PARANOIA
|
||||
{
|
||||
int ret2;
|
||||
char *tmp;
|
||||
tmp = malloc (val + 1);
|
||||
if (tmp == NULL)
|
||||
abort ();
|
||||
|
||||
ret2 = vsprintf (tmp, format, args);
|
||||
if (val != ret2 || strcmp(*ret, tmp))
|
||||
abort ();
|
||||
free (tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
va_end(args);
|
||||
return val;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_VASPRINTF) || defined(TEST_SNPRINTF)
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_vasprintf (char **ret, const char *format, va_list args)
|
||||
{
|
||||
return vasnprintf (ret, 0, format, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(HAVE_VASNPRINTF) || defined(TEST_SNPRINTF)
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
|
||||
{
|
||||
size_t st;
|
||||
struct snprintf_state state;
|
||||
|
||||
state.max_sz = max_sz;
|
||||
state.sz = 1;
|
||||
state.str = malloc(state.sz);
|
||||
if (state.str == NULL) {
|
||||
*ret = NULL;
|
||||
return -1;
|
||||
}
|
||||
state.s = state.str;
|
||||
state.theend = state.s + state.sz - 1;
|
||||
state.append_char = as_append_char;
|
||||
|
||||
st = xyzprintf (&state, format, args);
|
||||
if (st > state.sz) {
|
||||
free (state.str);
|
||||
*ret = NULL;
|
||||
return -1;
|
||||
} else {
|
||||
char *tmp;
|
||||
|
||||
*state.s = '\0';
|
||||
tmp = realloc (state.str, st+1);
|
||||
if (tmp == NULL) {
|
||||
free (state.str);
|
||||
*ret = NULL;
|
||||
return -1;
|
||||
}
|
||||
*ret = tmp;
|
||||
return st;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_VSNPRINTF) || defined(TEST_SNPRINTF)
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_vsnprintf (char *str, size_t sz, const char *format, va_list args)
|
||||
{
|
||||
struct snprintf_state state;
|
||||
int ret;
|
||||
unsigned char *ustr = (unsigned char *)str;
|
||||
|
||||
state.max_sz = 0;
|
||||
state.sz = sz;
|
||||
state.str = ustr;
|
||||
state.s = ustr;
|
||||
state.theend = ustr + sz - (sz > 0);
|
||||
state.append_char = sn_append_char;
|
||||
|
||||
ret = xyzprintf (&state, format, args);
|
||||
if (state.s != NULL && sz != 0)
|
||||
*state.s = '\0';
|
||||
return ret;
|
||||
}
|
||||
#endif
|
351
src/external/heimdal/roken/socket.c
vendored
Normal file
351
src/external/heimdal/roken/socket.c
vendored
Normal file
@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (c) 1999 - 2000 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "roken.h"
|
||||
#include <err.h>
|
||||
|
||||
/*
|
||||
* Set `sa' to the unitialized address of address family `af'
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_any (struct sockaddr *sa, int af)
|
||||
{
|
||||
switch (af) {
|
||||
case AF_INET : {
|
||||
struct sockaddr_in *sin4 = (struct sockaddr_in *)sa;
|
||||
|
||||
memset (sin4, 0, sizeof(*sin4));
|
||||
sin4->sin_family = AF_INET;
|
||||
sin4->sin_port = 0;
|
||||
sin4->sin_addr.s_addr = INADDR_ANY;
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 : {
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
|
||||
|
||||
memset (sin6, 0, sizeof(*sin6));
|
||||
sin6->sin6_family = AF_INET6;
|
||||
sin6->sin6_port = 0;
|
||||
sin6->sin6_addr = in6addr_any;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* set `sa' to (`ptr', `port')
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port)
|
||||
{
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET : {
|
||||
struct sockaddr_in *sin4 = (struct sockaddr_in *)sa;
|
||||
|
||||
memset (sin4, 0, sizeof(*sin4));
|
||||
sin4->sin_family = AF_INET;
|
||||
sin4->sin_port = port;
|
||||
memcpy (&sin4->sin_addr, ptr, sizeof(struct in_addr));
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 : {
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
|
||||
|
||||
memset (sin6, 0, sizeof(*sin6));
|
||||
sin6->sin6_family = AF_INET6;
|
||||
sin6->sin6_port = port;
|
||||
memcpy (&sin6->sin6_addr, ptr, sizeof(struct in6_addr));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the size of an address of the type in `sa'
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
socket_addr_size (const struct sockaddr *sa)
|
||||
{
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET :
|
||||
return sizeof(struct in_addr);
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 :
|
||||
return sizeof(struct in6_addr);
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the size of a `struct sockaddr' in `sa'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
socket_sockaddr_size (const struct sockaddr *sa)
|
||||
{
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET :
|
||||
return sizeof(struct sockaddr_in);
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 :
|
||||
return sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the binary address of `sa'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
socket_get_address (const struct sockaddr *sa)
|
||||
{
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET : {
|
||||
const struct sockaddr_in *sin4 = (const struct sockaddr_in *)sa;
|
||||
return rk_UNCONST(&sin4->sin_addr);
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 : {
|
||||
const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
|
||||
return rk_UNCONST(&sin6->sin6_addr);
|
||||
}
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
UNREACHABLE(return NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the port number from `sa'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
socket_get_port (const struct sockaddr *sa)
|
||||
{
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET : {
|
||||
const struct sockaddr_in *sin4 = (const struct sockaddr_in *)sa;
|
||||
return sin4->sin_port;
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 : {
|
||||
const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
|
||||
return sin6->sin6_port;
|
||||
}
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the port in `sa' to `port'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_port (struct sockaddr *sa, int port)
|
||||
{
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET : {
|
||||
struct sockaddr_in *sin4 = (struct sockaddr_in *)sa;
|
||||
sin4->sin_port = port;
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 : {
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
|
||||
sin6->sin6_port = port;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default :
|
||||
errx (1, "unknown address family %d", sa->sa_family);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the range of ports to use when binding with port = 0.
|
||||
*/
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_portrange (rk_socket_t sock, int restr, int af)
|
||||
{
|
||||
#if defined(IP_PORTRANGE)
|
||||
if (af == AF_INET) {
|
||||
int on = restr ? IP_PORTRANGE_HIGH : IP_PORTRANGE_DEFAULT;
|
||||
if (setsockopt (sock, IPPROTO_IP, IP_PORTRANGE, &on,
|
||||
sizeof(on)) < 0)
|
||||
warn ("setsockopt IP_PORTRANGE (ignored)");
|
||||
}
|
||||
#endif
|
||||
#if defined(IPV6_PORTRANGE)
|
||||
if (af == AF_INET6) {
|
||||
int on = restr ? IPV6_PORTRANGE_HIGH :
|
||||
IPV6_PORTRANGE_DEFAULT;
|
||||
if (setsockopt (sock, IPPROTO_IPV6, IPV6_PORTRANGE, &on,
|
||||
sizeof(on)) < 0)
|
||||
warn ("setsockopt IPV6_PORTRANGE (ignored)");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable debug on `sock'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_debug (rk_socket_t sock)
|
||||
{
|
||||
#if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT)
|
||||
int on = 1;
|
||||
|
||||
if (setsockopt (sock, SOL_SOCKET, SO_DEBUG, (void *) &on, sizeof (on)) < 0)
|
||||
warn ("setsockopt SO_DEBUG (ignored)");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the type-of-service of `sock' to `tos'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_tos (rk_socket_t sock, int tos)
|
||||
{
|
||||
#if defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
|
||||
if (setsockopt (sock, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof (int)) < 0)
|
||||
if (errno != EINVAL)
|
||||
warn ("setsockopt TOS (ignored)");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* set the reuse of addresses on `sock' to `val'.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_reuseaddr (rk_socket_t sock, int val)
|
||||
{
|
||||
#if defined(SO_REUSEADDR) && defined(HAVE_SETSOCKOPT)
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&val,
|
||||
sizeof(val)) < 0)
|
||||
err (1, "setsockopt SO_REUSEADDR");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the that the `sock' should bind to only IPv6 addresses.
|
||||
*/
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
socket_set_ipv6only (rk_socket_t sock, int val)
|
||||
{
|
||||
#if defined(IPV6_V6ONLY) && defined(HAVE_SETSOCKOPT)
|
||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&val, sizeof(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file descriptor from a socket
|
||||
*
|
||||
* While the socket handle in \a sock can be used with WinSock
|
||||
* functions after calling socket_to_fd(), it should not be closed
|
||||
* with rk_closesocket(). The socket will be closed when the associated
|
||||
* file descriptor is closed.
|
||||
*/
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
socket_to_fd(rk_socket_t sock, int flags)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return sock;
|
||||
#else
|
||||
return _open_osfhandle((intptr_t) sock, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_WINSOCK
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp) {
|
||||
u_long ul = (argp)? *argp : 0;
|
||||
int rv;
|
||||
|
||||
rv = ioctlsocket(s, cmd, &ul);
|
||||
if (argp)
|
||||
*argp = (int) ul;
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HEIMDAL_SMALLER
|
||||
#undef socket
|
||||
|
||||
int rk_socket(int, int, int);
|
||||
|
||||
int
|
||||
rk_socket(int domain, int type, int protocol)
|
||||
{
|
||||
int s;
|
||||
s = socket (domain, type, protocol);
|
||||
#ifdef SOCK_CLOEXEC
|
||||
if ((SOCK_CLOEXEC & type) && s < 0 && errno == EINVAL) {
|
||||
type &= ~SOCK_CLOEXEC;
|
||||
s = socket (domain, type, protocol);
|
||||
}
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif /* HEIMDAL_SMALLER */
|
84
src/external/heimdal/roken/strerror_r.c
vendored
Normal file
84
src/external/heimdal/roken/strerror_r.c
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "roken.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
rk_strerror_r(int eno, char * strerrbuf, size_t buflen)
|
||||
{
|
||||
errno_t err;
|
||||
|
||||
err = strerror_s(strerrbuf, buflen, eno);
|
||||
if (err != 0) {
|
||||
int code;
|
||||
code = sprintf_s(strerrbuf, buflen, "Error % occurred.", eno);
|
||||
err = ((code != 0)? errno : 0);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#else /* _MSC_VER */
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
rk_strerror_r(int eno, char *strerrbuf, size_t buflen)
|
||||
{
|
||||
/* Assume is the linux broken strerror_r (returns the a buffer (char *) if the input buffer wasn't use */
|
||||
#ifdef HAVE_STRERROR_R
|
||||
const char *str;
|
||||
str = strerror_r(eno, strerrbuf, buflen);
|
||||
if (str != strerrbuf)
|
||||
if (strlcpy(strerrbuf, str, buflen) >= buflen)
|
||||
return ERANGE;
|
||||
return 0;
|
||||
#else
|
||||
int ret;
|
||||
ret = strlcpy(strerrbuf, strerror(eno), buflen);
|
||||
if (ret > buflen)
|
||||
return ERANGE;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !_MSC_VER */
|
||||
|
||||
#endif
|
60
src/external/heimdal/roken/strlcat.c
vendored
Normal file
60
src/external/heimdal/roken/strlcat.c
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 1995-2002 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "roken.h"
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
strlcat (char *dst, const char *src, size_t dst_sz)
|
||||
{
|
||||
size_t len;
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
len = strnlen_s(dst, dst_sz);
|
||||
#elif defined(HAVE_STRNLEN)
|
||||
len = strnlen(dst, dst_sz);
|
||||
#else
|
||||
len = strlen(dst);
|
||||
#endif
|
||||
|
||||
if (dst_sz <= len)
|
||||
/* the total size of dst is less than the string it contains;
|
||||
this could be considered bad input, but we might as well
|
||||
handle it */
|
||||
return len + strlen(src);
|
||||
|
||||
return len + strlcpy (dst + len, src, dst_sz - len);
|
||||
}
|
||||
|
||||
#endif
|
46
src/external/heimdal/roken/strnlen.c
vendored
Normal file
46
src/external/heimdal/roken/strnlen.c
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
strnlen(const char *s, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < len && s[i]; i++)
|
||||
;
|
||||
return i;
|
||||
}
|
Loading…
Reference in New Issue
Block a user