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));
|
||||
}
|
Reference in New Issue
Block a user