Move the upstream-netbsd libc files into the correct directory.
I screwed up when I originally imported these files; they're in lib/libc/ in the upstream tree; there is no top-level libc/ (though there is a top-level common/, so those files stay where they are). Change-Id: I7c5e2224a4441ab0e33616a855a8c6aacfeac46f
This commit is contained in:
98
libc/upstream-netbsd/lib/libc/gen/ftw.c
Normal file
98
libc/upstream-netbsd/lib/libc/gen/ftw.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/* $NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $ */
|
||||
|
||||
/* From OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Sponsored in part by the Defense Advanced Research Projects
|
||||
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <ftw.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
|
||||
int nfds)
|
||||
{
|
||||
/* LINTED */
|
||||
char * const paths[2] = { __UNCONST(path), NULL };
|
||||
FTSENT *cur;
|
||||
FTS *ftsp;
|
||||
int fnflag, error, sverrno;
|
||||
|
||||
/* XXX - nfds is currently unused */
|
||||
if (nfds < 1 || nfds > OPEN_MAX) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ftsp = fts_open(paths, FTS_COMFOLLOW | FTS_NOCHDIR, NULL);
|
||||
if (ftsp == NULL)
|
||||
return (-1);
|
||||
error = 0;
|
||||
while ((cur = fts_read(ftsp)) != NULL) {
|
||||
switch (cur->fts_info) {
|
||||
case FTS_D:
|
||||
fnflag = FTW_D;
|
||||
break;
|
||||
case FTS_DNR:
|
||||
fnflag = FTW_DNR;
|
||||
break;
|
||||
case FTS_DP:
|
||||
/* we only visit in preorder */
|
||||
continue;
|
||||
case FTS_F:
|
||||
case FTS_DEFAULT:
|
||||
fnflag = FTW_F;
|
||||
break;
|
||||
case FTS_NS:
|
||||
case FTS_NSOK:
|
||||
case FTS_SLNONE:
|
||||
fnflag = FTW_NS;
|
||||
break;
|
||||
case FTS_SL:
|
||||
fnflag = FTW_SL;
|
||||
break;
|
||||
case FTS_DC:
|
||||
errno = ELOOP;
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
error = -1;
|
||||
goto done;
|
||||
}
|
||||
error = fn(cur->fts_path, cur->fts_statp, fnflag);
|
||||
if (error != 0)
|
||||
break;
|
||||
}
|
||||
done:
|
||||
sverrno = errno;
|
||||
if (fts_close(ftsp) != 0 && error == 0)
|
||||
error = -1;
|
||||
else
|
||||
errno = sverrno;
|
||||
return (error);
|
||||
}
|
114
libc/upstream-netbsd/lib/libc/gen/nftw.c
Normal file
114
libc/upstream-netbsd/lib/libc/gen/nftw.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/* $NetBSD */
|
||||
|
||||
/* From OpenBSD: nftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Sponsored in part by the Defense Advanced Research Projects
|
||||
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: nftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <ftw.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
|
||||
struct FTW *), int nfds, int ftwflags)
|
||||
{
|
||||
/* LINTED */
|
||||
char * const paths[2] = { __UNCONST(path), NULL };
|
||||
struct FTW f;
|
||||
FTSENT *cur;
|
||||
FTS *ftsp;
|
||||
int ftsflags, fnflag, error, postorder, sverrno;
|
||||
|
||||
/* XXX - nfds is currently unused */
|
||||
if (nfds < 1 || nfds > OPEN_MAX) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ftsflags = FTS_COMFOLLOW;
|
||||
if (!(ftwflags & FTW_CHDIR))
|
||||
ftsflags |= FTS_NOCHDIR;
|
||||
if (ftwflags & FTW_MOUNT)
|
||||
ftsflags |= FTS_XDEV;
|
||||
if (ftwflags & FTW_PHYS)
|
||||
ftsflags |= FTS_PHYSICAL;
|
||||
postorder = (ftwflags & FTW_DEPTH) != 0;
|
||||
ftsp = fts_open(paths, ftsflags, NULL);
|
||||
if (ftsp == NULL)
|
||||
return (-1);
|
||||
error = 0;
|
||||
while ((cur = fts_read(ftsp)) != NULL) {
|
||||
switch (cur->fts_info) {
|
||||
case FTS_D:
|
||||
if (postorder)
|
||||
continue;
|
||||
fnflag = FTW_D;
|
||||
break;
|
||||
case FTS_DNR:
|
||||
fnflag = FTW_DNR;
|
||||
break;
|
||||
case FTS_DP:
|
||||
if (!postorder)
|
||||
continue;
|
||||
fnflag = FTW_DP;
|
||||
break;
|
||||
case FTS_F:
|
||||
case FTS_DEFAULT:
|
||||
fnflag = FTW_F;
|
||||
break;
|
||||
case FTS_NS:
|
||||
case FTS_NSOK:
|
||||
fnflag = FTW_NS;
|
||||
break;
|
||||
case FTS_SL:
|
||||
fnflag = FTW_SL;
|
||||
break;
|
||||
case FTS_SLNONE:
|
||||
fnflag = FTW_SLN;
|
||||
break;
|
||||
case FTS_DC:
|
||||
errno = ELOOP;
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
error = -1;
|
||||
goto done;
|
||||
}
|
||||
f.base = cur->fts_pathlen - cur->fts_namelen;
|
||||
f.level = cur->fts_level;
|
||||
error = fn(cur->fts_path, cur->fts_statp, fnflag, &f);
|
||||
if (error != 0)
|
||||
break;
|
||||
}
|
||||
done:
|
||||
sverrno = errno;
|
||||
(void) fts_close(ftsp);
|
||||
errno = sverrno;
|
||||
return (error);
|
||||
}
|
70
libc/upstream-netbsd/lib/libc/gen/nice.c
Normal file
70
libc/upstream-netbsd/lib/libc/gen/nice.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* $NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)nice.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(nice,_nice)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Backwards compatible nice.
|
||||
*/
|
||||
int
|
||||
nice(int incr)
|
||||
{
|
||||
int prio;
|
||||
|
||||
errno = 0;
|
||||
prio = getpriority(PRIO_PROCESS, 0);
|
||||
if (prio == -1 && errno)
|
||||
return -1;
|
||||
if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) {
|
||||
if (errno == EACCES)
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
return getpriority(PRIO_PROCESS, 0);
|
||||
}
|
227
libc/upstream-netbsd/lib/libc/gen/popen.c
Normal file
227
libc/upstream-netbsd/lib/libc/gen/popen.c
Normal file
@@ -0,0 +1,227 @@
|
||||
/* $NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software written by Ken Arnold and
|
||||
* published in UNIX Review, Vol. 6, No. 8.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "env.h"
|
||||
#include "reentrant.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(popen,_popen)
|
||||
__weak_alias(pclose,_pclose)
|
||||
#endif
|
||||
|
||||
static struct pid {
|
||||
struct pid *next;
|
||||
FILE *fp;
|
||||
#ifdef _REENTRANT
|
||||
int fd;
|
||||
#endif
|
||||
pid_t pid;
|
||||
} *pidlist;
|
||||
|
||||
#ifdef _REENTRANT
|
||||
static rwlock_t pidlist_lock = RWLOCK_INITIALIZER;
|
||||
#endif
|
||||
|
||||
FILE *
|
||||
popen(const char *command, const char *type)
|
||||
{
|
||||
struct pid *cur, *old;
|
||||
FILE *iop;
|
||||
const char * volatile xtype = type;
|
||||
int pdes[2], pid, serrno;
|
||||
volatile int twoway;
|
||||
int flags;
|
||||
|
||||
_DIAGASSERT(command != NULL);
|
||||
_DIAGASSERT(xtype != NULL);
|
||||
|
||||
flags = strchr(xtype, 'e') ? O_CLOEXEC : 0;
|
||||
if (strchr(xtype, '+')) {
|
||||
int stype = flags ? (SOCK_STREAM | SOCK_CLOEXEC) : SOCK_STREAM;
|
||||
twoway = 1;
|
||||
xtype = "r+";
|
||||
if (socketpair(AF_LOCAL, stype, 0, pdes) < 0)
|
||||
return NULL;
|
||||
} else {
|
||||
twoway = 0;
|
||||
xtype = strrchr(xtype, 'r') ? "r" : "w";
|
||||
if (pipe2(pdes, flags) == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((cur = malloc(sizeof(struct pid))) == NULL) {
|
||||
(void)close(pdes[0]);
|
||||
(void)close(pdes[1]);
|
||||
errno = ENOMEM;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
(void)rwlock_rdlock(&pidlist_lock);
|
||||
(void)__readlockenv();
|
||||
switch (pid = vfork()) {
|
||||
case -1: /* Error. */
|
||||
serrno = errno;
|
||||
(void)__unlockenv();
|
||||
(void)rwlock_unlock(&pidlist_lock);
|
||||
free(cur);
|
||||
(void)close(pdes[0]);
|
||||
(void)close(pdes[1]);
|
||||
errno = serrno;
|
||||
return (NULL);
|
||||
/* NOTREACHED */
|
||||
case 0: /* Child. */
|
||||
/* POSIX.2 B.3.2.2 "popen() shall ensure that any streams
|
||||
from previous popen() calls that remain open in the
|
||||
parent process are closed in the new child process. */
|
||||
for (old = pidlist; old; old = old->next)
|
||||
#ifdef _REENTRANT
|
||||
close(old->fd); /* don't allow a flush */
|
||||
#else
|
||||
close(fileno(old->fp)); /* don't allow a flush */
|
||||
#endif
|
||||
|
||||
if (*xtype == 'r') {
|
||||
(void)close(pdes[0]);
|
||||
if (pdes[1] != STDOUT_FILENO) {
|
||||
(void)dup2(pdes[1], STDOUT_FILENO);
|
||||
(void)close(pdes[1]);
|
||||
}
|
||||
if (twoway)
|
||||
(void)dup2(STDOUT_FILENO, STDIN_FILENO);
|
||||
} else {
|
||||
(void)close(pdes[1]);
|
||||
if (pdes[0] != STDIN_FILENO) {
|
||||
(void)dup2(pdes[0], STDIN_FILENO);
|
||||
(void)close(pdes[0]);
|
||||
}
|
||||
}
|
||||
|
||||
execl(_PATH_BSHELL, "sh", "-c", command, NULL);
|
||||
_exit(127);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
(void)__unlockenv();
|
||||
|
||||
/* Parent; assume fdopen can't fail. */
|
||||
if (*xtype == 'r') {
|
||||
iop = fdopen(pdes[0], xtype);
|
||||
#ifdef _REENTRANT
|
||||
cur->fd = pdes[0];
|
||||
#endif
|
||||
(void)close(pdes[1]);
|
||||
} else {
|
||||
iop = fdopen(pdes[1], xtype);
|
||||
#ifdef _REENTRANT
|
||||
cur->fd = pdes[1];
|
||||
#endif
|
||||
(void)close(pdes[0]);
|
||||
}
|
||||
|
||||
/* Link into list of file descriptors. */
|
||||
cur->fp = iop;
|
||||
cur->pid = pid;
|
||||
cur->next = pidlist;
|
||||
pidlist = cur;
|
||||
(void)rwlock_unlock(&pidlist_lock);
|
||||
|
||||
return (iop);
|
||||
}
|
||||
|
||||
/*
|
||||
* pclose --
|
||||
* Pclose returns -1 if stream is not associated with a `popened' command,
|
||||
* if already `pclosed', or waitpid returns an error.
|
||||
*/
|
||||
int
|
||||
pclose(FILE *iop)
|
||||
{
|
||||
struct pid *cur, *last;
|
||||
int pstat;
|
||||
pid_t pid;
|
||||
|
||||
_DIAGASSERT(iop != NULL);
|
||||
|
||||
rwlock_wrlock(&pidlist_lock);
|
||||
|
||||
/* Find the appropriate file pointer. */
|
||||
for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
|
||||
if (cur->fp == iop)
|
||||
break;
|
||||
if (cur == NULL) {
|
||||
(void)rwlock_unlock(&pidlist_lock);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
(void)fclose(iop);
|
||||
|
||||
/* Remove the entry from the linked list. */
|
||||
if (last == NULL)
|
||||
pidlist = cur->next;
|
||||
else
|
||||
last->next = cur->next;
|
||||
|
||||
(void)rwlock_unlock(&pidlist_lock);
|
||||
|
||||
do {
|
||||
pid = waitpid(cur->pid, &pstat, 0);
|
||||
} while (pid == -1 && errno == EINTR);
|
||||
|
||||
free(cur);
|
||||
|
||||
return (pid == -1 ? -1 : pstat);
|
||||
}
|
85
libc/upstream-netbsd/lib/libc/gen/psignal.c
Normal file
85
libc/upstream-netbsd/lib/libc/gen/psignal.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/* $NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(psignal,_psignal)
|
||||
#endif
|
||||
|
||||
void
|
||||
psignal(int sig, const char *s)
|
||||
{
|
||||
struct iovec *v;
|
||||
struct iovec iov[4];
|
||||
char buf[NL_TEXTMAX];
|
||||
|
||||
v = iov;
|
||||
if (s && *s) {
|
||||
v->iov_base = __UNCONST(s);
|
||||
v->iov_len = strlen(s);
|
||||
v++;
|
||||
v->iov_base = __UNCONST(": ");
|
||||
v->iov_len = 2;
|
||||
v++;
|
||||
}
|
||||
v->iov_base = __UNCONST(__strsignal((int)sig, buf, sizeof(buf)));
|
||||
v->iov_len = strlen(v->iov_base);
|
||||
v++;
|
||||
v->iov_base = __UNCONST("\n");
|
||||
v->iov_len = 1;
|
||||
(void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1));
|
||||
}
|
||||
|
||||
void
|
||||
psiginfo(const siginfo_t *si, const char *s)
|
||||
{
|
||||
psignal(si->si_signo, s);
|
||||
}
|
56
libc/upstream-netbsd/lib/libc/gen/setjmperr.c
Normal file
56
libc/upstream-netbsd/lib/libc/gen/setjmperr.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* $NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)setjmperr.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* This routine is called from longjmp() when an error occurs.
|
||||
* Programs that wish to exit gracefully from this error may
|
||||
* write their own versions.
|
||||
* If this routine returns, the program is aborted.
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void
|
||||
longjmperror(void)
|
||||
{
|
||||
#define ERRMSG "longjmp botch.\n"
|
||||
(void)write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1);
|
||||
}
|
65
libc/upstream-netbsd/lib/libc/gen/utime.c
Normal file
65
libc/upstream-netbsd/lib/libc/gen/utime.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* $NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $ */
|
||||
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)utime.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <utime.h>
|
||||
|
||||
int
|
||||
utime(const char *path, const struct utimbuf *times)
|
||||
{
|
||||
struct timeval tv[2], *tvp;
|
||||
|
||||
_DIAGASSERT(path != NULL);
|
||||
|
||||
if (times == (struct utimbuf *) NULL)
|
||||
tvp = NULL;
|
||||
else {
|
||||
tv[0].tv_sec = times->actime;
|
||||
tv[1].tv_sec = times->modtime;
|
||||
tv[0].tv_usec = tv[1].tv_usec = 0;
|
||||
tvp = tv;
|
||||
}
|
||||
return (utimes(path, tvp));
|
||||
}
|
132
libc/upstream-netbsd/lib/libc/include/isc/assertions.h
Normal file
132
libc/upstream-netbsd/lib/libc/include/isc/assertions.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/* $NetBSD: assertions.h,v 1.5 2009/04/12 17:07:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (C) 1997-2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp
|
||||
*/
|
||||
|
||||
#ifndef ASSERTIONS_H
|
||||
#define ASSERTIONS_H 1
|
||||
|
||||
typedef enum {
|
||||
assert_require, assert_ensure, assert_insist, assert_invariant
|
||||
} assertion_type;
|
||||
|
||||
typedef void (*assertion_failure_callback)(const char *, int, assertion_type,
|
||||
const char *, int);
|
||||
|
||||
/* coverity[+kill] */
|
||||
extern assertion_failure_callback __assertion_failed;
|
||||
void set_assertion_failure_callback(assertion_failure_callback f);
|
||||
const char *assertion_type_to_text(assertion_type type);
|
||||
|
||||
#if defined(CHECK_ALL) || defined(__COVERITY__)
|
||||
#define CHECK_REQUIRE 1
|
||||
#define CHECK_ENSURE 1
|
||||
#define CHECK_INSIST 1
|
||||
#define CHECK_INVARIANT 1
|
||||
#endif
|
||||
|
||||
#if defined(CHECK_NONE) && !defined(__COVERITY__)
|
||||
#define CHECK_REQUIRE 0
|
||||
#define CHECK_ENSURE 0
|
||||
#define CHECK_INSIST 0
|
||||
#define CHECK_INVARIANT 0
|
||||
#endif
|
||||
|
||||
#ifdef _DIAGNOSTIC
|
||||
#ifndef CHECK_REQUIRE
|
||||
#define CHECK_REQUIRE 1
|
||||
#endif
|
||||
|
||||
#ifndef CHECK_ENSURE
|
||||
#define CHECK_ENSURE 1
|
||||
#endif
|
||||
|
||||
#ifndef CHECK_INSIST
|
||||
#define CHECK_INSIST 1
|
||||
#endif
|
||||
|
||||
#ifndef CHECK_INVARIANT
|
||||
#define CHECK_INVARIANT 1
|
||||
#endif
|
||||
#endif /* _DIAGNOSTIC */
|
||||
|
||||
#if CHECK_REQUIRE != 0
|
||||
#define REQUIRE(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_require, \
|
||||
#cond, 0), 0)))
|
||||
#define REQUIRE_ERR(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_require, \
|
||||
#cond, 1), 0)))
|
||||
#else
|
||||
#define REQUIRE(cond) ((void) (cond))
|
||||
#define REQUIRE_ERR(cond) ((void) (cond))
|
||||
#endif /* CHECK_REQUIRE */
|
||||
|
||||
#if CHECK_ENSURE != 0
|
||||
#define ENSURE(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
|
||||
#cond, 0), 0)))
|
||||
#define ENSURE_ERR(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
|
||||
#cond, 1), 0)))
|
||||
#else
|
||||
#define ENSURE(cond) ((void) (cond))
|
||||
#define ENSURE_ERR(cond) ((void) (cond))
|
||||
#endif /* CHECK_ENSURE */
|
||||
|
||||
#if CHECK_INSIST != 0
|
||||
#define INSIST(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
|
||||
#cond, 0), 0)))
|
||||
#define INSIST_ERR(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
|
||||
#cond, 1), 0)))
|
||||
#else
|
||||
#if !defined(__lint__)
|
||||
#define INSIST(cond) ((void) (cond))
|
||||
#define INSIST_ERR(cond) ((void) (cond))
|
||||
#else /* !__lint__ */
|
||||
#define INSIST(cond)
|
||||
#define INSIST_ERR(cond)
|
||||
#endif /* !__lint__ */
|
||||
#endif /* CHECK_INSIST */
|
||||
|
||||
#if CHECK_INVARIANT != 0
|
||||
#define INVARIANT(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
|
||||
#cond, 0), 0)))
|
||||
#define INVARIANT_ERR(cond) \
|
||||
((void) ((cond) || \
|
||||
((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
|
||||
#cond, 1), 0)))
|
||||
#else
|
||||
#define INVARIANT(cond) ((void) (cond))
|
||||
#define INVARIANT_ERR(cond) ((void) (cond))
|
||||
#endif /* CHECK_INVARIANT */
|
||||
#endif /* ASSERTIONS_H */
|
||||
/*! \file */
|
170
libc/upstream-netbsd/lib/libc/include/isc/dst.h
Normal file
170
libc/upstream-netbsd/lib/libc/include/isc/dst.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/* $NetBSD: dst.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */
|
||||
|
||||
#ifndef DST_H
|
||||
#define DST_H
|
||||
|
||||
#ifndef HAS_DST_KEY
|
||||
typedef struct dst_key {
|
||||
char *dk_key_name; /*%< name of the key */
|
||||
int dk_key_size; /*%< this is the size of the key in bits */
|
||||
int dk_proto; /*%< what protocols this key can be used for */
|
||||
int dk_alg; /*%< algorithm number from key record */
|
||||
u_int32_t dk_flags; /*%< and the flags of the public key */
|
||||
u_int16_t dk_id; /*%< identifier of the key */
|
||||
} DST_KEY;
|
||||
#endif /* HAS_DST_KEY */
|
||||
/*
|
||||
* do not taint namespace
|
||||
*/
|
||||
#define dst_bsafe_init __dst_bsafe_init
|
||||
#define dst_buffer_to_key __dst_buffer_to_key
|
||||
#define dst_check_algorithm __dst_check_algorithm
|
||||
#define dst_compare_keys __dst_compare_keys
|
||||
#define dst_cylink_init __dst_cylink_init
|
||||
#define dst_dnskey_to_key __dst_dnskey_to_key
|
||||
#define dst_eay_dss_init __dst_eay_dss_init
|
||||
#define dst_free_key __dst_free_key
|
||||
#define dst_generate_key __dst_generate_key
|
||||
#define dst_hmac_md5_init __dst_hmac_md5_init
|
||||
#define dst_init __dst_init
|
||||
#define dst_key_to_buffer __dst_key_to_buffer
|
||||
#define dst_key_to_dnskey __dst_key_to_dnskey
|
||||
#define dst_read_key __dst_read_key
|
||||
#define dst_rsaref_init __dst_rsaref_init
|
||||
#define dst_s_build_filename __dst_s_build_filename
|
||||
#define dst_s_calculate_bits __dst_s_calculate_bits
|
||||
#define dst_s_conv_bignum_b64_to_u8 __dst_s_conv_bignum_b64_to_u8
|
||||
#define dst_s_conv_bignum_u8_to_b64 __dst_s_conv_bignum_u8_to_b64
|
||||
#define dst_s_dns_key_id __dst_s_dns_key_id
|
||||
#define dst_s_dump __dst_s_dump
|
||||
#define dst_s_filename_length __dst_s_filename_length
|
||||
#define dst_s_fopen __dst_s_fopen
|
||||
#define dst_s_get_int16 __dst_s_get_int16
|
||||
#define dst_s_get_int32 __dst_s_get_int32
|
||||
#define dst_s_id_calc __dst_s_id_calc
|
||||
#define dst_s_put_int16 __dst_s_put_int16
|
||||
#define dst_s_put_int32 __dst_s_put_int32
|
||||
#define dst_s_quick_random __dst_s_quick_random
|
||||
#define dst_s_quick_random_set __dst_s_quick_random_set
|
||||
#define dst_s_random __dst_s_random
|
||||
#define dst_s_semi_random __dst_s_semi_random
|
||||
#define dst_s_verify_str __dst_s_verify_str
|
||||
#define dst_sig_size __dst_sig_size
|
||||
#define dst_sign_data __dst_sign_data
|
||||
#define dst_verify_data __dst_verify_data
|
||||
#define dst_write_key __dst_write_key
|
||||
|
||||
/*
|
||||
* DST Crypto API defintions
|
||||
*/
|
||||
void dst_init(void);
|
||||
int dst_check_algorithm(const int);
|
||||
|
||||
|
||||
int dst_sign_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */
|
||||
DST_KEY *, /*!< the key to use */
|
||||
void **, /*!< pointer to state structure */
|
||||
const u_char *, /*!< data to be signed */
|
||||
const int, /*!< length of input data */
|
||||
u_char *, /*!< buffer to write signature to */
|
||||
const int); /*!< size of output buffer */
|
||||
int dst_verify_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */
|
||||
DST_KEY *, /*!< the key to use */
|
||||
void **, /*!< pointer to state structure */
|
||||
const u_char *, /*!< data to be verified */
|
||||
const int, /*!< length of input data */
|
||||
const u_char *, /*!< buffer containing signature */
|
||||
const int); /*!< length of signature */
|
||||
DST_KEY *dst_read_key(const char *, /*!< name of key */
|
||||
const u_int16_t, /*!< key tag identifier */
|
||||
const int, /*!< key algorithm */
|
||||
const int); /*!< Private/PublicKey wanted */
|
||||
int dst_write_key(const DST_KEY *, /*!< key to write out */
|
||||
const int); /*!< Public/Private */
|
||||
DST_KEY *dst_dnskey_to_key(const char *, /*!< KEY record name */
|
||||
const u_char *, /*!< KEY RDATA */
|
||||
const int); /*!< size of input buffer */
|
||||
int dst_key_to_dnskey(const DST_KEY *, /*!< key to translate */
|
||||
u_char *, /*!< output buffer */
|
||||
const int); /*!< size of out_storage */
|
||||
DST_KEY *dst_buffer_to_key(const char *, /*!< name of the key */
|
||||
const int, /*!< algorithm */
|
||||
const int, /*!< dns flags */
|
||||
const int, /*!< dns protocol */
|
||||
const u_char *, /*!< key in dns wire fmt */
|
||||
const int); /*!< size of key */
|
||||
int dst_key_to_buffer(DST_KEY *, u_char *, int);
|
||||
|
||||
DST_KEY *dst_generate_key(const char *, /*!< name of new key */
|
||||
const int, /*!< key algorithm to generate */
|
||||
const int, /*!< size of new key */
|
||||
const int, /*!< alg dependent parameter */
|
||||
const int, /*!< key DNS flags */
|
||||
const int); /*!< key DNS protocol */
|
||||
DST_KEY *dst_free_key(DST_KEY *);
|
||||
int dst_compare_keys(const DST_KEY *, const DST_KEY *);
|
||||
|
||||
int dst_sig_size(DST_KEY *);
|
||||
|
||||
|
||||
/* support for dns key tags/ids */
|
||||
u_int16_t dst_s_dns_key_id(const u_char *, const int);
|
||||
u_int16_t dst_s_id_calc(const u_char *, const int);
|
||||
|
||||
/* Used by callers as well as by the library. */
|
||||
#define RAW_KEY_SIZE 8192 /*%< large enough to store any key */
|
||||
/* DST_API control flags */
|
||||
/* These are used used in functions dst_sign_data and dst_verify_data */
|
||||
#define SIG_MODE_INIT 1 /*%< initialize digest */
|
||||
#define SIG_MODE_UPDATE 2 /*%< add data to digest */
|
||||
#define SIG_MODE_FINAL 4 /*%< generate/verify signature */
|
||||
#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
|
||||
|
||||
/* Flags for dst_read_private_key() */
|
||||
#define DST_FORCE_READ 0x1000000
|
||||
#define DST_CAN_SIGN 0x010F
|
||||
#define DST_NO_AUTHEN 0x8000
|
||||
#define DST_EXTEND_FLAG 0x1000
|
||||
#define DST_STANDARD 0
|
||||
#define DST_PRIVATE 0x2000000
|
||||
#define DST_PUBLIC 0x4000000
|
||||
#define DST_RAND_SEMI 1
|
||||
#define DST_RAND_STD 2
|
||||
#define DST_RAND_KEY 3
|
||||
#define DST_RAND_DSS 4
|
||||
|
||||
|
||||
/* DST algorithm codes */
|
||||
#define KEY_RSA 1
|
||||
#define KEY_DH 2
|
||||
#define KEY_DSA 3
|
||||
#define KEY_PRIVATE 254
|
||||
#define KEY_EXPAND 255
|
||||
#define KEY_HMAC_MD5 157
|
||||
#define KEY_HMAC_SHA1 158
|
||||
#define UNKNOWN_KEYALG 0
|
||||
#define DST_MAX_ALGS KEY_HMAC_SHA1
|
||||
|
||||
/* DST constants to locations in KEY record changes in new KEY record */
|
||||
#define DST_FLAGS_SIZE 2
|
||||
#define DST_KEY_PROT 2
|
||||
#define DST_KEY_ALG 3
|
||||
#define DST_EXT_FLAG 4
|
||||
#define DST_KEY_START 4
|
||||
|
||||
#ifndef SIGN_F_NOKEY
|
||||
#define SIGN_F_NOKEY 0xC000
|
||||
#endif
|
||||
|
||||
/* error codes from dst routines */
|
||||
#define SIGN_INIT_FAILURE (-23)
|
||||
#define SIGN_UPDATE_FAILURE (-24)
|
||||
#define SIGN_FINAL_FAILURE (-25)
|
||||
#define VERIFY_INIT_FAILURE (-26)
|
||||
#define VERIFY_UPDATE_FAILURE (-27)
|
||||
#define VERIFY_FINAL_FAILURE (-28)
|
||||
#define MISSING_KEY_OR_SIGNATURE (-30)
|
||||
#define UNSUPPORTED_KEYALG (-31)
|
||||
|
||||
#endif /* DST_H */
|
||||
/*! \file */
|
206
libc/upstream-netbsd/lib/libc/include/isc/eventlib.h
Normal file
206
libc/upstream-netbsd/lib/libc/include/isc/eventlib.h
Normal file
@@ -0,0 +1,206 @@
|
||||
/* $NetBSD: eventlib.h,v 1.3 2009/04/12 17:07:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (C) 1995-1999, 2001, 2003 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* eventlib.h - exported interfaces for eventlib
|
||||
* vix 09sep95 [initial]
|
||||
*
|
||||
* Id: eventlib.h,v 1.7 2008/11/14 02:36:51 marka Exp
|
||||
*/
|
||||
|
||||
#ifndef _EVENTLIB_H
|
||||
#define _EVENTLIB_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef __P
|
||||
# define __EVENTLIB_P_DEFINED
|
||||
# ifdef __STDC__
|
||||
# define __P(x) x
|
||||
# else
|
||||
# define __P(x) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* In the absence of branded types... */
|
||||
typedef struct { void *opaque; } evConnID;
|
||||
typedef struct { void *opaque; } evFileID;
|
||||
typedef struct { void *opaque; } evStreamID;
|
||||
typedef struct { void *opaque; } evTimerID;
|
||||
typedef struct { void *opaque; } evWaitID;
|
||||
typedef struct { void *opaque; } evContext;
|
||||
typedef struct { void *opaque; } evEvent;
|
||||
|
||||
#define evInitID(id) ((id)->opaque = NULL)
|
||||
#define evTestID(id) ((id).opaque != NULL)
|
||||
|
||||
typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int,
|
||||
const void *, int));
|
||||
typedef void (*evFileFunc)__P((evContext, void *, int, int));
|
||||
typedef void (*evStreamFunc)__P((evContext, void *, int, int));
|
||||
typedef void (*evTimerFunc)__P((evContext, void *,
|
||||
struct timespec, struct timespec));
|
||||
typedef void (*evWaitFunc)__P((evContext, void *, const void *));
|
||||
|
||||
typedef struct { unsigned char mask[256/8]; } evByteMask;
|
||||
#define EV_BYTEMASK_BYTE(b) ((b) / 8)
|
||||
#define EV_BYTEMASK_MASK(b) (1 << ((b) % 8))
|
||||
#define EV_BYTEMASK_SET(bm, b) \
|
||||
((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b))
|
||||
#define EV_BYTEMASK_CLR(bm, b) \
|
||||
((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b))
|
||||
#define EV_BYTEMASK_TST(bm, b) \
|
||||
((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b))
|
||||
|
||||
#define EV_POLL 1
|
||||
#define EV_WAIT 2
|
||||
#define EV_NULL 4
|
||||
|
||||
#define EV_READ 1
|
||||
#define EV_WRITE 2
|
||||
#define EV_EXCEPT 4
|
||||
|
||||
#define EV_WASNONBLOCKING 8 /* Internal library use. */
|
||||
|
||||
/* eventlib.c */
|
||||
#define evCreate __evCreate
|
||||
#define evSetDebug __evSetDebug
|
||||
#define evDestroy __evDestroy
|
||||
#define evGetNext __evGetNext
|
||||
#define evDispatch __evDispatch
|
||||
#define evDrop __evDrop
|
||||
#define evMainLoop __evMainLoop
|
||||
#define evHighestFD __evHighestFD
|
||||
#define evGetOption __evGetOption
|
||||
#define evSetOption __evSetOption
|
||||
|
||||
int evCreate __P((evContext *));
|
||||
void evSetDebug __P((evContext, int, FILE *));
|
||||
int evDestroy __P((evContext));
|
||||
int evGetNext __P((evContext, evEvent *, int));
|
||||
int evDispatch __P((evContext, evEvent));
|
||||
void evDrop __P((evContext, evEvent));
|
||||
int evMainLoop __P((evContext));
|
||||
int evHighestFD __P((evContext));
|
||||
int evGetOption __P((evContext *, const char *, int *));
|
||||
int evSetOption __P((evContext *, const char *, int));
|
||||
|
||||
/* ev_connects.c */
|
||||
#define evListen __evListen
|
||||
#define evConnect __evConnect
|
||||
#define evCancelConn __evCancelConn
|
||||
#define evHold __evHold
|
||||
#define evUnhold __evUnhold
|
||||
#define evTryAccept __evTryAccept
|
||||
|
||||
int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *));
|
||||
int evConnect __P((evContext, int, const void *, int,
|
||||
evConnFunc, void *, evConnID *));
|
||||
int evCancelConn __P((evContext, evConnID));
|
||||
int evHold __P((evContext, evConnID));
|
||||
int evUnhold __P((evContext, evConnID));
|
||||
int evTryAccept __P((evContext, evConnID, int *));
|
||||
|
||||
/* ev_files.c */
|
||||
#define evSelectFD __evSelectFD
|
||||
#define evDeselectFD __evDeselectFD
|
||||
|
||||
int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *));
|
||||
int evDeselectFD __P((evContext, evFileID));
|
||||
|
||||
/* ev_streams.c */
|
||||
#define evConsIovec __evConsIovec
|
||||
#define evWrite __evWrite
|
||||
#define evRead __evRead
|
||||
#define evTimeRW __evTimeRW
|
||||
#define evUntimeRW __evUntimeRW
|
||||
#define evCancelRW __evCancelRW
|
||||
|
||||
struct iovec evConsIovec __P((void *, size_t));
|
||||
int evWrite __P((evContext, int, const struct iovec *, int,
|
||||
evStreamFunc func, void *, evStreamID *));
|
||||
int evRead __P((evContext, int, const struct iovec *, int,
|
||||
evStreamFunc func, void *, evStreamID *));
|
||||
int evTimeRW __P((evContext, evStreamID, evTimerID timer));
|
||||
int evUntimeRW __P((evContext, evStreamID));
|
||||
int evCancelRW __P((evContext, evStreamID));
|
||||
|
||||
/* ev_timers.c */
|
||||
#define evConsTime __evConsTime
|
||||
#define evAddTime __evAddTime
|
||||
#define evSubTime __evSubTime
|
||||
#define evCmpTime __evCmpTime
|
||||
#define evTimeSpec __evTimeSpec
|
||||
#define evTimeVal __evTimeVal
|
||||
|
||||
#define evNowTime __evNowTime
|
||||
#define evUTCTime __evUTCTime
|
||||
#define evLastEventTime __evLastEventTime
|
||||
#define evSetTimer __evSetTimer
|
||||
#define evClearTimer __evClearTimer
|
||||
#define evConfigTimer __evConfigTimer
|
||||
#define evResetTimer __evResetTimer
|
||||
#define evSetIdleTimer __evSetIdleTimer
|
||||
#define evClearIdleTimer __evClearIdleTimer
|
||||
#define evResetIdleTimer __evResetIdleTimer
|
||||
#define evTouchIdleTimer __evTouchIdleTimer
|
||||
|
||||
struct timespec evConsTime __P((time_t sec, long nsec));
|
||||
struct timespec evAddTime __P((struct timespec, struct timespec));
|
||||
struct timespec evSubTime __P((struct timespec, struct timespec));
|
||||
struct timespec evNowTime __P((void));
|
||||
struct timespec evUTCTime __P((void));
|
||||
struct timespec evLastEventTime __P((evContext));
|
||||
struct timespec evTimeSpec __P((struct timeval));
|
||||
struct timeval evTimeVal __P((struct timespec));
|
||||
int evCmpTime __P((struct timespec, struct timespec));
|
||||
int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec,
|
||||
struct timespec, evTimerID *));
|
||||
int evClearTimer __P((evContext, evTimerID));
|
||||
int evConfigTimer __P((evContext, evTimerID, const char *param,
|
||||
int value));
|
||||
int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *,
|
||||
struct timespec, struct timespec));
|
||||
int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec,
|
||||
evTimerID *));
|
||||
int evClearIdleTimer __P((evContext, evTimerID));
|
||||
int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *,
|
||||
struct timespec));
|
||||
int evTouchIdleTimer __P((evContext, evTimerID));
|
||||
|
||||
/* ev_waits.c */
|
||||
#define evWaitFor __evWaitFor
|
||||
#define evDo __evDo
|
||||
#define evUnwait __evUnwait
|
||||
#define evDefer __evDefer
|
||||
|
||||
int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *));
|
||||
int evDo __P((evContext, const void *));
|
||||
int evUnwait __P((evContext, evWaitID));
|
||||
int evDefer __P((evContext, evWaitFunc, void *));
|
||||
|
||||
#ifdef __EVENTLIB_P_DEFINED
|
||||
# undef __P
|
||||
#endif
|
||||
|
||||
#endif /*_EVENTLIB_H*/
|
||||
|
||||
/*! \file */
|
51
libc/upstream-netbsd/lib/libc/include/isc/heap.h
Normal file
51
libc/upstream-netbsd/lib/libc/include/isc/heap.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* $NetBSD: heap.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1997,1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
typedef int (*heap_higher_priority_func)(void *, void *);
|
||||
typedef void (*heap_index_func)(void *, int);
|
||||
typedef void (*heap_for_each_func)(void *, void *);
|
||||
|
||||
typedef struct heap_context {
|
||||
int array_size;
|
||||
int array_size_increment;
|
||||
int heap_size;
|
||||
void **heap;
|
||||
heap_higher_priority_func higher_priority;
|
||||
heap_index_func index;
|
||||
} *heap_context;
|
||||
|
||||
#define heap_new __heap_new
|
||||
#define heap_free __heap_free
|
||||
#define heap_insert __heap_insert
|
||||
#define heap_delete __heap_delete
|
||||
#define heap_increased __heap_increased
|
||||
#define heap_decreased __heap_decreased
|
||||
#define heap_element __heap_element
|
||||
#define heap_for_each __heap_for_each
|
||||
|
||||
heap_context heap_new(heap_higher_priority_func, heap_index_func, int);
|
||||
int heap_free(heap_context);
|
||||
int heap_insert(heap_context, void *);
|
||||
int heap_delete(heap_context, int);
|
||||
int heap_increased(heap_context, int);
|
||||
int heap_decreased(heap_context, int);
|
||||
void * heap_element(heap_context, int);
|
||||
int heap_for_each(heap_context, heap_for_each_func, void *);
|
||||
|
||||
/*! \file */
|
120
libc/upstream-netbsd/lib/libc/include/isc/list.h
Normal file
120
libc/upstream-netbsd/lib/libc/include/isc/list.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/* $NetBSD: list.h,v 1.5 2009/04/12 17:07:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1997,1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LIST_H
|
||||
#define LIST_H 1
|
||||
#include <isc/assertions.h>
|
||||
|
||||
#define LIST(type) struct { type *head, *tail; }
|
||||
#define INIT_LIST(list) \
|
||||
do { (list).head = NULL; (list).tail = NULL; } while (/*CONSTCOND*/0)
|
||||
|
||||
#define LINK(type) struct { type *prev, *next; }
|
||||
#define INIT_LINK_TYPE(elt, link, type) \
|
||||
do { \
|
||||
(elt)->link.prev = (type *)(-1); \
|
||||
(elt)->link.next = (type *)(-1); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
#define INIT_LINK(elt, link) \
|
||||
INIT_LINK_TYPE(elt, link, void)
|
||||
#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1) && \
|
||||
(void *)((elt)->link.next) != (void *)(-1))
|
||||
|
||||
#define HEAD(list) ((list).head)
|
||||
#define TAIL(list) ((list).tail)
|
||||
#define EMPTY(list) ((list).head == NULL)
|
||||
|
||||
#define PREPEND(list, elt, link) \
|
||||
do { \
|
||||
INSIST(!LINKED(elt, link));\
|
||||
if ((list).head != NULL) \
|
||||
(list).head->link.prev = (elt); \
|
||||
else \
|
||||
(list).tail = (elt); \
|
||||
(elt)->link.prev = NULL; \
|
||||
(elt)->link.next = (list).head; \
|
||||
(list).head = (elt); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define APPEND(list, elt, link) \
|
||||
do { \
|
||||
INSIST(!LINKED(elt, link));\
|
||||
if ((list).tail != NULL) \
|
||||
(list).tail->link.next = (elt); \
|
||||
else \
|
||||
(list).head = (elt); \
|
||||
(elt)->link.prev = (list).tail; \
|
||||
(elt)->link.next = NULL; \
|
||||
(list).tail = (elt); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define UNLINK_TYPE(list, elt, link, type) \
|
||||
do { \
|
||||
INSIST(LINKED(elt, link));\
|
||||
if ((elt)->link.next != NULL) \
|
||||
(elt)->link.next->link.prev = (elt)->link.prev; \
|
||||
else { \
|
||||
INSIST((list).tail == (elt)); \
|
||||
(list).tail = (elt)->link.prev; \
|
||||
} \
|
||||
if ((elt)->link.prev != NULL) \
|
||||
(elt)->link.prev->link.next = (elt)->link.next; \
|
||||
else { \
|
||||
INSIST((list).head == (elt)); \
|
||||
(list).head = (elt)->link.next; \
|
||||
} \
|
||||
INIT_LINK_TYPE(elt, link, type); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
#define UNLINK(list, elt, link) \
|
||||
UNLINK_TYPE(list, elt, link, void)
|
||||
|
||||
#define PREV(elt, link) ((elt)->link.prev)
|
||||
#define NEXT(elt, link) ((elt)->link.next)
|
||||
|
||||
#define INSERT_BEFORE(list, before, elt, link) \
|
||||
do { \
|
||||
INSIST(!LINKED(elt, link));\
|
||||
if ((before)->link.prev == NULL) \
|
||||
PREPEND(list, elt, link); \
|
||||
else { \
|
||||
(elt)->link.prev = (before)->link.prev; \
|
||||
(before)->link.prev = (elt); \
|
||||
(elt)->link.prev->link.next = (elt); \
|
||||
(elt)->link.next = (before); \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define INSERT_AFTER(list, after, elt, link) \
|
||||
do { \
|
||||
INSIST(!LINKED(elt, link));\
|
||||
if ((after)->link.next == NULL) \
|
||||
APPEND(list, elt, link); \
|
||||
else { \
|
||||
(elt)->link.next = (after)->link.next; \
|
||||
(after)->link.next = (elt); \
|
||||
(elt)->link.next->link.prev = (elt); \
|
||||
(elt)->link.prev = (after); \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define ENQUEUE(list, elt, link) APPEND(list, elt, link)
|
||||
#define DEQUEUE(list, elt, link) UNLINK(list, elt, link)
|
||||
|
||||
#endif /* LIST_H */
|
||||
/*! \file */
|
52
libc/upstream-netbsd/lib/libc/include/isc/memcluster.h
Normal file
52
libc/upstream-netbsd/lib/libc/include/isc/memcluster.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* $NetBSD: memcluster.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1997,1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MEMCLUSTER_H
|
||||
#define MEMCLUSTER_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define meminit __meminit
|
||||
#ifdef MEMCLUSTER_DEBUG
|
||||
#define memget(s) __memget_debug(s, __FILE__, __LINE__)
|
||||
#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__)
|
||||
#else /*MEMCLUSTER_DEBUG*/
|
||||
#ifdef MEMCLUSTER_RECORD
|
||||
#define memget(s) __memget_record(s, __FILE__, __LINE__)
|
||||
#define memput(p, s) __memput_record(p, s, __FILE__, __LINE__)
|
||||
#else /*MEMCLUSTER_RECORD*/
|
||||
#define memget __memget
|
||||
#define memput __memput
|
||||
#endif /*MEMCLUSTER_RECORD*/
|
||||
#endif /*MEMCLUSTER_DEBUG*/
|
||||
#define memstats __memstats
|
||||
#define memactive __memactive
|
||||
|
||||
int meminit(size_t, size_t);
|
||||
void * __memget(size_t);
|
||||
void __memput(void *, size_t);
|
||||
void * __memget_debug(size_t, const char *, int);
|
||||
void __memput_debug(void *, size_t, const char *, int);
|
||||
void * __memget_record(size_t, const char *, int);
|
||||
void __memput_record(void *, size_t, const char *, int);
|
||||
void memstats(FILE *);
|
||||
int memactive(void);
|
||||
|
||||
#endif /* MEMCLUSTER_H */
|
||||
/*! \file */
|
64
libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c
Normal file
64
libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* $NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(inet_ntoa,_inet_ntoa)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Convert network-format internet address
|
||||
* to base 256 d.d.d.d representation.
|
||||
*/
|
||||
/*const*/ char *
|
||||
inet_ntoa(struct in_addr in) {
|
||||
static char ret[18];
|
||||
|
||||
strlcpy(ret, "[inet_ntoa error]", sizeof(ret));
|
||||
(void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret);
|
||||
return ret;
|
||||
}
|
232
libc/upstream-netbsd/lib/libc/inet/inet_ntop.c
Normal file
232
libc/upstream-netbsd/lib/libc/inet/inet_ntop.c
Normal file
@@ -0,0 +1,232 @@
|
||||
/* $NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1996-1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "port_before.h"
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(inet_ntop,_inet_ntop)
|
||||
#endif
|
||||
|
||||
/*%
|
||||
* WARNING: Don't even consider trying to compile this on a system where
|
||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||
*/
|
||||
|
||||
static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size);
|
||||
static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
|
||||
|
||||
/* char *
|
||||
* inet_ntop(af, src, dst, size)
|
||||
* convert a network format address to presentation format.
|
||||
* return:
|
||||
* pointer to presentation format address (`dst'), or NULL (see errno).
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
const char *
|
||||
inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
||||
{
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
_DIAGASSERT(dst != NULL);
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return (inet_ntop4(src, dst, size));
|
||||
case AF_INET6:
|
||||
return (inet_ntop6(src, dst, size));
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return (NULL);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* const char *
|
||||
* inet_ntop4(src, dst, size)
|
||||
* format an IPv4 address, more or less like inet_ntoa()
|
||||
* return:
|
||||
* `dst' (as a const)
|
||||
* notes:
|
||||
* (1) uses no statics
|
||||
* (2) takes a u_char* not an in_addr as input
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static const char *
|
||||
inet_ntop4(const u_char *src, char *dst, socklen_t size)
|
||||
{
|
||||
char tmp[sizeof "255.255.255.255"];
|
||||
int l;
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
_DIAGASSERT(dst != NULL);
|
||||
|
||||
l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
|
||||
src[0], src[1], src[2], src[3]);
|
||||
if (l <= 0 || (socklen_t) l >= size) {
|
||||
errno = ENOSPC;
|
||||
return (NULL);
|
||||
}
|
||||
strlcpy(dst, tmp, size);
|
||||
return (dst);
|
||||
}
|
||||
|
||||
/* const char *
|
||||
* inet_ntop6(src, dst, size)
|
||||
* convert IPv6 binary address into presentation (printable) format
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static const char *
|
||||
inet_ntop6(const u_char *src, char *dst, socklen_t size)
|
||||
{
|
||||
/*
|
||||
* Note that int32_t and int16_t need only be "at least" large enough
|
||||
* to contain a value of the specified size. On some systems, like
|
||||
* Crays, there is no such thing as an integer variable with 16 bits.
|
||||
* Keep this in mind if you think this function should have been coded
|
||||
* to use pointer overlays. All the world's not a VAX.
|
||||
*/
|
||||
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
|
||||
char *tp, *ep;
|
||||
struct { int base, len; } best, cur;
|
||||
u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
|
||||
int i;
|
||||
int advance;
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
_DIAGASSERT(dst != NULL);
|
||||
|
||||
/*
|
||||
* Preprocess:
|
||||
* Copy the input (bytewise) array into a wordwise array.
|
||||
* Find the longest run of 0x00's in src[] for :: shorthanding.
|
||||
*/
|
||||
memset(words, '\0', sizeof words);
|
||||
for (i = 0; i < NS_IN6ADDRSZ; i++)
|
||||
words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
|
||||
best.base = -1;
|
||||
best.len = 0;
|
||||
cur.base = -1;
|
||||
cur.len = 0;
|
||||
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
|
||||
if (words[i] == 0) {
|
||||
if (cur.base == -1)
|
||||
cur.base = i, cur.len = 1;
|
||||
else
|
||||
cur.len++;
|
||||
} else {
|
||||
if (cur.base != -1) {
|
||||
if (best.base == -1 || cur.len > best.len)
|
||||
best = cur;
|
||||
cur.base = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cur.base != -1) {
|
||||
if (best.base == -1 || cur.len > best.len)
|
||||
best = cur;
|
||||
}
|
||||
if (best.base != -1 && best.len < 2)
|
||||
best.base = -1;
|
||||
|
||||
/*
|
||||
* Format the result.
|
||||
*/
|
||||
tp = tmp;
|
||||
ep = tmp + sizeof(tmp);
|
||||
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
|
||||
/* Are we inside the best run of 0x00's? */
|
||||
if (best.base != -1 && i >= best.base &&
|
||||
i < (best.base + best.len)) {
|
||||
if (i == best.base)
|
||||
*tp++ = ':';
|
||||
continue;
|
||||
}
|
||||
/* Are we following an initial run of 0x00s or any real hex? */
|
||||
if (i != 0) {
|
||||
if (tp + 1 >= ep)
|
||||
return (NULL);
|
||||
*tp++ = ':';
|
||||
}
|
||||
/* Is this address an encapsulated IPv4? */
|
||||
if (i == 6 && best.base == 0 &&
|
||||
(best.len == 6 ||
|
||||
(best.len == 7 && words[7] != 0x0001) ||
|
||||
(best.len == 5 && words[5] == 0xffff))) {
|
||||
if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
|
||||
return (NULL);
|
||||
tp += strlen(tp);
|
||||
break;
|
||||
}
|
||||
advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
|
||||
if (advance <= 0 || advance >= ep - tp)
|
||||
return (NULL);
|
||||
tp += advance;
|
||||
}
|
||||
/* Was it a trailing run of 0x00's? */
|
||||
if (best.base != -1 && (best.base + best.len) ==
|
||||
(NS_IN6ADDRSZ / NS_INT16SZ)) {
|
||||
if (tp + 1 >= ep)
|
||||
return (NULL);
|
||||
*tp++ = ':';
|
||||
}
|
||||
if (tp + 1 >= ep)
|
||||
return (NULL);
|
||||
*tp++ = '\0';
|
||||
|
||||
/*
|
||||
* Check for overflow, copy, and we're done.
|
||||
*/
|
||||
if ((size_t)(tp - tmp) > size) {
|
||||
errno = ENOSPC;
|
||||
return (NULL);
|
||||
}
|
||||
strlcpy(dst, tmp, size);
|
||||
return (dst);
|
||||
}
|
||||
|
||||
/*! \file */
|
310
libc/upstream-netbsd/lib/libc/inet/inet_pton.c
Normal file
310
libc/upstream-netbsd/lib/libc/inet/inet_pton.c
Normal file
@@ -0,0 +1,310 @@
|
||||
/* $NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "port_before.h"
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(inet_pton,_inet_pton)
|
||||
#endif
|
||||
|
||||
/*%
|
||||
* WARNING: Don't even consider trying to compile this on a system where
|
||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||
*/
|
||||
|
||||
static int inet_pton4(const char *src, u_char *dst, int pton);
|
||||
static int inet_pton6(const char *src, u_char *dst);
|
||||
|
||||
/* int
|
||||
* inet_pton(af, src, dst)
|
||||
* convert from presentation format (which usually means ASCII printable)
|
||||
* to network format (which is usually some kind of binary format).
|
||||
* return:
|
||||
* 1 if the address was valid for the specified address family
|
||||
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
||||
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
int
|
||||
inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
_DIAGASSERT(dst != NULL);
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return (inet_pton4(src, dst, 1));
|
||||
case AF_INET6:
|
||||
return (inet_pton6(src, dst));
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return (-1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* int
|
||||
* inet_pton4(src, dst, pton)
|
||||
* when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand.
|
||||
* when last arg is 1: inet_pton(). decimal dotted-quad only.
|
||||
* return:
|
||||
* 1 if `src' is a valid input, else 0.
|
||||
* notice:
|
||||
* does not touch `dst' unless it's returning 1.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static int
|
||||
inet_pton4(const char *src, u_char *dst, int pton)
|
||||
{
|
||||
u_int32_t val;
|
||||
u_int digit, base;
|
||||
ptrdiff_t n;
|
||||
unsigned char c;
|
||||
u_int parts[4];
|
||||
u_int *pp = parts;
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
_DIAGASSERT(dst != NULL);
|
||||
|
||||
c = *src;
|
||||
for (;;) {
|
||||
/*
|
||||
* Collect number up to ``.''.
|
||||
* Values are specified as for C:
|
||||
* 0x=hex, 0=octal, isdigit=decimal.
|
||||
*/
|
||||
if (!isdigit(c))
|
||||
return (0);
|
||||
val = 0; base = 10;
|
||||
if (c == '0') {
|
||||
c = *++src;
|
||||
if (c == 'x' || c == 'X')
|
||||
base = 16, c = *++src;
|
||||
else if (isdigit(c) && c != '9')
|
||||
base = 8;
|
||||
}
|
||||
/* inet_pton() takes decimal only */
|
||||
if (pton && base != 10)
|
||||
return (0);
|
||||
for (;;) {
|
||||
if (isdigit(c)) {
|
||||
digit = c - '0';
|
||||
if (digit >= base)
|
||||
break;
|
||||
val = (val * base) + digit;
|
||||
c = *++src;
|
||||
} else if (base == 16 && isxdigit(c)) {
|
||||
digit = c + 10 - (islower(c) ? 'a' : 'A');
|
||||
if (digit >= 16)
|
||||
break;
|
||||
val = (val << 4) | digit;
|
||||
c = *++src;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (c == '.') {
|
||||
/*
|
||||
* Internet format:
|
||||
* a.b.c.d
|
||||
* a.b.c (with c treated as 16 bits)
|
||||
* a.b (with b treated as 24 bits)
|
||||
* a (with a treated as 32 bits)
|
||||
*/
|
||||
if (pp >= parts + 3)
|
||||
return (0);
|
||||
*pp++ = val;
|
||||
c = *++src;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check for trailing characters.
|
||||
*/
|
||||
if (c != '\0' && !isspace(c))
|
||||
return (0);
|
||||
/*
|
||||
* Concoct the address according to
|
||||
* the number of parts specified.
|
||||
*/
|
||||
n = pp - parts + 1;
|
||||
/* inet_pton() takes dotted-quad only. it does not take shorthand. */
|
||||
if (pton && n != 4)
|
||||
return (0);
|
||||
switch (n) {
|
||||
|
||||
case 0:
|
||||
return (0); /* initial nondigit */
|
||||
|
||||
case 1: /* a -- 32 bits */
|
||||
break;
|
||||
|
||||
case 2: /* a.b -- 8.24 bits */
|
||||
if (parts[0] > 0xff || val > 0xffffff)
|
||||
return (0);
|
||||
val |= parts[0] << 24;
|
||||
break;
|
||||
|
||||
case 3: /* a.b.c -- 8.8.16 bits */
|
||||
if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||
break;
|
||||
|
||||
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||
if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if (dst) {
|
||||
val = htonl(val);
|
||||
memcpy(dst, &val, NS_INADDRSZ);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* int
|
||||
* inet_pton6(src, dst)
|
||||
* convert presentation level address to network order binary form.
|
||||
* return:
|
||||
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
||||
* notice:
|
||||
* (1) does not touch `dst' unless it's returning 1.
|
||||
* (2) :: in a full address is silently ignored.
|
||||
* credit:
|
||||
* inspired by Mark Andrews.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static int
|
||||
inet_pton6(const char *src, u_char *dst)
|
||||
{
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, seen_xdigits;
|
||||
u_int val;
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
_DIAGASSERT(dst != NULL);
|
||||
|
||||
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
||||
endp = tp + NS_IN6ADDRSZ;
|
||||
colonp = NULL;
|
||||
/* Leading :: requires some special handling. */
|
||||
if (*src == ':')
|
||||
if (*++src != ':')
|
||||
return (0);
|
||||
curtok = src;
|
||||
seen_xdigits = 0;
|
||||
val = 0;
|
||||
while ((ch = *src++) != '\0') {
|
||||
const char *pch;
|
||||
|
||||
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||
pch = strchr((xdigits = xdigits_u), ch);
|
||||
if (pch != NULL) {
|
||||
val <<= 4;
|
||||
val |= (int)(pch - xdigits);
|
||||
if (++seen_xdigits > 4)
|
||||
return (0);
|
||||
continue;
|
||||
}
|
||||
if (ch == ':') {
|
||||
curtok = src;
|
||||
if (!seen_xdigits) {
|
||||
if (colonp)
|
||||
return (0);
|
||||
colonp = tp;
|
||||
continue;
|
||||
} else if (*src == '\0')
|
||||
return (0);
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||
*tp++ = (u_char) val & 0xff;
|
||||
seen_xdigits = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
||||
inet_pton4(curtok, tp, 1) > 0) {
|
||||
tp += NS_INADDRSZ;
|
||||
seen_xdigits = 0;
|
||||
break; /*%< '\\0' was seen by inet_pton4(). */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (seen_xdigits) {
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||
*tp++ = (u_char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL) {
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
const ptrdiff_t n = tp - colonp;
|
||||
int i;
|
||||
|
||||
if (tp == endp)
|
||||
return (0);
|
||||
for (i = 1; i <= n; i++) {
|
||||
endp[- i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
if (tp != endp)
|
||||
return (0);
|
||||
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*! \file */
|
319
libc/upstream-netbsd/lib/libc/isc/ev_streams.c
Normal file
319
libc/upstream-netbsd/lib/libc/isc/ev_streams.c
Normal file
@@ -0,0 +1,319 @@
|
||||
/* $NetBSD: ev_streams.c,v 1.6 2009/04/12 17:07:17 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1996-1999 by Internet Software Consortium
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* ev_streams.c - implement asynch stream file IO for the eventlib
|
||||
* vix 04mar96 [initial]
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(LINT) && !defined(CODECENTER) && !defined(lint)
|
||||
#ifdef notdef
|
||||
static const char rcsid[] = "Id: ev_streams.c,v 1.5 2005/04/27 04:56:36 sra Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: ev_streams.c,v 1.6 2009/04/12 17:07:17 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "port_before.h"
|
||||
#include "fd_setsize.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <isc/eventlib.h>
|
||||
#include <isc/assertions.h>
|
||||
#include "eventlib_p.h"
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
#ifndef _LIBC
|
||||
static int copyvec(evStream *str, const struct iovec *iov, int iocnt);
|
||||
static void consume(evStream *str, size_t bytes);
|
||||
static void done(evContext opaqueCtx, evStream *str);
|
||||
static void writable(evContext opaqueCtx, void *uap, int fd, int evmask);
|
||||
static void readable(evContext opaqueCtx, void *uap, int fd, int evmask);
|
||||
#endif
|
||||
|
||||
struct iovec
|
||||
evConsIovec(void *buf, size_t cnt) {
|
||||
struct iovec ret;
|
||||
|
||||
memset(&ret, 0xf5, sizeof ret);
|
||||
ret.iov_base = buf;
|
||||
ret.iov_len = cnt;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
int
|
||||
evWrite(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt,
|
||||
evStreamFunc func, void *uap, evStreamID *id)
|
||||
{
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evStream *new;
|
||||
int save;
|
||||
|
||||
OKNEW(new);
|
||||
new->func = func;
|
||||
new->uap = uap;
|
||||
new->fd = fd;
|
||||
new->flags = 0;
|
||||
if (evSelectFD(opaqueCtx, fd, EV_WRITE, writable, new, &new->file) < 0)
|
||||
goto free;
|
||||
if (copyvec(new, iov, iocnt) < 0)
|
||||
goto free;
|
||||
new->prevDone = NULL;
|
||||
new->nextDone = NULL;
|
||||
if (ctx->streams != NULL)
|
||||
ctx->streams->prev = new;
|
||||
new->prev = NULL;
|
||||
new->next = ctx->streams;
|
||||
ctx->streams = new;
|
||||
if (id != NULL)
|
||||
id->opaque = new;
|
||||
return (0);
|
||||
free:
|
||||
save = errno;
|
||||
FREE(new);
|
||||
errno = save;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
evRead(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt,
|
||||
evStreamFunc func, void *uap, evStreamID *id)
|
||||
{
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evStream *new;
|
||||
int save;
|
||||
|
||||
OKNEW(new);
|
||||
new->func = func;
|
||||
new->uap = uap;
|
||||
new->fd = fd;
|
||||
new->flags = 0;
|
||||
if (evSelectFD(opaqueCtx, fd, EV_READ, readable, new, &new->file) < 0)
|
||||
goto free;
|
||||
if (copyvec(new, iov, iocnt) < 0)
|
||||
goto free;
|
||||
new->prevDone = NULL;
|
||||
new->nextDone = NULL;
|
||||
if (ctx->streams != NULL)
|
||||
ctx->streams->prev = new;
|
||||
new->prev = NULL;
|
||||
new->next = ctx->streams;
|
||||
ctx->streams = new;
|
||||
if (id)
|
||||
id->opaque = new;
|
||||
return (0);
|
||||
free:
|
||||
save = errno;
|
||||
FREE(new);
|
||||
errno = save;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
evTimeRW(evContext opaqueCtx, evStreamID id, evTimerID timer) /*ARGSUSED*/ {
|
||||
evStream *str = id.opaque;
|
||||
|
||||
UNUSED(opaqueCtx);
|
||||
|
||||
str->timer = timer;
|
||||
str->flags |= EV_STR_TIMEROK;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
evUntimeRW(evContext opaqueCtx, evStreamID id) /*ARGSUSED*/ {
|
||||
evStream *str = id.opaque;
|
||||
|
||||
UNUSED(opaqueCtx);
|
||||
|
||||
str->flags &= ~EV_STR_TIMEROK;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
evCancelRW(evContext opaqueCtx, evStreamID id) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evStream *old = id.opaque;
|
||||
|
||||
/*
|
||||
* The streams list is doubly threaded. First, there's ctx->streams
|
||||
* that's used by evDestroy() to find and cancel all streams. Second,
|
||||
* there's ctx->strDone (head) and ctx->strLast (tail) which thread
|
||||
* through the potentially smaller number of "IO completed" streams,
|
||||
* used in evGetNext() to avoid scanning the entire list.
|
||||
*/
|
||||
|
||||
/* Unlink from ctx->streams. */
|
||||
if (old->prev != NULL)
|
||||
old->prev->next = old->next;
|
||||
else
|
||||
ctx->streams = old->next;
|
||||
if (old->next != NULL)
|
||||
old->next->prev = old->prev;
|
||||
|
||||
/*
|
||||
* If 'old' is on the ctx->strDone list, remove it. Update
|
||||
* ctx->strLast if necessary.
|
||||
*/
|
||||
if (old->prevDone == NULL && old->nextDone == NULL) {
|
||||
/*
|
||||
* Either 'old' is the only item on the done list, or it's
|
||||
* not on the done list. If the former, then we unlink it
|
||||
* from the list. If the latter, we leave the list alone.
|
||||
*/
|
||||
if (ctx->strDone == old) {
|
||||
ctx->strDone = NULL;
|
||||
ctx->strLast = NULL;
|
||||
}
|
||||
} else {
|
||||
if (old->prevDone != NULL)
|
||||
old->prevDone->nextDone = old->nextDone;
|
||||
else
|
||||
ctx->strDone = old->nextDone;
|
||||
if (old->nextDone != NULL)
|
||||
old->nextDone->prevDone = old->prevDone;
|
||||
else
|
||||
ctx->strLast = old->prevDone;
|
||||
}
|
||||
|
||||
/* Deallocate the stream. */
|
||||
if (old->file.opaque)
|
||||
evDeselectFD(opaqueCtx, old->file);
|
||||
memput(old->iovOrig, sizeof (struct iovec) * old->iovOrigCount);
|
||||
FREE(old);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Copy a scatter/gather vector and initialize a stream handler's IO. */
|
||||
static int
|
||||
copyvec(evStream *str, const struct iovec *iov, int iocnt) {
|
||||
int i;
|
||||
|
||||
str->iovOrig = (struct iovec *)memget(sizeof(struct iovec) * iocnt);
|
||||
if (str->iovOrig == NULL) {
|
||||
errno = ENOMEM;
|
||||
return (-1);
|
||||
}
|
||||
str->ioTotal = 0;
|
||||
for (i = 0; i < iocnt; i++) {
|
||||
str->iovOrig[i] = iov[i];
|
||||
str->ioTotal += iov[i].iov_len;
|
||||
}
|
||||
str->iovOrigCount = iocnt;
|
||||
str->iovCur = str->iovOrig;
|
||||
str->iovCurCount = str->iovOrigCount;
|
||||
str->ioDone = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Pull off or truncate lead iovec(s). */
|
||||
static void
|
||||
consume(evStream *str, size_t bytes) {
|
||||
while (bytes > 0U) {
|
||||
if (bytes < (size_t)str->iovCur->iov_len) {
|
||||
str->iovCur->iov_len -= bytes;
|
||||
str->iovCur->iov_base = (void *)
|
||||
((u_char *)str->iovCur->iov_base + bytes);
|
||||
str->ioDone += bytes;
|
||||
bytes = 0;
|
||||
} else {
|
||||
bytes -= str->iovCur->iov_len;
|
||||
str->ioDone += str->iovCur->iov_len;
|
||||
str->iovCur++;
|
||||
str->iovCurCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a stream to Done list and deselect the FD. */
|
||||
static void
|
||||
done(evContext opaqueCtx, evStream *str) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
|
||||
if (ctx->strLast != NULL) {
|
||||
str->prevDone = ctx->strLast;
|
||||
ctx->strLast->nextDone = str;
|
||||
ctx->strLast = str;
|
||||
} else {
|
||||
INSIST(ctx->strDone == NULL);
|
||||
ctx->strDone = ctx->strLast = str;
|
||||
}
|
||||
evDeselectFD(opaqueCtx, str->file);
|
||||
str->file.opaque = NULL;
|
||||
/* evDrop() will call evCancelRW() on us. */
|
||||
}
|
||||
|
||||
/* Dribble out some bytes on the stream. (Called by evDispatch().) */
|
||||
static void
|
||||
writable(evContext opaqueCtx, void *uap, int fd, int evmask) {
|
||||
evStream *str = uap;
|
||||
int bytes;
|
||||
|
||||
UNUSED(evmask);
|
||||
|
||||
bytes = writev(fd, str->iovCur, str->iovCurCount);
|
||||
if (bytes > 0) {
|
||||
if ((str->flags & EV_STR_TIMEROK) != 0)
|
||||
evTouchIdleTimer(opaqueCtx, str->timer);
|
||||
consume(str, bytes);
|
||||
} else {
|
||||
if (bytes < 0 && errno != EINTR) {
|
||||
str->ioDone = -1;
|
||||
str->ioErrno = errno;
|
||||
}
|
||||
}
|
||||
if (str->ioDone == -1 || str->ioDone == str->ioTotal)
|
||||
done(opaqueCtx, str);
|
||||
}
|
||||
|
||||
/* Scoop up some bytes from the stream. (Called by evDispatch().) */
|
||||
static void
|
||||
readable(evContext opaqueCtx, void *uap, int fd, int evmask) {
|
||||
evStream *str = uap;
|
||||
int bytes;
|
||||
|
||||
UNUSED(evmask);
|
||||
|
||||
bytes = readv(fd, str->iovCur, str->iovCurCount);
|
||||
if (bytes > 0) {
|
||||
if ((str->flags & EV_STR_TIMEROK) != 0)
|
||||
evTouchIdleTimer(opaqueCtx, str->timer);
|
||||
consume(str, bytes);
|
||||
} else {
|
||||
if (bytes == 0)
|
||||
str->ioDone = 0;
|
||||
else {
|
||||
if (errno != EINTR) {
|
||||
str->ioDone = -1;
|
||||
str->ioErrno = errno;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (str->ioDone <= 0 || str->ioDone == str->ioTotal)
|
||||
done(opaqueCtx, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! \file */
|
519
libc/upstream-netbsd/lib/libc/isc/ev_timers.c
Normal file
519
libc/upstream-netbsd/lib/libc/isc/ev_timers.c
Normal file
@@ -0,0 +1,519 @@
|
||||
/* $NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1995-1999 by Internet Software Consortium
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* ev_timers.c - implement timers for the eventlib
|
||||
* vix 09sep95 [initial]
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(LINT) && !defined(CODECENTER) && !defined(lint)
|
||||
#ifdef notdef
|
||||
static const char rcsid[] = "Id: ev_timers.c,v 1.6 2005/04/27 04:56:36 sra Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Import. */
|
||||
|
||||
#include "port_before.h"
|
||||
#include "fd_setsize.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <isc/assertions.h>
|
||||
#include <isc/eventlib.h>
|
||||
#include "eventlib_p.h"
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
/* Constants. */
|
||||
|
||||
#define MILLION 1000000
|
||||
#define BILLION 1000000000
|
||||
|
||||
/* Forward. */
|
||||
|
||||
#ifndef _LIBC
|
||||
static int due_sooner(void *, void *);
|
||||
static void set_index(void *, int);
|
||||
static void free_timer(void *, void *);
|
||||
static void print_timer(void *, void *);
|
||||
static void idle_timeout(evContext, void *, struct timespec, struct timespec);
|
||||
|
||||
/* Private type. */
|
||||
|
||||
typedef struct {
|
||||
evTimerFunc func;
|
||||
void * uap;
|
||||
struct timespec lastTouched;
|
||||
struct timespec max_idle;
|
||||
evTimer * timer;
|
||||
} idle_timer;
|
||||
#endif
|
||||
|
||||
/* Public. */
|
||||
|
||||
struct timespec
|
||||
evConsTime(time_t sec, long nsec) {
|
||||
struct timespec x;
|
||||
|
||||
x.tv_sec = sec;
|
||||
x.tv_nsec = nsec;
|
||||
return (x);
|
||||
}
|
||||
|
||||
struct timespec
|
||||
evAddTime(struct timespec addend1, struct timespec addend2) {
|
||||
struct timespec x;
|
||||
|
||||
x.tv_sec = addend1.tv_sec + addend2.tv_sec;
|
||||
x.tv_nsec = addend1.tv_nsec + addend2.tv_nsec;
|
||||
if (x.tv_nsec >= BILLION) {
|
||||
x.tv_sec++;
|
||||
x.tv_nsec -= BILLION;
|
||||
}
|
||||
return (x);
|
||||
}
|
||||
|
||||
struct timespec
|
||||
evSubTime(struct timespec minuend, struct timespec subtrahend) {
|
||||
struct timespec x;
|
||||
|
||||
x.tv_sec = minuend.tv_sec - subtrahend.tv_sec;
|
||||
if (minuend.tv_nsec >= subtrahend.tv_nsec)
|
||||
x.tv_nsec = minuend.tv_nsec - subtrahend.tv_nsec;
|
||||
else {
|
||||
x.tv_nsec = BILLION - subtrahend.tv_nsec + minuend.tv_nsec;
|
||||
x.tv_sec--;
|
||||
}
|
||||
return (x);
|
||||
}
|
||||
|
||||
int
|
||||
evCmpTime(struct timespec a, struct timespec b) {
|
||||
#define SGN(x) ((x) < 0 ? (-1) : (x) > 0 ? (1) : (0));
|
||||
time_t s = a.tv_sec - b.tv_sec;
|
||||
long n;
|
||||
|
||||
if (s != 0)
|
||||
return SGN(s);
|
||||
|
||||
n = a.tv_nsec - b.tv_nsec;
|
||||
return SGN(n);
|
||||
}
|
||||
|
||||
struct timespec
|
||||
evNowTime(void)
|
||||
{
|
||||
struct timeval now;
|
||||
#ifdef CLOCK_REALTIME
|
||||
struct timespec tsnow;
|
||||
int m = CLOCK_REALTIME;
|
||||
|
||||
#ifdef CLOCK_MONOTONIC
|
||||
#ifndef _LIBC
|
||||
if (__evOptMonoTime)
|
||||
m = CLOCK_MONOTONIC;
|
||||
#endif
|
||||
#endif
|
||||
if (clock_gettime(m, &tsnow) == 0)
|
||||
return (tsnow);
|
||||
#endif
|
||||
if (gettimeofday(&now, NULL) < 0)
|
||||
return (evConsTime((time_t)0, 0L));
|
||||
return (evTimeSpec(now));
|
||||
}
|
||||
|
||||
struct timespec
|
||||
evUTCTime(void) {
|
||||
struct timeval now;
|
||||
#ifdef CLOCK_REALTIME
|
||||
struct timespec tsnow;
|
||||
if (clock_gettime(CLOCK_REALTIME, &tsnow) == 0)
|
||||
return (tsnow);
|
||||
#endif
|
||||
if (gettimeofday(&now, NULL) < 0)
|
||||
return (evConsTime((time_t)0, 0L));
|
||||
return (evTimeSpec(now));
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
struct timespec
|
||||
evLastEventTime(evContext opaqueCtx) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
|
||||
return (ctx->lastEventTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct timespec
|
||||
evTimeSpec(struct timeval tv) {
|
||||
struct timespec ts;
|
||||
|
||||
ts.tv_sec = tv.tv_sec;
|
||||
ts.tv_nsec = tv.tv_usec * 1000;
|
||||
return (ts);
|
||||
}
|
||||
|
||||
struct timeval
|
||||
evTimeVal(struct timespec ts) {
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = ts.tv_sec;
|
||||
tv.tv_usec = (suseconds_t)(ts.tv_nsec / 1000);
|
||||
return (tv);
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
int
|
||||
evSetTimer(evContext opaqueCtx,
|
||||
evTimerFunc func,
|
||||
void *uap,
|
||||
struct timespec due,
|
||||
struct timespec inter,
|
||||
evTimerID *opaqueID
|
||||
) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evTimer *id;
|
||||
|
||||
evPrintf(ctx, 1,
|
||||
"evSetTimer(ctx %p, func %p, uap %p, due %ld.%09ld, inter %ld.%09ld)\n",
|
||||
ctx, func, uap,
|
||||
(long)due.tv_sec, due.tv_nsec,
|
||||
(long)inter.tv_sec, inter.tv_nsec);
|
||||
|
||||
#ifdef __hpux
|
||||
/*
|
||||
* tv_sec and tv_nsec are unsigned.
|
||||
*/
|
||||
if (due.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
|
||||
if (inter.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
#else
|
||||
if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
|
||||
if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
#endif
|
||||
|
||||
/* due={0,0} is a magic cookie meaning "now." */
|
||||
if (due.tv_sec == (time_t)0 && due.tv_nsec == 0L)
|
||||
due = evNowTime();
|
||||
|
||||
/* Allocate and fill. */
|
||||
OKNEW(id);
|
||||
id->func = func;
|
||||
id->uap = uap;
|
||||
id->due = due;
|
||||
id->inter = inter;
|
||||
|
||||
if (heap_insert(ctx->timers, id) < 0)
|
||||
return (-1);
|
||||
|
||||
/* Remember the ID if the caller provided us a place for it. */
|
||||
if (opaqueID)
|
||||
opaqueID->opaque = id;
|
||||
|
||||
if (ctx->debug > 7) {
|
||||
evPrintf(ctx, 7, "timers after evSetTimer:\n");
|
||||
(void) heap_for_each(ctx->timers, print_timer, (void *)ctx);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
evClearTimer(evContext opaqueCtx, evTimerID id) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evTimer *del = id.opaque;
|
||||
|
||||
if (ctx->cur != NULL &&
|
||||
ctx->cur->type == Timer &&
|
||||
ctx->cur->u.timer.this == del) {
|
||||
evPrintf(ctx, 8, "deferring delete of timer (executing)\n");
|
||||
/*
|
||||
* Setting the interval to zero ensures that evDrop() will
|
||||
* clean up the timer.
|
||||
*/
|
||||
del->inter = evConsTime(0, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (heap_element(ctx->timers, del->index) != del)
|
||||
EV_ERR(ENOENT);
|
||||
|
||||
if (heap_delete(ctx->timers, del->index) < 0)
|
||||
return (-1);
|
||||
FREE(del);
|
||||
|
||||
if (ctx->debug > 7) {
|
||||
evPrintf(ctx, 7, "timers after evClearTimer:\n");
|
||||
(void) heap_for_each(ctx->timers, print_timer, (void *)ctx);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
evConfigTimer(evContext opaqueCtx,
|
||||
evTimerID id,
|
||||
const char *param,
|
||||
int value
|
||||
) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evTimer *timer = id.opaque;
|
||||
int result=0;
|
||||
|
||||
UNUSED(value);
|
||||
|
||||
if (heap_element(ctx->timers, timer->index) != timer)
|
||||
EV_ERR(ENOENT);
|
||||
|
||||
if (strcmp(param, "rate") == 0)
|
||||
timer->mode |= EV_TMR_RATE;
|
||||
else if (strcmp(param, "interval") == 0)
|
||||
timer->mode &= ~EV_TMR_RATE;
|
||||
else
|
||||
EV_ERR(EINVAL);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
int
|
||||
evResetTimer(evContext opaqueCtx,
|
||||
evTimerID id,
|
||||
evTimerFunc func,
|
||||
void *uap,
|
||||
struct timespec due,
|
||||
struct timespec inter
|
||||
) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evTimer *timer = id.opaque;
|
||||
struct timespec old_due;
|
||||
int result=0;
|
||||
|
||||
if (heap_element(ctx->timers, timer->index) != timer)
|
||||
EV_ERR(ENOENT);
|
||||
|
||||
#ifdef __hpux
|
||||
/*
|
||||
* tv_sec and tv_nsec are unsigned.
|
||||
*/
|
||||
if (due.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
|
||||
if (inter.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
#else
|
||||
if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
|
||||
if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION)
|
||||
EV_ERR(EINVAL);
|
||||
#endif
|
||||
|
||||
old_due = timer->due;
|
||||
|
||||
timer->func = func;
|
||||
timer->uap = uap;
|
||||
timer->due = due;
|
||||
timer->inter = inter;
|
||||
|
||||
switch (evCmpTime(due, old_due)) {
|
||||
case -1:
|
||||
result = heap_increased(ctx->timers, timer->index);
|
||||
break;
|
||||
case 0:
|
||||
result = 0;
|
||||
break;
|
||||
case 1:
|
||||
result = heap_decreased(ctx->timers, timer->index);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ctx->debug > 7) {
|
||||
evPrintf(ctx, 7, "timers after evResetTimer:\n");
|
||||
(void) heap_for_each(ctx->timers, print_timer, (void *)ctx);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
int
|
||||
evSetIdleTimer(evContext opaqueCtx,
|
||||
evTimerFunc func,
|
||||
void *uap,
|
||||
struct timespec max_idle,
|
||||
evTimerID *opaqueID
|
||||
) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
idle_timer *tt;
|
||||
|
||||
/* Allocate and fill. */
|
||||
OKNEW(tt);
|
||||
tt->func = func;
|
||||
tt->uap = uap;
|
||||
tt->lastTouched = ctx->lastEventTime;
|
||||
tt->max_idle = max_idle;
|
||||
|
||||
if (evSetTimer(opaqueCtx, idle_timeout, tt,
|
||||
evAddTime(ctx->lastEventTime, max_idle),
|
||||
max_idle, opaqueID) < 0) {
|
||||
FREE(tt);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
tt->timer = opaqueID->opaque;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
evClearIdleTimer(evContext opaqueCtx, evTimerID id) {
|
||||
evTimer *del = id.opaque;
|
||||
idle_timer *tt = del->uap;
|
||||
|
||||
FREE(tt);
|
||||
return (evClearTimer(opaqueCtx, id));
|
||||
}
|
||||
|
||||
int
|
||||
evResetIdleTimer(evContext opaqueCtx,
|
||||
evTimerID opaqueID,
|
||||
evTimerFunc func,
|
||||
void *uap,
|
||||
struct timespec max_idle
|
||||
) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evTimer *timer = opaqueID.opaque;
|
||||
idle_timer *tt = timer->uap;
|
||||
|
||||
tt->func = func;
|
||||
tt->uap = uap;
|
||||
tt->lastTouched = ctx->lastEventTime;
|
||||
tt->max_idle = max_idle;
|
||||
|
||||
return (evResetTimer(opaqueCtx, opaqueID, idle_timeout, tt,
|
||||
evAddTime(ctx->lastEventTime, max_idle),
|
||||
max_idle));
|
||||
}
|
||||
|
||||
int
|
||||
evTouchIdleTimer(evContext opaqueCtx, evTimerID id) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
evTimer *t = id.opaque;
|
||||
idle_timer *tt = t->uap;
|
||||
|
||||
tt->lastTouched = ctx->lastEventTime;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Public to the rest of eventlib. */
|
||||
|
||||
heap_context
|
||||
evCreateTimers(const evContext_p *ctx) {
|
||||
|
||||
UNUSED(ctx);
|
||||
|
||||
return (heap_new(due_sooner, set_index, 2048));
|
||||
}
|
||||
|
||||
void
|
||||
evDestroyTimers(const evContext_p *ctx) {
|
||||
(void) heap_for_each(ctx->timers, free_timer, NULL);
|
||||
(void) heap_free(ctx->timers);
|
||||
}
|
||||
|
||||
/* Private. */
|
||||
|
||||
static int
|
||||
due_sooner(void *a, void *b) {
|
||||
evTimer *a_timer, *b_timer;
|
||||
|
||||
a_timer = a;
|
||||
b_timer = b;
|
||||
return (evCmpTime(a_timer->due, b_timer->due) < 0);
|
||||
}
|
||||
|
||||
static void
|
||||
set_index(void *what, int idx) {
|
||||
evTimer *timer;
|
||||
|
||||
timer = what;
|
||||
timer->index = idx;
|
||||
}
|
||||
|
||||
static void
|
||||
free_timer(void *what, void *uap) {
|
||||
evTimer *t = what;
|
||||
|
||||
UNUSED(uap);
|
||||
|
||||
FREE(t);
|
||||
}
|
||||
|
||||
static void
|
||||
print_timer(void *what, void *uap) {
|
||||
evTimer *cur = what;
|
||||
evContext_p *ctx = uap;
|
||||
|
||||
cur = what;
|
||||
evPrintf(ctx, 7,
|
||||
" func %p, uap %p, due %ld.%09ld, inter %ld.%09ld\n",
|
||||
cur->func, cur->uap,
|
||||
(long)cur->due.tv_sec, cur->due.tv_nsec,
|
||||
(long)cur->inter.tv_sec, cur->inter.tv_nsec);
|
||||
}
|
||||
|
||||
static void
|
||||
idle_timeout(evContext opaqueCtx,
|
||||
void *uap,
|
||||
struct timespec due,
|
||||
struct timespec inter
|
||||
) {
|
||||
evContext_p *ctx = opaqueCtx.opaque;
|
||||
idle_timer *this = uap;
|
||||
struct timespec idle;
|
||||
|
||||
UNUSED(due);
|
||||
UNUSED(inter);
|
||||
|
||||
idle = evSubTime(ctx->lastEventTime, this->lastTouched);
|
||||
if (evCmpTime(idle, this->max_idle) >= 0) {
|
||||
(this->func)(opaqueCtx, this->uap, this->timer->due,
|
||||
this->max_idle);
|
||||
/*
|
||||
* Setting the interval to zero will cause the timer to
|
||||
* be cleaned up in evDrop().
|
||||
*/
|
||||
this->timer->inter = evConsTime(0L, 0L);
|
||||
FREE(this);
|
||||
} else {
|
||||
/* evDrop() will reschedule the timer. */
|
||||
this->timer->inter = evSubTime(this->max_idle, idle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! \file */
|
283
libc/upstream-netbsd/lib/libc/isc/eventlib_p.h
Normal file
283
libc/upstream-netbsd/lib/libc/isc/eventlib_p.h
Normal file
@@ -0,0 +1,283 @@
|
||||
/* $NetBSD: eventlib_p.h,v 1.3 2009/04/12 17:07:17 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1995-1999 by Internet Software Consortium
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief private interfaces for eventlib
|
||||
* \author vix 09sep95 [initial]
|
||||
*
|
||||
* Id: eventlib_p.h,v 1.9 2006/03/09 23:57:56 marka Exp
|
||||
*/
|
||||
|
||||
#ifndef _EVENTLIB_P_H
|
||||
#define _EVENTLIB_P_H
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#define EVENTLIB_DEBUG 1
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/heap.h>
|
||||
#include <isc/list.h>
|
||||
#include <isc/memcluster.h>
|
||||
|
||||
#define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
|
||||
#define EV_ERR(e) return (errno = (e), -1)
|
||||
#define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
|
||||
#define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \
|
||||
else (void)NULL
|
||||
|
||||
#define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
|
||||
FILL(p); \
|
||||
else \
|
||||
(void)NULL;
|
||||
#define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
|
||||
errno = ENOMEM; \
|
||||
return (-1); \
|
||||
} else \
|
||||
FILL(p)
|
||||
#define FREE(p) memput((p), sizeof *(p))
|
||||
|
||||
#if EVENTLIB_DEBUG
|
||||
#define FILL(p) memset((p), 0xF5, sizeof *(p))
|
||||
#else
|
||||
#define FILL(p)
|
||||
#endif
|
||||
|
||||
#ifdef USE_POLL
|
||||
#ifdef HAVE_STROPTS_H
|
||||
#include <stropts.h>
|
||||
#endif
|
||||
#include <poll.h>
|
||||
#endif /* USE_POLL */
|
||||
|
||||
typedef struct evConn {
|
||||
evConnFunc func;
|
||||
void * uap;
|
||||
int fd;
|
||||
int flags;
|
||||
#define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */
|
||||
#define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */
|
||||
#define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */
|
||||
evFileID file;
|
||||
struct evConn * prev;
|
||||
struct evConn * next;
|
||||
} evConn;
|
||||
|
||||
typedef struct evAccept {
|
||||
int fd;
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in in;
|
||||
#ifndef NO_SOCKADDR_UN
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
} la;
|
||||
ISC_SOCKLEN_T lalen;
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in in;
|
||||
#ifndef NO_SOCKADDR_UN
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
} ra;
|
||||
ISC_SOCKLEN_T ralen;
|
||||
int ioErrno;
|
||||
evConn * conn;
|
||||
LINK(struct evAccept) link;
|
||||
} evAccept;
|
||||
|
||||
typedef struct evFile {
|
||||
evFileFunc func;
|
||||
void * uap;
|
||||
int fd;
|
||||
int eventmask;
|
||||
int preemptive;
|
||||
struct evFile * prev;
|
||||
struct evFile * next;
|
||||
struct evFile * fdprev;
|
||||
struct evFile * fdnext;
|
||||
} evFile;
|
||||
|
||||
typedef struct evStream {
|
||||
evStreamFunc func;
|
||||
void * uap;
|
||||
evFileID file;
|
||||
evTimerID timer;
|
||||
int flags;
|
||||
#define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */
|
||||
int fd;
|
||||
struct iovec * iovOrig;
|
||||
int iovOrigCount;
|
||||
struct iovec * iovCur;
|
||||
int iovCurCount;
|
||||
int ioTotal;
|
||||
int ioDone;
|
||||
int ioErrno;
|
||||
struct evStream *prevDone, *nextDone;
|
||||
struct evStream *prev, *next;
|
||||
} evStream;
|
||||
|
||||
typedef struct evTimer {
|
||||
evTimerFunc func;
|
||||
void * uap;
|
||||
struct timespec due, inter;
|
||||
int index;
|
||||
int mode;
|
||||
#define EV_TMR_RATE 1
|
||||
} evTimer;
|
||||
|
||||
typedef struct evWait {
|
||||
evWaitFunc func;
|
||||
void * uap;
|
||||
const void * tag;
|
||||
struct evWait * next;
|
||||
} evWait;
|
||||
|
||||
typedef struct evWaitList {
|
||||
evWait * first;
|
||||
evWait * last;
|
||||
struct evWaitList * prev;
|
||||
struct evWaitList * next;
|
||||
} evWaitList;
|
||||
|
||||
typedef struct evEvent_p {
|
||||
enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
|
||||
union {
|
||||
struct { evAccept *this; } accept;
|
||||
struct { evFile *this; int eventmask; } file;
|
||||
struct { evStream *this; } stream;
|
||||
struct { evTimer *this; } timer;
|
||||
struct { evWait *this; } wait;
|
||||
struct { struct evEvent_p *next; } free;
|
||||
struct { const void *placeholder; } null;
|
||||
} u;
|
||||
} evEvent_p;
|
||||
|
||||
#ifdef USE_POLL
|
||||
typedef struct {
|
||||
void *ctx; /* pointer to the evContext_p */
|
||||
uint32_t type; /* READ, WRITE, EXCEPT, nonblk */
|
||||
uint32_t result; /* 1 => revents, 0 => events */
|
||||
} __evEmulMask;
|
||||
|
||||
#define emulMaskInit(ctx, field, ev, lastnext) \
|
||||
ctx->field.ctx = ctx; \
|
||||
ctx->field.type = ev; \
|
||||
ctx->field.result = lastnext;
|
||||
|
||||
extern short *__fd_eventfield(int fd, __evEmulMask *maskp);
|
||||
extern short __poll_event(__evEmulMask *maskp);
|
||||
extern void __fd_clr(int fd, __evEmulMask *maskp);
|
||||
extern void __fd_set(int fd, __evEmulMask *maskp);
|
||||
|
||||
#undef FD_ZERO
|
||||
#define FD_ZERO(maskp)
|
||||
|
||||
#undef FD_SET
|
||||
#define FD_SET(fd, maskp) \
|
||||
__fd_set(fd, maskp)
|
||||
|
||||
#undef FD_CLR
|
||||
#define FD_CLR(fd, maskp) \
|
||||
__fd_clr(fd, maskp)
|
||||
|
||||
#undef FD_ISSET
|
||||
#define FD_ISSET(fd, maskp) \
|
||||
((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
|
||||
|
||||
#endif /* USE_POLL */
|
||||
|
||||
typedef struct {
|
||||
/* Global. */
|
||||
const evEvent_p *cur;
|
||||
/* Debugging. */
|
||||
int debug;
|
||||
FILE *output;
|
||||
/* Connections. */
|
||||
evConn *conns;
|
||||
LIST(evAccept) accepts;
|
||||
/* Files. */
|
||||
evFile *files, *fdNext;
|
||||
#ifndef USE_POLL
|
||||
fd_set rdLast, rdNext;
|
||||
fd_set wrLast, wrNext;
|
||||
fd_set exLast, exNext;
|
||||
fd_set nonblockBefore;
|
||||
int fdMax, fdCount, highestFD;
|
||||
evFile *fdTable[FD_SETSIZE];
|
||||
#else
|
||||
struct pollfd *pollfds; /* Allocated as needed */
|
||||
evFile **fdTable; /* Ditto */
|
||||
int maxnfds; /* # elements in above */
|
||||
int firstfd; /* First active fd */
|
||||
int fdMax; /* Last active fd */
|
||||
int fdCount; /* # fd:s with I/O */
|
||||
int highestFD; /* max fd allowed by OS */
|
||||
__evEmulMask rdLast, rdNext;
|
||||
__evEmulMask wrLast, wrNext;
|
||||
__evEmulMask exLast, exNext;
|
||||
__evEmulMask nonblockBefore;
|
||||
#endif /* USE_POLL */
|
||||
#ifdef EVENTLIB_TIME_CHECKS
|
||||
struct timespec lastSelectTime;
|
||||
int lastFdCount;
|
||||
#endif
|
||||
/* Streams. */
|
||||
evStream *streams;
|
||||
evStream *strDone, *strLast;
|
||||
/* Timers. */
|
||||
struct timespec lastEventTime;
|
||||
heap_context timers;
|
||||
/* Waits. */
|
||||
evWaitList *waitLists;
|
||||
evWaitList waitDone;
|
||||
} evContext_p;
|
||||
|
||||
/* eventlib.c */
|
||||
#define evPrintf __evPrintf
|
||||
void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
|
||||
ISC_FORMAT_PRINTF(3, 4);
|
||||
|
||||
#ifdef USE_POLL
|
||||
extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd);
|
||||
#endif /* USE_POLL */
|
||||
|
||||
/* ev_timers.c */
|
||||
#define evCreateTimers __evCreateTimers
|
||||
heap_context evCreateTimers(const evContext_p *);
|
||||
#define evDestroyTimers __evDestroyTimers
|
||||
void evDestroyTimers(const evContext_p *);
|
||||
|
||||
/* ev_waits.c */
|
||||
#define evFreeWait __evFreeWait
|
||||
evWait *evFreeWait(evContext_p *ctx, evWait *old);
|
||||
|
||||
/* Global options */
|
||||
extern int __evOptMonoTime;
|
||||
|
||||
#endif /*_EVENTLIB_P_H*/
|
104
libc/upstream-netbsd/lib/libc/regex/cclass.h
Normal file
104
libc/upstream-netbsd/lib/libc/regex/cclass.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* $NetBSD: cclass.h,v 1.7 2003/08/07 16:43:19 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)cclass.h 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)cclass.h 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/* character-class table */
|
||||
static const struct cclass {
|
||||
const char *name;
|
||||
const char *chars;
|
||||
const char *multis;
|
||||
} cclasses[] = {
|
||||
{ "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
|
||||
0123456789", "" },
|
||||
{ "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
||||
"" },
|
||||
{ "blank", " \t", "" },
|
||||
{ "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
|
||||
\25\26\27\30\31\32\33\34\35\36\37\177", "" },
|
||||
{ "digit", "0123456789", "" },
|
||||
{ "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
|
||||
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
|
||||
"" },
|
||||
{ "lower", "abcdefghijklmnopqrstuvwxyz",
|
||||
"" },
|
||||
{ "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
|
||||
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
|
||||
"" },
|
||||
{ "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
|
||||
"" },
|
||||
{ "space", "\t\n\v\f\r ", "" },
|
||||
{ "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"" },
|
||||
{ "xdigit", "0123456789ABCDEFabcdef",
|
||||
"" },
|
||||
{ NULL, 0, "" }
|
||||
};
|
175
libc/upstream-netbsd/lib/libc/regex/cname.h
Normal file
175
libc/upstream-netbsd/lib/libc/regex/cname.h
Normal file
@@ -0,0 +1,175 @@
|
||||
/* $NetBSD: cname.h,v 1.7 2003/08/07 16:43:19 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)cname.h 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)cname.h 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/* character-name table */
|
||||
static const struct cname {
|
||||
const char *name;
|
||||
char code;
|
||||
} cnames[] = {
|
||||
{ "NUL", '\0' },
|
||||
{ "SOH", '\001' },
|
||||
{ "STX", '\002' },
|
||||
{ "ETX", '\003' },
|
||||
{ "EOT", '\004' },
|
||||
{ "ENQ", '\005' },
|
||||
{ "ACK", '\006' },
|
||||
{ "BEL", '\007' },
|
||||
{ "alert", '\007' },
|
||||
{ "BS", '\010' },
|
||||
{ "backspace", '\b' },
|
||||
{ "HT", '\011' },
|
||||
{ "tab", '\t' },
|
||||
{ "LF", '\012' },
|
||||
{ "newline", '\n' },
|
||||
{ "VT", '\013' },
|
||||
{ "vertical-tab", '\v' },
|
||||
{ "FF", '\014' },
|
||||
{ "form-feed", '\f' },
|
||||
{ "CR", '\015' },
|
||||
{ "carriage-return", '\r' },
|
||||
{ "SO", '\016' },
|
||||
{ "SI", '\017' },
|
||||
{ "DLE", '\020' },
|
||||
{ "DC1", '\021' },
|
||||
{ "DC2", '\022' },
|
||||
{ "DC3", '\023' },
|
||||
{ "DC4", '\024' },
|
||||
{ "NAK", '\025' },
|
||||
{ "SYN", '\026' },
|
||||
{ "ETB", '\027' },
|
||||
{ "CAN", '\030' },
|
||||
{ "EM", '\031' },
|
||||
{ "SUB", '\032' },
|
||||
{ "ESC", '\033' },
|
||||
{ "IS4", '\034' },
|
||||
{ "FS", '\034' },
|
||||
{ "IS3", '\035' },
|
||||
{ "GS", '\035' },
|
||||
{ "IS2", '\036' },
|
||||
{ "RS", '\036' },
|
||||
{ "IS1", '\037' },
|
||||
{ "US", '\037' },
|
||||
{ "space", ' ' },
|
||||
{ "exclamation-mark", '!' },
|
||||
{ "quotation-mark", '"' },
|
||||
{ "number-sign", '#' },
|
||||
{ "dollar-sign", '$' },
|
||||
{ "percent-sign", '%' },
|
||||
{ "ampersand", '&' },
|
||||
{ "apostrophe", '\'' },
|
||||
{ "left-parenthesis", '(' },
|
||||
{ "right-parenthesis", ')' },
|
||||
{ "asterisk", '*' },
|
||||
{ "plus-sign", '+' },
|
||||
{ "comma", ',' },
|
||||
{ "hyphen", '-' },
|
||||
{ "hyphen-minus", '-' },
|
||||
{ "period", '.' },
|
||||
{ "full-stop", '.' },
|
||||
{ "slash", '/' },
|
||||
{ "solidus", '/' },
|
||||
{ "zero", '0' },
|
||||
{ "one", '1' },
|
||||
{ "two", '2' },
|
||||
{ "three", '3' },
|
||||
{ "four", '4' },
|
||||
{ "five", '5' },
|
||||
{ "six", '6' },
|
||||
{ "seven", '7' },
|
||||
{ "eight", '8' },
|
||||
{ "nine", '9' },
|
||||
{ "colon", ':' },
|
||||
{ "semicolon", ';' },
|
||||
{ "less-than-sign", '<' },
|
||||
{ "equals-sign", '=' },
|
||||
{ "greater-than-sign", '>' },
|
||||
{ "question-mark", '?' },
|
||||
{ "commercial-at", '@' },
|
||||
{ "left-square-bracket", '[' },
|
||||
{ "backslash", '\\' },
|
||||
{ "reverse-solidus", '\\' },
|
||||
{ "right-square-bracket", ']' },
|
||||
{ "circumflex", '^' },
|
||||
{ "circumflex-accent", '^' },
|
||||
{ "underscore", '_' },
|
||||
{ "low-line", '_' },
|
||||
{ "grave-accent", '`' },
|
||||
{ "left-brace", '{' },
|
||||
{ "left-curly-bracket", '{' },
|
||||
{ "vertical-line", '|' },
|
||||
{ "right-brace", '}' },
|
||||
{ "right-curly-bracket", '}' },
|
||||
{ "tilde", '~' },
|
||||
{ "DEL", '\177' },
|
||||
{ NULL, 0 },
|
||||
};
|
1188
libc/upstream-netbsd/lib/libc/regex/engine.c
Normal file
1188
libc/upstream-netbsd/lib/libc/regex/engine.c
Normal file
File diff suppressed because it is too large
Load Diff
1944
libc/upstream-netbsd/lib/libc/regex/regcomp.c
Normal file
1944
libc/upstream-netbsd/lib/libc/regex/regcomp.c
Normal file
File diff suppressed because it is too large
Load Diff
223
libc/upstream-netbsd/lib/libc/regex/regerror.c
Normal file
223
libc/upstream-netbsd/lib/libc/regex/regerror.c
Normal file
@@ -0,0 +1,223 @@
|
||||
/* $NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)regerror.c 8.4 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)regerror.c 8.4 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <regex.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(regerror,_regerror)
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
/* ========= begin header generated by ./mkh ========= */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* === regerror.c === */
|
||||
static const char *regatoi(const regex_t *preg, char *localbuf, size_t buflen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* ========= end header generated by ./mkh ========= */
|
||||
/*
|
||||
= #define REG_NOMATCH 1
|
||||
= #define REG_BADPAT 2
|
||||
= #define REG_ECOLLATE 3
|
||||
= #define REG_ECTYPE 4
|
||||
= #define REG_EESCAPE 5
|
||||
= #define REG_ESUBREG 6
|
||||
= #define REG_EBRACK 7
|
||||
= #define REG_EPAREN 8
|
||||
= #define REG_EBRACE 9
|
||||
= #define REG_BADBR 10
|
||||
= #define REG_ERANGE 11
|
||||
= #define REG_ESPACE 12
|
||||
= #define REG_BADRPT 13
|
||||
= #define REG_EMPTY 14
|
||||
= #define REG_ASSERT 15
|
||||
= #define REG_INVARG 16
|
||||
= #define REG_ATOI 255 // convert name to number (!)
|
||||
= #define REG_ITOA 0400 // convert number to name (!)
|
||||
*/
|
||||
static const struct rerr {
|
||||
int code;
|
||||
const char *name;
|
||||
const char *explain;
|
||||
} rerrs[] = {
|
||||
{ REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" },
|
||||
{ REG_BADPAT, "REG_BADPAT", "invalid regular expression" },
|
||||
{ REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" },
|
||||
{ REG_ECTYPE, "REG_ECTYPE", "invalid character class" },
|
||||
{ REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" },
|
||||
{ REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" },
|
||||
{ REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" },
|
||||
{ REG_EPAREN, "REG_EPAREN", "parentheses not balanced" },
|
||||
{ REG_EBRACE, "REG_EBRACE", "braces not balanced" },
|
||||
{ REG_BADBR, "REG_BADBR", "invalid repetition count(s)" },
|
||||
{ REG_ERANGE, "REG_ERANGE", "invalid character range" },
|
||||
{ REG_ESPACE, "REG_ESPACE", "out of memory" },
|
||||
{ REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" },
|
||||
{ REG_EMPTY, "REG_EMPTY", "empty (sub)expression" },
|
||||
{ REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" },
|
||||
{ REG_INVARG, "REG_INVARG", "invalid argument to regex routine" },
|
||||
{ 0, "", "*** unknown regexp error code ***" }
|
||||
};
|
||||
|
||||
/*
|
||||
* regerror - the interface to error numbers
|
||||
* extern size_t regerror(int, const regex_t *, char *, size_t);
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
size_t
|
||||
regerror(
|
||||
int errcode,
|
||||
const regex_t *preg,
|
||||
char *errbuf,
|
||||
size_t errbuf_size)
|
||||
{
|
||||
const struct rerr *r;
|
||||
size_t len;
|
||||
int target = errcode &~ REG_ITOA;
|
||||
const char *s;
|
||||
char convbuf[50];
|
||||
|
||||
_DIAGASSERT(errcode != REG_ATOI || preg != NULL);
|
||||
_DIAGASSERT(errbuf != NULL);
|
||||
|
||||
if (errcode == REG_ATOI)
|
||||
s = regatoi(preg, convbuf, sizeof convbuf);
|
||||
else {
|
||||
for (r = rerrs; r->code != 0; r++)
|
||||
if (r->code == target)
|
||||
break;
|
||||
|
||||
if (errcode & REG_ITOA) {
|
||||
if (r->code != 0) {
|
||||
(void)strlcpy(convbuf, r->name, sizeof convbuf);
|
||||
} else
|
||||
(void)snprintf(convbuf, sizeof convbuf,
|
||||
"REG_0x%x", target);
|
||||
s = convbuf;
|
||||
} else
|
||||
s = r->explain;
|
||||
}
|
||||
|
||||
len = strlen(s) + 1;
|
||||
if (errbuf_size > 0)
|
||||
(void)strlcpy(errbuf, s, errbuf_size);
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
||||
/*
|
||||
* regatoi - internal routine to implement REG_ATOI
|
||||
* static const char *regatoi(const regex_t *preg, char *localbuf,
|
||||
* size_t buflen);
|
||||
*/
|
||||
static const char *
|
||||
regatoi(
|
||||
const regex_t *preg,
|
||||
char *localbuf,
|
||||
size_t buflen)
|
||||
{
|
||||
const struct rerr *r;
|
||||
|
||||
for (r = rerrs; r->code != 0; r++)
|
||||
if (strcmp(r->name, preg->re_endp) == 0)
|
||||
break;
|
||||
if (r->code == 0)
|
||||
return "0";
|
||||
|
||||
(void)snprintf(localbuf, buflen, "%d", r->code);
|
||||
return localbuf;
|
||||
}
|
209
libc/upstream-netbsd/lib/libc/regex/regex2.h
Normal file
209
libc/upstream-netbsd/lib/libc/regex/regex2.h
Normal file
@@ -0,0 +1,209 @@
|
||||
/* $NetBSD: regex2.h,v 1.13 2011/10/09 18:23:00 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)regex2.h 8.4 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)regex2.h 8.4 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*
|
||||
* First, the stuff that ends up in the outside-world include file
|
||||
= typedef off_t regoff_t;
|
||||
= typedef struct {
|
||||
= int re_magic;
|
||||
= size_t re_nsub; // number of parenthesized subexpressions
|
||||
= const char *re_endp; // end pointer for REG_PEND
|
||||
= struct re_guts *re_g; // none of your business :-)
|
||||
= } regex_t;
|
||||
= typedef struct {
|
||||
= regoff_t rm_so; // start of match
|
||||
= regoff_t rm_eo; // end of match
|
||||
= } regmatch_t;
|
||||
*/
|
||||
/*
|
||||
* internals of regex_t
|
||||
*/
|
||||
#define MAGIC1 ((('r'^0200)<<8) | 'e')
|
||||
|
||||
/*
|
||||
* The internal representation is a *strip*, a sequence of
|
||||
* operators ending with an endmarker. (Some terminology etc. is a
|
||||
* historical relic of earlier versions which used multiple strips.)
|
||||
* Certain oddities in the representation are there to permit running
|
||||
* the machinery backwards; in particular, any deviation from sequential
|
||||
* flow must be marked at both its source and its destination. Some
|
||||
* fine points:
|
||||
*
|
||||
* - OPLUS_ and O_PLUS are *inside* the loop they create.
|
||||
* - OQUEST_ and O_QUEST are *outside* the bypass they create.
|
||||
* - OCH_ and O_CH are *outside* the multi-way branch they create, while
|
||||
* OOR1 and OOR2 are respectively the end and the beginning of one of
|
||||
* the branches. Note that there is an implicit OOR2 following OCH_
|
||||
* and an implicit OOR1 preceding O_CH.
|
||||
*
|
||||
* In state representations, an operator's bit is on to signify a state
|
||||
* immediately *preceding* "execution" of that operator.
|
||||
*/
|
||||
typedef u_int32_t sop; /* strip operator */
|
||||
typedef size_t sopno;
|
||||
#define OPRMASK ((u_int32_t)0xf8000000UL)
|
||||
#define OPDMASK ((u_int32_t)0x07ffffffUL)
|
||||
#define OPSHIFT ((unsigned)27)
|
||||
#define OP(n) ((n)&OPRMASK)
|
||||
#define OPND(n) ((int)((n)&OPDMASK))
|
||||
#define SOP(op, opnd) ((op)|(opnd))
|
||||
|
||||
#define OPC(n) (((u_int32_t)(n))<<OPSHIFT)
|
||||
/* operators meaning operand */
|
||||
/* (back, fwd are offsets) */
|
||||
#define OEND OPC(1) /* endmarker - */
|
||||
#define OCHAR OPC(2) /* character unsigned char */
|
||||
#define OBOL OPC(3) /* left anchor - */
|
||||
#define OEOL OPC(4) /* right anchor - */
|
||||
#define OANY OPC(5) /* . - */
|
||||
#define OANYOF OPC(6) /* [...] set number */
|
||||
#define OBACK_ OPC(7) /* begin \d paren number */
|
||||
#define O_BACK OPC(8) /* end \d paren number */
|
||||
#define OPLUS_ OPC(9) /* + prefix fwd to suffix */
|
||||
#define O_PLUS OPC(10) /* + suffix back to prefix */
|
||||
#define OQUEST_ OPC(11) /* ? prefix fwd to suffix */
|
||||
#define O_QUEST OPC(12) /* ? suffix back to prefix */
|
||||
#define OLPAREN OPC(13) /* ( fwd to ) */
|
||||
#define ORPAREN OPC(14) /* ) back to ( */
|
||||
#define OCH_ OPC(15) /* begin choice fwd to OOR2 */
|
||||
#define OOR1 OPC(16) /* | pt. 1 back to OOR1 or OCH_ */
|
||||
#define OOR2 OPC(17) /* | pt. 2 fwd to OOR2 or O_CH */
|
||||
#define O_CH OPC(18) /* end choice back to OOR1 */
|
||||
#define OBOW OPC(19) /* begin word - */
|
||||
#define OEOW OPC(20) /* end word - */
|
||||
|
||||
/*
|
||||
* Structure for [] character-set representation. Character sets are
|
||||
* done as bit vectors, grouped 8 to a byte vector for compactness.
|
||||
* The individual set therefore has both a pointer to the byte vector
|
||||
* and a mask to pick out the relevant bit of each byte. A hash code
|
||||
* simplifies testing whether two sets could be identical.
|
||||
*
|
||||
* This will get trickier for multicharacter collating elements. As
|
||||
* preliminary hooks for dealing with such things, we also carry along
|
||||
* a string of multi-character elements, and decide the size of the
|
||||
* vectors at run time.
|
||||
*/
|
||||
typedef struct {
|
||||
uch *ptr; /* -> uch [csetsize] */
|
||||
uch mask; /* bit within array */
|
||||
uch hash; /* hash code */
|
||||
size_t smultis;
|
||||
char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
|
||||
} cset;
|
||||
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
|
||||
#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
|
||||
#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
|
||||
#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
|
||||
#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
|
||||
#define MCsub(p, cs, cp) mcsub(p, cs, cp)
|
||||
#define MCin(p, cs, cp) mcin(p, cs, cp)
|
||||
|
||||
/* stuff for character categories */
|
||||
typedef unsigned char cat_t;
|
||||
|
||||
/*
|
||||
* main compiled-expression structure
|
||||
*/
|
||||
struct re_guts {
|
||||
int magic;
|
||||
# define MAGIC2 ((('R'^0200)<<8)|'E')
|
||||
sop *strip; /* malloced area for strip */
|
||||
size_t csetsize; /* number of bits in a cset vector */
|
||||
size_t ncsets; /* number of csets in use */
|
||||
cset *sets; /* -> cset [ncsets] */
|
||||
uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
|
||||
int cflags; /* copy of regcomp() cflags argument */
|
||||
sopno nstates; /* = number of sops */
|
||||
sopno firststate; /* the initial OEND (normally 0) */
|
||||
sopno laststate; /* the final OEND */
|
||||
int iflags; /* internal flags */
|
||||
# define USEBOL 01 /* used ^ */
|
||||
# define USEEOL 02 /* used $ */
|
||||
# define BAD 04 /* something wrong */
|
||||
size_t nbol; /* number of ^ used */
|
||||
size_t neol; /* number of $ used */
|
||||
size_t ncategories; /* how many character categories */
|
||||
cat_t *categories; /* ->catspace[-CHAR_MIN] */
|
||||
char *must; /* match must contain this string */
|
||||
size_t mlen; /* length of must */
|
||||
size_t nsub; /* copy of re_nsub */
|
||||
int backrefs; /* does it use back references? */
|
||||
sopno nplus; /* how deep does it nest +s? */
|
||||
/* catspace must be last */
|
||||
cat_t catspace[1]; /* actually [NC] */
|
||||
};
|
||||
|
||||
/* misc utilities */
|
||||
#define OUT (CHAR_MAX+1) /* a non-character value */
|
||||
#define ISWORD(c) (isalnum((unsigned char)c) || (c) == '_')
|
234
libc/upstream-netbsd/lib/libc/regex/regexec.c
Normal file
234
libc/upstream-netbsd/lib/libc/regex/regexec.c
Normal file
@@ -0,0 +1,234 @@
|
||||
/* $NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)regexec.c 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)regexec.c 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* the outer shell of regexec()
|
||||
*
|
||||
* This file includes engine.c *twice*, after muchos fiddling with the
|
||||
* macros that code uses. This lets the same code operate on two different
|
||||
* representations for state sets.
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <regex.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(regexec,_regexec)
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "regex2.h"
|
||||
|
||||
/* macros for manipulating states, small version */
|
||||
#define states unsigned long
|
||||
#define states1 unsigned long /* for later use in regexec() decision */
|
||||
#define CLEAR(v) ((v) = 0)
|
||||
#define SET0(v, n) ((v) &= ~((unsigned long)1 << (n)))
|
||||
#define SET1(v, n) ((v) |= (unsigned long)1 << (n))
|
||||
#define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0)
|
||||
#define ASSIGN(d, s) ((d) = (s))
|
||||
#define EQ(a, b) ((a) == (b))
|
||||
#define STATEVARS int dummy /* dummy version */
|
||||
#define STATESETUP(m, n) /* nothing */
|
||||
#define STATETEARDOWN(m) /* nothing */
|
||||
#define SETUP(v) ((v) = 0)
|
||||
#define onestate unsigned long
|
||||
#define INIT(o, n) ((o) = (unsigned long)1 << (n))
|
||||
#define INC(o) ((o) <<= 1)
|
||||
#define ISSTATEIN(v, o) (((v) & (o)) != 0)
|
||||
/* some abbreviations; note that some of these know variable names! */
|
||||
/* do "if I'm here, I can also be there" etc without branches */
|
||||
#define FWD(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) << (n))
|
||||
#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n))
|
||||
#define ISSETBACK(v, n) (((v) & ((unsigned long)here >> (n))) != 0)
|
||||
/* function names */
|
||||
#define SNAMES /* engine.c looks after details */
|
||||
|
||||
#include "engine.c"
|
||||
|
||||
/* now undo things */
|
||||
#undef states
|
||||
#undef CLEAR
|
||||
#undef SET0
|
||||
#undef SET1
|
||||
#undef ISSET
|
||||
#undef ASSIGN
|
||||
#undef EQ
|
||||
#undef STATEVARS
|
||||
#undef STATESETUP
|
||||
#undef STATETEARDOWN
|
||||
#undef SETUP
|
||||
#undef onestate
|
||||
#undef INIT
|
||||
#undef INC
|
||||
#undef ISSTATEIN
|
||||
#undef FWD
|
||||
#undef BACK
|
||||
#undef ISSETBACK
|
||||
#undef SNAMES
|
||||
|
||||
/* macros for manipulating states, large version */
|
||||
#define states char *
|
||||
#define CLEAR(v) memset(v, 0, (size_t)m->g->nstates)
|
||||
#define SET0(v, n) ((v)[n] = 0)
|
||||
#define SET1(v, n) ((v)[n] = 1)
|
||||
#define ISSET(v, n) ((v)[n])
|
||||
#define ASSIGN(d, s) memcpy(d, s, (size_t)m->g->nstates)
|
||||
#define EQ(a, b) (memcmp(a, b, (size_t)m->g->nstates) == 0)
|
||||
#define STATEVARS int vn; char *space
|
||||
#define STATESETUP(m, nv) \
|
||||
if (((m)->space = malloc((size_t)((nv)*(m)->g->nstates))) == NULL) \
|
||||
return(REG_ESPACE); \
|
||||
else \
|
||||
(m)->vn = 0
|
||||
|
||||
#define STATETEARDOWN(m) { free((m)->space); m->space = NULL; }
|
||||
#define SETUP(v) ((v) = &m->space[(size_t)(m->vn++ * m->g->nstates)])
|
||||
#define onestate int
|
||||
#define INIT(o, n) ((o) = (int)(n))
|
||||
#define INC(o) ((o)++)
|
||||
#define ISSTATEIN(v, o) ((v)[o])
|
||||
/* some abbreviations; note that some of these know variable names! */
|
||||
/* do "if I'm here, I can also be there" etc without branches */
|
||||
#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
|
||||
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
|
||||
#define ISSETBACK(v, n) ((v)[here - (n)])
|
||||
/* function names */
|
||||
#define LNAMES /* flag */
|
||||
|
||||
#include "engine.c"
|
||||
|
||||
/*
|
||||
- regexec - interface for matching
|
||||
= extern int regexec(const regex_t *, const char *, size_t, \
|
||||
= regmatch_t [], int);
|
||||
= #define REG_NOTBOL 00001
|
||||
= #define REG_NOTEOL 00002
|
||||
= #define REG_STARTEND 00004
|
||||
= #define REG_TRACE 00400 // tracing of execution
|
||||
= #define REG_LARGE 01000 // force large representation
|
||||
= #define REG_BACKR 02000 // force use of backref code
|
||||
*
|
||||
* We put this here so we can exploit knowledge of the state representation
|
||||
* when choosing which matcher to call. Also, by this point the matchers
|
||||
* have been prototyped.
|
||||
*/
|
||||
int /* 0 success, REG_NOMATCH failure */
|
||||
regexec(
|
||||
const regex_t *preg,
|
||||
const char *string,
|
||||
size_t nmatch,
|
||||
regmatch_t pmatch[],
|
||||
int eflags)
|
||||
{
|
||||
struct re_guts *g = preg->re_g;
|
||||
char *s;
|
||||
#ifdef REDEBUG
|
||||
# define GOODFLAGS(f) (f)
|
||||
#else
|
||||
# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
|
||||
#endif
|
||||
|
||||
_DIAGASSERT(preg != NULL);
|
||||
_DIAGASSERT(string != NULL);
|
||||
|
||||
if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
|
||||
return(REG_BADPAT);
|
||||
assert(!(g->iflags&BAD));
|
||||
if (g->iflags&BAD) /* backstop for no-debug case */
|
||||
return(REG_BADPAT);
|
||||
eflags = GOODFLAGS(eflags);
|
||||
|
||||
s = __UNCONST(string);
|
||||
|
||||
if (g->nstates <= (sopno)(CHAR_BIT*sizeof(states1)) && !(eflags®_LARGE))
|
||||
return(smatcher(g, s, nmatch, pmatch, eflags));
|
||||
else
|
||||
return(lmatcher(g, s, nmatch, pmatch, eflags));
|
||||
}
|
129
libc/upstream-netbsd/lib/libc/regex/regfree.c
Normal file
129
libc/upstream-netbsd/lib/libc/regex/regfree.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/* $NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)regfree.c 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)regfree.c 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <regex.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(regfree,_regfree)
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "regex2.h"
|
||||
|
||||
/*
|
||||
- regfree - free everything
|
||||
= extern void regfree(regex_t *);
|
||||
*/
|
||||
void
|
||||
regfree(
|
||||
regex_t *preg)
|
||||
{
|
||||
struct re_guts *g;
|
||||
|
||||
_DIAGASSERT(preg != NULL);
|
||||
|
||||
_DIAGASSERT(preg->re_magic == MAGIC1);
|
||||
if (preg->re_magic != MAGIC1) /* oops */
|
||||
return; /* nice to complain, but hard */
|
||||
|
||||
g = preg->re_g;
|
||||
if (g == NULL || g->magic != MAGIC2) /* oops again */
|
||||
return;
|
||||
preg->re_magic = 0; /* mark it invalid */
|
||||
g->magic = 0; /* mark it invalid */
|
||||
|
||||
if (g->strip != NULL)
|
||||
free(g->strip);
|
||||
if (g->sets != NULL)
|
||||
free(g->sets);
|
||||
if (g->setbits != NULL)
|
||||
free(g->setbits);
|
||||
if (g->must != NULL)
|
||||
free(g->must);
|
||||
free(g);
|
||||
}
|
91
libc/upstream-netbsd/lib/libc/regex/utils.h
Normal file
91
libc/upstream-netbsd/lib/libc/regex/utils.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* $NetBSD: utils.h,v 1.6 2003/08/07 16:43:21 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)utils.h 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. 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.
|
||||
*
|
||||
* @(#)utils.h 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
/* utility definitions */
|
||||
#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */
|
||||
#define INFINITY (DUPMAX + 1)
|
||||
#define NC (CHAR_MAX - CHAR_MIN + 1)
|
||||
typedef unsigned char uch;
|
||||
|
||||
/* switch off assertions (if not already off) if no REDEBUG */
|
||||
#ifndef REDEBUG
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG /* no assertions please */
|
||||
#endif
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
/* for old systems with bcopy() but no memmove() */
|
||||
#ifdef USEBCOPY
|
||||
#define memmove(d, s, c) bcopy(s, d, c)
|
||||
#endif
|
154
libc/upstream-netbsd/lib/libc/stdio/getdelim.c
Normal file
154
libc/upstream-netbsd/lib/libc/stdio/getdelim.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Roy Marples.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $");
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "reentrant.h"
|
||||
#include "local.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(getdelim, _getdelim)
|
||||
#endif
|
||||
|
||||
/* Minimum buffer size we create.
|
||||
* This should allow config files to fit into our power of 2 buffer growth
|
||||
* without the need for a realloc. */
|
||||
#define MINBUF 128
|
||||
|
||||
ssize_t
|
||||
__getdelim(char **__restrict buf, size_t *__restrict buflen,
|
||||
int sep, FILE *__restrict fp)
|
||||
{
|
||||
unsigned char *p;
|
||||
size_t len, newlen, off;
|
||||
char *newb;
|
||||
|
||||
_DIAGASSERT(fp != NULL);
|
||||
|
||||
if (buf == NULL || buflen == NULL) {
|
||||
errno = EINVAL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* If buf is NULL, we have to assume a size of zero */
|
||||
if (*buf == NULL)
|
||||
*buflen = 0;
|
||||
|
||||
_SET_ORIENTATION(fp, -1);
|
||||
off = 0;
|
||||
do {
|
||||
/* If the input buffer is empty, refill it */
|
||||
if (fp->_r <= 0 && __srefill(fp)) {
|
||||
if (__sferror(fp))
|
||||
goto error;
|
||||
/* No error, so EOF. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Scan through looking for the separator */
|
||||
p = memchr(fp->_p, sep, (size_t)fp->_r);
|
||||
if (p == NULL)
|
||||
len = fp->_r;
|
||||
else
|
||||
len = (p - fp->_p) + 1;
|
||||
|
||||
newlen = off + len;
|
||||
/* Ensure we can handle it */
|
||||
if (newlen < off || newlen > SSIZE_MAX) {
|
||||
errno = EOVERFLOW;
|
||||
goto error;
|
||||
}
|
||||
newlen++; /* reserve space for the NULL terminator */
|
||||
if (newlen > *buflen) {
|
||||
if (newlen < MINBUF)
|
||||
newlen = MINBUF;
|
||||
if (!powerof2(newlen)) {
|
||||
/* Grow the buffer to the next power of 2 */
|
||||
newlen--;
|
||||
newlen |= newlen >> 1;
|
||||
newlen |= newlen >> 2;
|
||||
newlen |= newlen >> 4;
|
||||
newlen |= newlen >> 8;
|
||||
newlen |= newlen >> 16;
|
||||
#if SIZE_T_MAX > 0xffffffffU
|
||||
newlen |= newlen >> 32;
|
||||
#endif
|
||||
newlen++;
|
||||
}
|
||||
|
||||
newb = realloc(*buf, newlen);
|
||||
if (newb == NULL)
|
||||
goto error;
|
||||
*buf = newb;
|
||||
*buflen = newlen;
|
||||
}
|
||||
|
||||
(void)memcpy((*buf + off), fp->_p, len);
|
||||
/* Safe, len is never greater than what fp->_r can fit. */
|
||||
fp->_r -= (int)len;
|
||||
fp->_p += (int)len;
|
||||
off += len;
|
||||
} while (p == NULL);
|
||||
|
||||
/* POSIX demands we return -1 on EOF. */
|
||||
if (off == 0)
|
||||
return -1;
|
||||
|
||||
if (*buf != NULL)
|
||||
*(*buf + off) = '\0';
|
||||
return off;
|
||||
|
||||
error:
|
||||
fp->_flags |= __SERR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
getdelim(char **__restrict buf, size_t *__restrict buflen,
|
||||
int sep, FILE *__restrict fp)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
n = __getdelim(buf, buflen, sep, fp);
|
||||
FUNLOCKFILE(fp);
|
||||
return n;
|
||||
}
|
45
libc/upstream-netbsd/lib/libc/stdio/getline.c
Normal file
45
libc/upstream-netbsd/lib/libc/stdio/getline.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Roy Marples.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $");
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(getline, _getline)
|
||||
#endif
|
||||
|
||||
ssize_t
|
||||
getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp)
|
||||
{
|
||||
return getdelim(buf, buflen, '\n', fp);
|
||||
}
|
57
libc/upstream-netbsd/lib/libc/stdlib/_rand48.c
Normal file
57
libc/upstream-netbsd/lib/libc/stdlib/_rand48.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* $NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "rand48.h"
|
||||
|
||||
unsigned short __rand48_seed[3] = {
|
||||
RAND48_SEED_0,
|
||||
RAND48_SEED_1,
|
||||
RAND48_SEED_2
|
||||
};
|
||||
unsigned short __rand48_mult[3] = {
|
||||
RAND48_MULT_0,
|
||||
RAND48_MULT_1,
|
||||
RAND48_MULT_2
|
||||
};
|
||||
unsigned short __rand48_add = RAND48_ADD;
|
||||
|
||||
void
|
||||
__dorand48(unsigned short xseed[3])
|
||||
{
|
||||
unsigned long accu;
|
||||
unsigned short temp[2];
|
||||
|
||||
_DIAGASSERT(xseed != NULL);
|
||||
|
||||
accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] +
|
||||
(unsigned long) __rand48_add;
|
||||
temp[0] = (unsigned short) accu; /* lower 16 bits */
|
||||
accu >>= sizeof(unsigned short) * 8;
|
||||
accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] +
|
||||
(unsigned long) __rand48_mult[1] * (unsigned long) xseed[0];
|
||||
temp[1] = (unsigned short) accu; /* middle 16 bits */
|
||||
accu >>= sizeof(unsigned short) * 8;
|
||||
accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0];
|
||||
xseed[0] = temp[0];
|
||||
xseed[1] = temp[1];
|
||||
xseed[2] = (unsigned short) accu;
|
||||
}
|
85
libc/upstream-netbsd/lib/libc/stdlib/bsearch.c
Normal file
85
libc/upstream-netbsd/lib/libc/stdlib/bsearch.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/* $NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $ */
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* Perform a binary search.
|
||||
*
|
||||
* The code below is a bit sneaky. After a comparison fails, we
|
||||
* divide the work in half by moving either left or right. If lim
|
||||
* is odd, moving left simply involves halving lim: e.g., when lim
|
||||
* is 5 we look at item 2, so we change lim to 2 so that we will
|
||||
* look at items 0 & 1. If lim is even, the same applies. If lim
|
||||
* is odd, moving right again involes halving lim, this time moving
|
||||
* the base up one item past p: e.g., when lim is 5 we change base
|
||||
* to item 3 and make lim 2 so that we will look at items 3 and 4.
|
||||
* If lim is even, however, we have to shrink it by one before
|
||||
* halving: e.g., when lim is 4, we still looked at item 2, so we
|
||||
* have to make lim 3, then halve, obtaining 1, so that we will only
|
||||
* look at item 3.
|
||||
*/
|
||||
void *
|
||||
bsearch(const void *key, const void *base0, size_t nmemb, size_t size,
|
||||
int (*compar)(const void *, const void *))
|
||||
{
|
||||
const char *base = base0;
|
||||
size_t lim;
|
||||
int cmp;
|
||||
const void *p;
|
||||
|
||||
_DIAGASSERT(key != NULL);
|
||||
_DIAGASSERT(base0 != NULL || nmemb == 0);
|
||||
_DIAGASSERT(compar != NULL);
|
||||
|
||||
for (lim = nmemb; lim != 0; lim >>= 1) {
|
||||
p = base + (lim >> 1) * size;
|
||||
cmp = (*compar)(key, p);
|
||||
if (cmp == 0)
|
||||
return __UNCONST(p);
|
||||
if (cmp > 0) { /* key > p: move right */
|
||||
base = (const char *)p + size;
|
||||
lim--;
|
||||
} /* else move left */
|
||||
}
|
||||
return (NULL);
|
||||
}
|
81
libc/upstream-netbsd/lib/libc/stdlib/div.c
Normal file
81
libc/upstream-netbsd/lib/libc/stdlib/div.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/* $NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)div.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <stdlib.h> /* div_t */
|
||||
|
||||
div_t
|
||||
div(int num, int denom)
|
||||
{
|
||||
div_t r;
|
||||
|
||||
r.quot = num / denom;
|
||||
r.rem = num % denom;
|
||||
/*
|
||||
* The ANSI standard says that |r.quot| <= |n/d|, where
|
||||
* n/d is to be computed in infinite precision. In other
|
||||
* words, we should always truncate the quotient towards
|
||||
* 0, never -infinity.
|
||||
*
|
||||
* Machine division and remainer may work either way when
|
||||
* one or both of n or d is negative. If only one is
|
||||
* negative and r.quot has been truncated towards -inf,
|
||||
* r.rem will have the same sign as denom and the opposite
|
||||
* sign of num; if both are negative and r.quot has been
|
||||
* truncated towards -inf, r.rem will be positive (will
|
||||
* have the opposite sign of num). These are considered
|
||||
* `wrong'.
|
||||
*
|
||||
* If both are num and denom are positive, r will always
|
||||
* be positive.
|
||||
*
|
||||
* This all boils down to:
|
||||
* if num >= 0, but r.rem < 0, we got the wrong answer.
|
||||
* In that case, to get the right answer, add 1 to r.quot and
|
||||
* subtract denom from r.rem.
|
||||
*/
|
||||
if (num >= 0 && r.rem < 0) {
|
||||
r.quot++;
|
||||
r.rem -= denom;
|
||||
}
|
||||
return (r);
|
||||
}
|
32
libc/upstream-netbsd/lib/libc/stdlib/drand48.c
Normal file
32
libc/upstream-netbsd/lib/libc/stdlib/drand48.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* $NetBSD: drand48.c,v 1.6 2005/06/12 05:21:28 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: drand48.c,v 1.6 2005/06/12 05:21:28 lukem Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(drand48,_drand48)
|
||||
#endif
|
||||
|
||||
double
|
||||
drand48(void)
|
||||
{
|
||||
return erand48(__rand48_seed);
|
||||
}
|
42
libc/upstream-netbsd/lib/libc/stdlib/erand48.c
Normal file
42
libc/upstream-netbsd/lib/libc/stdlib/erand48.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* $NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(erand48,_erand48)
|
||||
#endif
|
||||
|
||||
double
|
||||
erand48(unsigned short xseed[3])
|
||||
{
|
||||
|
||||
_DIAGASSERT(xseed != NULL);
|
||||
|
||||
__dorand48(xseed);
|
||||
return ldexp((double) xseed[0], -48) +
|
||||
ldexp((double) xseed[1], -32) +
|
||||
ldexp((double) xseed[2], -16);
|
||||
}
|
63
libc/upstream-netbsd/lib/libc/stdlib/exit.c
Normal file
63
libc/upstream-netbsd/lib/libc/stdlib/exit.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* $NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _LIBC
|
||||
#include "reentrant.h"
|
||||
#include "atexit.h"
|
||||
#endif
|
||||
|
||||
void (*__cleanup)(void);
|
||||
|
||||
/*
|
||||
* Exit, flushing stdio buffers if necessary.
|
||||
*/
|
||||
void
|
||||
exit(int status)
|
||||
{
|
||||
|
||||
#ifdef _LIBC
|
||||
__cxa_finalize(NULL);
|
||||
#endif
|
||||
if (__cleanup)
|
||||
(*__cleanup)();
|
||||
_exit(status);
|
||||
}
|
39
libc/upstream-netbsd/lib/libc/stdlib/jrand48.c
Normal file
39
libc/upstream-netbsd/lib/libc/stdlib/jrand48.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* $NetBSD: jrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: jrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(jrand48,_jrand48)
|
||||
#endif
|
||||
|
||||
long
|
||||
jrand48(unsigned short xseed[3])
|
||||
{
|
||||
|
||||
_DIAGASSERT(xseed != NULL);
|
||||
|
||||
__dorand48(xseed);
|
||||
return (int16_t)xseed[2] * 65536 + xseed[1];
|
||||
}
|
60
libc/upstream-netbsd/lib/libc/stdlib/ldiv.c
Normal file
60
libc/upstream-netbsd/lib/libc/stdlib/ldiv.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <stdlib.h> /* ldiv_t */
|
||||
|
||||
ldiv_t
|
||||
ldiv(long num, long denom)
|
||||
{
|
||||
ldiv_t r;
|
||||
|
||||
/* see div.c for comments */
|
||||
|
||||
r.quot = num / denom;
|
||||
r.rem = num % denom;
|
||||
if (num >= 0 && r.rem < 0) {
|
||||
r.quot++;
|
||||
r.rem -= denom;
|
||||
}
|
||||
return (r);
|
||||
}
|
66
libc/upstream-netbsd/lib/libc/stdlib/lldiv.c
Normal file
66
libc/upstream-netbsd/lib/libc/stdlib/lldiv.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* $NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)ldiv.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdlib.h> /* lldiv_t */
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(lldiv, _lldiv)
|
||||
#endif
|
||||
|
||||
/* LONGLONG */
|
||||
lldiv_t
|
||||
lldiv(long long int num, long long int denom)
|
||||
{
|
||||
lldiv_t r;
|
||||
|
||||
/* see div.c for comments */
|
||||
|
||||
r.quot = num / denom;
|
||||
r.rem = num % denom;
|
||||
if (num >= 0 && r.rem < 0) {
|
||||
r.quot++;
|
||||
r.rem -= denom;
|
||||
}
|
||||
return (r);
|
||||
}
|
33
libc/upstream-netbsd/lib/libc/stdlib/lrand48.c
Normal file
33
libc/upstream-netbsd/lib/libc/stdlib/lrand48.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* $NetBSD: lrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: lrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(lrand48,_lrand48)
|
||||
#endif
|
||||
|
||||
long
|
||||
lrand48(void)
|
||||
{
|
||||
__dorand48(__rand48_seed);
|
||||
return __rand48_seed[2] * 32768 + (__rand48_seed[1] >> 1);
|
||||
}
|
33
libc/upstream-netbsd/lib/libc/stdlib/mrand48.c
Normal file
33
libc/upstream-netbsd/lib/libc/stdlib/mrand48.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* $NetBSD: mrand48.c,v 1.8 2013/10/22 08:08:51 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: mrand48.c,v 1.8 2013/10/22 08:08:51 matt Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(mrand48,_mrand48)
|
||||
#endif
|
||||
|
||||
long
|
||||
mrand48(void)
|
||||
{
|
||||
__dorand48(__rand48_seed);
|
||||
return (int16_t)__rand48_seed[2] * 65536 + __rand48_seed[1];
|
||||
}
|
38
libc/upstream-netbsd/lib/libc/stdlib/nrand48.c
Normal file
38
libc/upstream-netbsd/lib/libc/stdlib/nrand48.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* $NetBSD: nrand48.c,v 1.10 2013/10/22 08:08:51 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: nrand48.c,v 1.10 2013/10/22 08:08:51 matt Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(nrand48,_nrand48)
|
||||
#endif
|
||||
|
||||
long
|
||||
nrand48(unsigned short xseed[3])
|
||||
{
|
||||
_DIAGASSERT(xseed != NULL);
|
||||
|
||||
__dorand48(xseed);
|
||||
return xseed[2] * 32768 + (xseed[1] >> 1);
|
||||
}
|
49
libc/upstream-netbsd/lib/libc/stdlib/seed48.c
Normal file
49
libc/upstream-netbsd/lib/libc/stdlib/seed48.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* $NetBSD: seed48.c,v 1.8 2005/06/12 05:21:28 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: seed48.c,v 1.8 2005/06/12 05:21:28 lukem Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(seed48,_seed48)
|
||||
#endif
|
||||
|
||||
unsigned short *
|
||||
seed48(unsigned short xseed[3])
|
||||
{
|
||||
static unsigned short sseed[3];
|
||||
|
||||
_DIAGASSERT(xseed != NULL);
|
||||
|
||||
sseed[0] = __rand48_seed[0];
|
||||
sseed[1] = __rand48_seed[1];
|
||||
sseed[2] = __rand48_seed[2];
|
||||
__rand48_seed[0] = xseed[0];
|
||||
__rand48_seed[1] = xseed[1];
|
||||
__rand48_seed[2] = xseed[2];
|
||||
__rand48_mult[0] = RAND48_MULT_0;
|
||||
__rand48_mult[1] = RAND48_MULT_1;
|
||||
__rand48_mult[2] = RAND48_MULT_2;
|
||||
__rand48_add = RAND48_ADD;
|
||||
return sseed;
|
||||
}
|
38
libc/upstream-netbsd/lib/libc/stdlib/srand48.c
Normal file
38
libc/upstream-netbsd/lib/libc/stdlib/srand48.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* $NetBSD: srand48.c,v 1.7 2005/06/12 05:21:28 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Martin Birgmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* You may redistribute unmodified or modified versions of this source
|
||||
* code provided that the above copyright notice and this and the
|
||||
* following conditions are retained.
|
||||
*
|
||||
* This software is provided ``as is'', and comes with no warranties
|
||||
* of any kind. I shall in no event be liable for anything that happens
|
||||
* to anyone/anything when using this software.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: srand48.c,v 1.7 2005/06/12 05:21:28 lukem Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include "rand48.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(srand48,_srand48)
|
||||
#endif
|
||||
|
||||
void
|
||||
srand48(long seed)
|
||||
{
|
||||
__rand48_seed[0] = RAND48_SEED_0;
|
||||
__rand48_seed[1] = (unsigned short) seed;
|
||||
__rand48_seed[2] = (unsigned short) ((unsigned long)seed >> 16);
|
||||
__rand48_mult[0] = RAND48_MULT_0;
|
||||
__rand48_mult[1] = RAND48_MULT_1;
|
||||
__rand48_mult[2] = RAND48_MULT_2;
|
||||
__rand48_add = RAND48_ADD;
|
||||
}
|
67
libc/upstream-netbsd/lib/libc/stdlib/tdelete.c
Normal file
67
libc/upstream-netbsd/lib/libc/stdlib/tdelete.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* $NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Tree search generalized from Knuth (6.2.2) Algorithm T just like
|
||||
* the AT&T man page says.
|
||||
*
|
||||
* The node_t structure is for internal use only, lint doesn't grok it.
|
||||
*
|
||||
* Written by reading the System V Interface Definition, not the code.
|
||||
*
|
||||
* Totally public domain.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#define _SEARCH_PRIVATE
|
||||
#include <search.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/* find a node with key "vkey" in tree "vrootp" */
|
||||
void *
|
||||
tdelete(const void *vkey, void **vrootp,
|
||||
int (*compar)(const void *, const void *))
|
||||
{
|
||||
node_t **rootp = (node_t **)vrootp;
|
||||
node_t *p, *q, *r;
|
||||
int cmp;
|
||||
|
||||
_DIAGASSERT(vkey != NULL);
|
||||
_DIAGASSERT(compar != NULL);
|
||||
|
||||
if (rootp == NULL || (p = *rootp) == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) {
|
||||
p = *rootp;
|
||||
rootp = (cmp < 0) ?
|
||||
&(*rootp)->llink : /* follow llink branch */
|
||||
&(*rootp)->rlink; /* follow rlink branch */
|
||||
if (*rootp == NULL)
|
||||
return NULL; /* key not found */
|
||||
}
|
||||
r = (*rootp)->rlink; /* D1: */
|
||||
if ((q = (*rootp)->llink) == NULL) /* Left NULL? */
|
||||
q = r;
|
||||
else if (r != NULL) { /* Right link is NULL? */
|
||||
if (r->llink == NULL) { /* D2: Find successor */
|
||||
r->llink = q;
|
||||
q = r;
|
||||
} else { /* D3: Find NULL link */
|
||||
for (q = r->llink; q->llink != NULL; q = r->llink)
|
||||
r = q;
|
||||
r->llink = q->rlink;
|
||||
q->llink = (*rootp)->llink;
|
||||
q->rlink = (*rootp)->rlink;
|
||||
}
|
||||
}
|
||||
if (p != *rootp)
|
||||
free(*rootp); /* D4: Free node */
|
||||
*rootp = q; /* link parent to new node */
|
||||
return p;
|
||||
}
|
47
libc/upstream-netbsd/lib/libc/stdlib/tfind.c
Normal file
47
libc/upstream-netbsd/lib/libc/stdlib/tfind.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/* $NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Tree search generalized from Knuth (6.2.2) Algorithm T just like
|
||||
* the AT&T man page says.
|
||||
*
|
||||
* The node_t structure is for internal use only, lint doesn't grok it.
|
||||
*
|
||||
* Written by reading the System V Interface Definition, not the code.
|
||||
*
|
||||
* Totally public domain.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#define _SEARCH_PRIVATE
|
||||
#include <stdlib.h>
|
||||
#include <search.h>
|
||||
|
||||
/* find a node by key "vkey" in tree "vrootp", or return 0 */
|
||||
void *
|
||||
tfind(const void *vkey, void * const *vrootp,
|
||||
int (*compar)(const void *, const void *))
|
||||
{
|
||||
node_t * const *rootp = (node_t * const*)vrootp;
|
||||
|
||||
_DIAGASSERT(vkey != NULL);
|
||||
_DIAGASSERT(compar != NULL);
|
||||
|
||||
if (rootp == NULL)
|
||||
return NULL;
|
||||
|
||||
while (*rootp != NULL) { /* T1: */
|
||||
int r;
|
||||
|
||||
if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
|
||||
return *rootp; /* key found */
|
||||
rootp = (r < 0) ?
|
||||
&(*rootp)->llink : /* T3: follow left branch */
|
||||
&(*rootp)->rlink; /* T4: follow right branch */
|
||||
}
|
||||
return NULL;
|
||||
}
|
56
libc/upstream-netbsd/lib/libc/stdlib/tsearch.c
Normal file
56
libc/upstream-netbsd/lib/libc/stdlib/tsearch.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */
|
||||
|
||||
/*
|
||||
* Tree search generalized from Knuth (6.2.2) Algorithm T just like
|
||||
* the AT&T man page says.
|
||||
*
|
||||
* The node_t structure is for internal use only, lint doesn't grok it.
|
||||
*
|
||||
* Written by reading the System V Interface Definition, not the code.
|
||||
*
|
||||
* Totally public domain.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#define _SEARCH_PRIVATE
|
||||
#include <search.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* find or insert datum into search tree */
|
||||
void *
|
||||
tsearch(const void *vkey, void **vrootp,
|
||||
int (*compar)(const void *, const void *))
|
||||
{
|
||||
node_t *q;
|
||||
node_t **rootp = (node_t **)vrootp;
|
||||
|
||||
_DIAGASSERT(vkey != NULL);
|
||||
_DIAGASSERT(compar != NULL);
|
||||
|
||||
if (rootp == NULL)
|
||||
return NULL;
|
||||
|
||||
while (*rootp != NULL) { /* Knuth's T1: */
|
||||
int r;
|
||||
|
||||
if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
|
||||
return *rootp; /* we found it! */
|
||||
|
||||
rootp = (r < 0) ?
|
||||
&(*rootp)->llink : /* T3: follow left branch */
|
||||
&(*rootp)->rlink; /* T4: follow right branch */
|
||||
}
|
||||
|
||||
q = malloc(sizeof(node_t)); /* T5: key not found */
|
||||
if (q != 0) { /* make new node */
|
||||
*rootp = q; /* link new node to old */
|
||||
q->key = __UNCONST(vkey); /* initialize new node */
|
||||
q->llink = q->rlink = NULL;
|
||||
}
|
||||
return q;
|
||||
}
|
61
libc/upstream-netbsd/lib/libc/string/memccpy.c
Normal file
61
libc/upstream-netbsd/lib/libc/string/memccpy.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */
|
||||
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memccpy(void *t, const void *f, int c, size_t n)
|
||||
{
|
||||
|
||||
_DIAGASSERT(t != 0);
|
||||
_DIAGASSERT(f != 0);
|
||||
|
||||
if (n) {
|
||||
unsigned char *tp = t;
|
||||
const unsigned char *fp = f;
|
||||
unsigned char uc = c;
|
||||
do {
|
||||
if ((*tp++ = *fp++) == uc)
|
||||
return (tp);
|
||||
} while (--n != 0);
|
||||
}
|
||||
return (0);
|
||||
}
|
69
libc/upstream-netbsd/lib/libc/string/strcasestr.c
Normal file
69
libc/upstream-netbsd/lib/libc/string/strcasestr.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, ignore case.
|
||||
*/
|
||||
char *
|
||||
strcasestr(const char *s, const char *find)
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(find != NULL);
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower((unsigned char)c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
} while ((char)tolower((unsigned char)sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return __UNCONST(s);
|
||||
}
|
59
libc/upstream-netbsd/lib/libc/string/strcoll.c
Normal file
59
libc/upstream-netbsd/lib/libc/string/strcoll.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* $NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Compare strings according to LC_COLLATE category of current locale.
|
||||
*/
|
||||
int
|
||||
strcoll(const char *s1, const char *s2)
|
||||
{
|
||||
|
||||
_DIAGASSERT(s1 != NULL);
|
||||
_DIAGASSERT(s2 != NULL);
|
||||
|
||||
/* LC_COLLATE is unimplemented, hence always "C" */
|
||||
return (strcmp(s1, s2));
|
||||
}
|
70
libc/upstream-netbsd/lib/libc/string/strxfrm.c
Normal file
70
libc/upstream-netbsd/lib/libc/string/strxfrm.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* $NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Transform src, storing the result in dst, such that
|
||||
* strcmp() on transformed strings returns what strcoll()
|
||||
* on the original untransformed strings would return.
|
||||
*/
|
||||
size_t
|
||||
strxfrm(char *dst, const char *src, size_t n)
|
||||
{
|
||||
size_t srclen, copysize;
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
|
||||
/*
|
||||
* Since locales are unimplemented, this is just a copy.
|
||||
*/
|
||||
srclen = strlen(src);
|
||||
if (n != 0) {
|
||||
_DIAGASSERT(dst != NULL);
|
||||
copysize = srclen < n ? srclen : n - 1;
|
||||
(void)memcpy(dst, src, copysize);
|
||||
dst[copysize] = 0;
|
||||
}
|
||||
return (srclen);
|
||||
}
|
37
libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c
Normal file
37
libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* $NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Michael Graff.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
int __isthreaded = 0;
|
56
libc/upstream-netbsd/lib/libc/unistd/killpg.c
Normal file
56
libc/upstream-netbsd/lib/libc/unistd/killpg.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* $NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)killpg.c 8.1 (Berkeley) 6/2/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* Backwards-compatible killpg().
|
||||
*/
|
||||
int
|
||||
killpg(pid_t pgid, int sig)
|
||||
{
|
||||
if (pgid == 1) {
|
||||
errno = ESRCH;
|
||||
return (-1);
|
||||
}
|
||||
return (kill(-pgid, sig));
|
||||
}
|
Reference in New Issue
Block a user