Removed unneeded sources.

Just noticed that VI did not like my copy-pasted commit log. It should be: we _need_ better pthread/mutex support. Here is the important part, again:
Cleaned up native part of libbind.so a little bit more. Though, the ugly hack remains. We need better pthread/mutex support. Added TODO that we also should move sysctl() into the kernel and libroot.so.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15606 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald 2005-12-20 10:58:47 +00:00
parent ce823541ec
commit 5af343b54b
6 changed files with 0 additions and 783 deletions

View File

@ -1,146 +0,0 @@
/*
* Arc4 random number generator for OpenBSD.
* Copyright 1996 David Mazieres <dm@lcs.mit.edu>.
*
* Modification and redistribution in source and binary forms is
* permitted provided that due credit is given to the author and the
* OpenBSD project by leaving this copyright notice intact.
*/
/*
* This code is derived from section 17.1 of Applied Cryptography,
* second edition, which describes a stream cipher allegedly
* compatible with RSA Labs "RC4" cipher (the actual description of
* which is a trade secret). The same algorithm is used as a stream
* cipher called "arcfour" in Tatu Ylonen's ssh package.
*
* Here the stream cipher has been modified always to include the time
* when initializing the state. That makes it impossible to
* regenerate the same random sequence twice, so this can't be used
* for encryption, but will generate good random numbers.
*
* RC4 is a registered trademark of RSA Laboratories.
*/
#include <kernel/OS.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#ifdef __GNUC__
#define inline __inline
#else /* !__GNUC__ */
#define inline
#endif /* !__GNUC__ */
struct arc4_stream {
uint8 i;
uint8 j;
uint8 s[256];
};
int rs_initialized;
static struct arc4_stream rs;
static inline void arc4_init(struct arc4_stream *as)
{
int n;
for (n = 0; n < 256; n++)
as->s[n] = n;
as->i = 0;
as->j = 0;
}
static inline void arc4_addrandom(struct arc4_stream *as,
u_char *dat, int datlen)
{
int n;
uint8 si;
as->i--;
for (n = 0; n < 256; n++) {
as->i = (as->i + 1);
si = as->s[as->i];
as->j = (as->j + si + dat[n % datlen]);
as->s[as->i] = as->s[as->j];
as->s[as->j] = si;
}
as->j = as->i;
}
static void arc4_stir(struct arc4_stream *as)
{
int fd;
struct {
struct timeval tv;
u_int rnd[(128 - sizeof(struct timeval)) / sizeof(u_int)];
} rdat;
gettimeofday(&rdat.tv, NULL);
fd = open("/dev/arandom", O_RDONLY);
if (fd != -1) {
read(fd, rdat.rnd, sizeof(rdat.rnd));
close(fd);
}
/* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take
* whatever was on the stack... */
arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
}
static inline uint8 arc4_getbyte(struct arc4_stream *as)
{
uint8 si, sj;
as->i = (as->i + 1);
si = as->s[as->i];
as->j = (as->j + si);
sj = as->s[as->j];
as->s[as->i] = sj;
as->s[as->j] = si;
return (as->s[(si + sj) & 0xff]);
}
static inline uint32 arc4_getword(struct arc4_stream *as)
{
uint32 val;
val = arc4_getbyte(as) << 24;
val |= arc4_getbyte(as) << 16;
val |= arc4_getbyte(as) << 8;
val |= arc4_getbyte(as);
return val;
}
void arc4random_stir(void)
{
if (!rs_initialized) {
arc4_init(&rs);
rs_initialized = 1;
}
arc4_stir(&rs);
}
void arc4random_addrandom(u_char *dat, int datlen)
{
if (!rs_initialized)
arc4random_stir();
arc4_addrandom(&rs, dat, datlen);
}
uint32 arc4random()
{
if (!rs_initialized)
arc4random_stir();
return arc4_getword(&rs);
}

View File

@ -1,261 +0,0 @@
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``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.
*/
/*
* ethers(3) a la Sun.
* Originally Written by Roland McGrath <roland@frob.com> 10/14/93.
* Substantially modified by Todd C. Miller <Todd.Miller@courtesan.com>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef YP
#include <rpcsvc/ypclnt.h>
#endif
#include "netdb.h" /* for MAXHOSTNAMELEN */
#ifndef _PATH_ETHERS
#define _PATH_ETHERS "/etc/ethers"
#endif
static char * _ether_aton (char *, struct ether_addr *);
char *ether_ntoa(struct ether_addr *e)
{
static char a[] = "xx:xx:xx:xx:xx:xx";
if (e->ether_addr_octet[0] > 0xFF || e->ether_addr_octet[1] > 0xFF ||
e->ether_addr_octet[2] > 0xFF || e->ether_addr_octet[3] > 0xFF ||
e->ether_addr_octet[4] > 0xFF || e->ether_addr_octet[5] > 0xFF) {
errno = EINVAL;
return (NULL);
}
(void)sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
e->ether_addr_octet[4], e->ether_addr_octet[5]);
return (a);
}
static char *_ether_aton(char *s, struct ether_addr *e)
{
int i;
long l;
char *pp;
while (isspace(*s))
s++;
/* expect 6 hex octets separated by ':' or space/NUL if last octet */
for (i = 0; i < 6; i++) {
l = strtol(s, &pp, 16);
if (pp == s || l > 0xFF || l < 0)
return (NULL);
if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0'))))
return (NULL);
e->ether_addr_octet[i] = (u_char)l;
s = pp + 1;
}
/* return character after the octets ala strtol(3) */
return (pp);
}
struct ether_addr *ether_aton(char *s)
{
static struct ether_addr n;
return (_ether_aton(s, &n) ? &n : NULL);
}
int ether_ntohost(char *hostname, struct ether_addr *e)
{
FILE *f;
char buf[BUFSIZ+1], *p;
size_t len;
struct ether_addr try;
char lbuf[80];
#ifdef YP
char trybuf[sizeof("xx:xx:xx:xx:xx:xx")];
int trylen;
#endif
if (e->ether_addr_octet[0] > 0xFF || e->ether_addr_octet[1] > 0xFF ||
e->ether_addr_octet[2] > 0xFF || e->ether_addr_octet[3] > 0xFF ||
e->ether_addr_octet[4] > 0xFF || e->ether_addr_octet[5] > 0xFF) {
errno = EINVAL;
return (-1);
}
#ifdef YP
sprintf(trybuf, "%x:%x:%x:%x:%x:%x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
e->ether_addr_octet[4], e->ether_addr_octet[5]);
trylen = strlen(trybuf);
#endif
f = fopen(_PATH_ETHERS, "r");
if (f == NULL)
return (-1);
while (fgets(lbuf, 80, f) != NULL) {
len = strlen(lbuf);
p = lbuf;
if (p[len-1] == '\n')
len--;
if (len > sizeof(buf) - 2)
continue;
(void)memcpy(buf, p, len);
buf[len] = '\n'; /* code assumes newlines later on */
buf[len+1] = '\0';
#ifdef YP
/* A + in the file means try YP now. */
if (!strncmp(buf, "+\n", sizeof(buf))) {
char *ypbuf, *ypdom;
int ypbuflen;
if (yp_get_default_domain(&ypdom))
continue;
if (yp_match(ypdom, "ethers.byaddr", trybuf,
trylen, &ypbuf, &ypbuflen))
continue;
if (ether_line(ypbuf, &try, hostname) == 0) {
free(ypbuf);
(void)fclose(f);
return (0);
}
free(ypbuf);
continue;
}
#endif
if (ether_line(buf, &try, hostname) == 0 &&
memcmp((void *)&try, (void *)e, sizeof(try)) == 0) {
(void)fclose(f);
return (0);
}
}
(void)fclose(f);
errno = ENOENT;
return (-1);
}
int
ether_hostton(hostname, e)
char *hostname;
struct ether_addr *e;
{
FILE *f;
char buf[BUFSIZ+1], *p;
char try[MAXHOSTNAMELEN];
size_t len;
char lbuf[80];
#ifdef YP
int hostlen = strlen(hostname);
#endif
f = fopen(_PATH_ETHERS, "r");
if (f==NULL)
return (-1);
while (fgets(lbuf, 80, f) != NULL) {
len = strlen(lbuf);
p = lbuf;
if (p[len-1] == '\n')
len--;
if (len > sizeof(buf) - 2)
continue;
memcpy(buf, p, len);
buf[len] = '\n'; /* code assumes newlines later on */
buf[len+1] = '\0';
#ifdef YP
/* A + in the file means try YP now. */
if (!strncmp(buf, "+\n", sizeof(buf))) {
char *ypbuf, *ypdom;
int ypbuflen;
if (yp_get_default_domain(&ypdom))
continue;
if (yp_match(ypdom, "ethers.byname", hostname, hostlen,
&ypbuf, &ypbuflen))
continue;
if (ether_line(ypbuf, e, try) == 0) {
free(ypbuf);
(void)fclose(f);
return (0);
}
free(ypbuf);
continue;
}
#endif
if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) {
(void)fclose(f);
return (0);
}
}
(void)fclose(f);
errno = ENOENT;
return (-1);
}
int ether_line(char *line, struct ether_addr *e, char *hostname)
{
char *p;
size_t n;
/* Parse "xx:xx:xx:xx:xx:xx" */
if ((p = _ether_aton(line, e)) == NULL || (*p != ' ' && *p != '\t'))
goto bad;
/* Now get the hostname */
while (isspace(*p))
p++;
if (*p == '\0')
goto bad;
n = strcspn(p, " \t\n");
if (n >= MAXHOSTNAMELEN)
goto bad;
strncpy(hostname, p, n + 1);
return (0);
bad:
errno = EINVAL;
return (-1);
}

View File

@ -1,62 +0,0 @@
#ifndef LINT
static const char rcsid[] = "$Id: gettimeofday.c,v 1.1.2.2 2002/07/12 00:49:51 marka Exp $";
#endif
#include "port_before.h"
#include <stdio.h>
#include <syslog.h>
#include <sys/time.h>
#include "port_after.h"
#if !defined(NEED_GETTIMEOFDAY)
/*
* gettimeofday() occasionally returns invalid tv_usec on some platforms.
*/
#define MILLION 1000000
#undef gettimeofday
int
isc__gettimeofday(struct timeval *tp, struct timezone *tzp) {
int res;
res = gettimeofday(tp, tzp);
if (res < 0)
return (res);
if (tp == NULL)
return (res);
if (tp->tv_usec < 0) {
do {
tp->tv_usec += MILLION;
tp->tv_sec--;
} while (tp->tv_usec < 0);
goto log;
} else if (tp->tv_usec > MILLION) {
do {
tp->tv_usec -= MILLION;
tp->tv_sec++;
} while (tp->tv_usec > MILLION);
goto log;
}
return (res);
log:
syslog(LOG_ERR, "gettimeofday: tv_usec out of range\n");
return (res);
}
#else
int
gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp) {
time_t clock, time(time_t *);
if (time(&clock) == (time_t) -1)
return (-1);
if (tvp) {
tvp->tv_sec = clock;
tvp->tv_usec = 0;
}
if (tzp) {
tzp->tz_minuteswest = 0;
tzp->tz_dsttime = 0;
}
return (0);
}
#endif /*NEED_GETTIMEOFDAY*/

View File

@ -1,155 +0,0 @@
/*-
* 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. 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.
*/
#include <sys/types.h>
#include <kernel/OS.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <string.h>
/* States*/
#define NAMING 0
#define GOTONE 1
#define GOTTWO 2
#define RESET 3
/* Inputs */
#define DIGIT (4*0)
#define END (4*1)
#define DELIM (4*2)
#define LETTER (4*3)
void
link_addr(addr, sdl)
register const char *addr;
register struct sockaddr_dl *sdl;
{
register char *cp = sdl->sdl_data;
char *cplim = sdl->sdl_len + (char *)sdl;
register int byte = 0, state = NAMING, newv = 0;
memset((char *)&sdl->sdl_family, 0, sdl->sdl_len - 1);
sdl->sdl_family = AF_LINK;
do {
state &= ~LETTER;
if ((*addr >= '0') && (*addr <= '9')) {
newv = *addr - '0';
} else if ((*addr >= 'a') && (*addr <= 'f')) {
newv = *addr - 'a' + 10;
} else if ((*addr >= 'A') && (*addr <= 'F')) {
newv = *addr - 'A' + 10;
} else if (*addr == 0) {
state |= END;
} else if (state == NAMING &&
(((*addr >= 'A') && (*addr <= 'Z')) ||
((*addr >= 'a') && (*addr <= 'z'))))
state |= LETTER;
else
state |= DELIM;
addr++;
switch (state /* | INPUT */) {
case NAMING | DIGIT:
case NAMING | LETTER:
*cp++ = addr[-1];
continue;
case NAMING | DELIM:
state = RESET;
sdl->sdl_nlen = cp - sdl->sdl_data;
continue;
case GOTTWO | DIGIT:
*cp++ = byte;
/* FALLTHROUGH */
case RESET | DIGIT:
state = GOTONE;
byte = newv;
continue;
case GOTONE | DIGIT:
state = GOTTWO;
byte = newv + (byte << 4);
continue;
default: /* | DELIM */
state = RESET;
*cp++ = byte;
byte = 0;
continue;
case GOTONE | END:
case GOTTWO | END:
*cp++ = byte;
/* FALLTHROUGH */
case RESET | END:
break;
}
break;
} while (cp < cplim);
sdl->sdl_alen = cp - LLADDR(sdl);
newv = cp - (char *)sdl;
if (newv > (int) sizeof(*sdl))
sdl->sdl_len = newv;
return;
}
static char hexlist[] = "0123456789abcdef";
char *
link_ntoa(sdl)
register const struct sockaddr_dl *sdl;
{
static char obuf[64];
register char *out = obuf;
register int i;
register u_char *in = (u_char *)LLADDR(sdl);
u_char *inlim = in + sdl->sdl_alen;
int firsttime = 1;
if (sdl->sdl_nlen) {
memcpy(obuf, sdl->sdl_data, sdl->sdl_nlen);
out += sdl->sdl_nlen;
if (sdl->sdl_alen)
*out++ = ':';
}
while (in < inlim) {
if (firsttime)
firsttime = 0;
else
*out++ = '.';
i = *in++;
if (i > 0xf) {
out[1] = hexlist[i & 0xf];
i >>= 4;
out[0] = hexlist[i];
out += 2;
} else
*out++ = hexlist[i];
}
*out = 0;
return (obuf);
}

View File

@ -1,73 +0,0 @@
/*
* ++Copyright++ 1995
* -
* Copyright (c) 1995
* 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. 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.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* 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, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION 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.
* -
* --Copyright--
*/
const char *_res_resultcodes[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"REFUSED",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"NOCHANGE",
};

View File

@ -1,86 +0,0 @@
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "strsep.c 8.1 (Berkeley) 6/4/93";
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/*
* 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. 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.
*/
#include "port_before.h"
#include <sys/cdefs.h>
#include <string.h>
#include <stdio.h>
#include "port_after.h"
#ifndef NEED_STRSEP
int __strsep_unneeded__;
#else
/*
* Get next token from string *stringp, where tokens are possibly-empty
* strings separated by characters from delim.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
* On return, *stringp points past the last NUL written (if there might
* be further tokens), or is NULL (if there are definitely no more tokens).
*
* If *stringp is NULL, strsep returns NULL.
*/
char *
strsep(char **stringp, const char *delim) {
char *s;
const char *spanp;
int c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
#endif /*NEED_STRSEP*/