libc: port FreeBSD string library routines
Oh my fucking god this was by far the most awful and boring and tedious day in my entire life. Also, dear FreeBSD people: please don't sue me. I tried really hard to comply with all the copyright stuff, but it is absolutely possible i made a mistake. Just DM me and i'll do everything in my power to fix it, even if that means releasing entire portions of GayBSD under the BSD license. I don't care, i just want stuff to work. (i'm including this message to use it as possible evidence in case i get sued to show my good will)main
parent
4679b7cee5
commit
0f9e9f91a6
@ -0,0 +1,108 @@
|
||||
The compilation of software known as GayBSD is distributed under the
|
||||
following terms:
|
||||
|
||||
Copyright (c) 2021 The GayBSD Project.
|
||||
|
||||
GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
modify it under the terms of the Cooperative Nonviolent Public License
|
||||
(CNPL) as found in the LICENSE file or at
|
||||
<https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
of the license, or (at your option) any later version.
|
||||
|
||||
GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
permitted by applicable law. See the CNPL for details.
|
||||
|
||||
The compilation of software known as FreeBSD is distributed under the
|
||||
following terms:
|
||||
|
||||
Copyright (c) 1992-2021 The FreeBSD Project.
|
||||
|
||||
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 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 AUTHOR 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.
|
||||
|
||||
The 4.4BSD and 4.4BSD-Lite software is distributed under the following
|
||||
terms:
|
||||
|
||||
All of the documentation and software included in the 4.4BSD and 4.4BSD-Lite
|
||||
Releases is copyrighted by The Regents of the University of California.
|
||||
|
||||
Copyright 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
|
||||
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.
|
||||
|
||||
|
||||
NOTE: The copyright of UC Berkeley's Berkeley Software Distribution ("BSD")
|
||||
source has been updated. The copyright addendum may be found at
|
||||
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change and is
|
||||
included below.
|
||||
|
||||
July 22, 1999
|
||||
|
||||
To All Licensees, Distributors of Any Version of BSD:
|
||||
|
||||
As you know, certain of the Berkeley Software Distribution ("BSD") source
|
||||
code files require that further distributions of products containing all or
|
||||
portions of the software, acknowledge within their advertising materials
|
||||
that such products contain software developed by UC Berkeley and its
|
||||
contributors.
|
||||
|
||||
Specifically, the provision reads:
|
||||
|
||||
" * 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."
|
||||
|
||||
Effective immediately, licensees and distributors are no longer required to
|
||||
include the acknowledgement within advertising materials. Accordingly, the
|
||||
foregoing paragraph of those BSD Unix files containing it is hereby deleted
|
||||
in its entirety.
|
||||
|
||||
William Hoskins
|
||||
Director, Office of Technology Licensing
|
||||
University of California, Berkeley
|
@ -0,0 +1,116 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* According to ANSI (section 2.2.4.2), the values below must be usable by
|
||||
* #if preprocessing directives. Additionally, the expression must have the
|
||||
* same type as would an expression that is an object of the corresponding
|
||||
* type converted according to the integral promotions. The subtraction for
|
||||
* INT_MIN, etc., is so the value is not unsigned; e.g., 0x80000000 is an
|
||||
* unsigned int for 32-bit two's complement ANSI compilers (section 3.1.3.2).
|
||||
*/
|
||||
|
||||
#define __CHAR_BIT 8 /* number of bits in a char */
|
||||
|
||||
#define __SCHAR_MAX 0x7f /* max value for a signed char */
|
||||
#define __SCHAR_MIN (-0x7f - 1) /* min value for a signed char */
|
||||
|
||||
#define __UCHAR_MAX 0xff /* max value for an unsigned char */
|
||||
|
||||
#define __USHRT_MAX 0xffff /* max value for an unsigned short */
|
||||
#define __SHRT_MAX 0x7fff /* max value for a short */
|
||||
#define __SHRT_MIN (-0x7fff - 1) /* min value for a short */
|
||||
|
||||
#define __UINT_MAX 0xffffffff /* max value for an unsigned int */
|
||||
#define __INT_MAX 0x7fffffff /* max value for an int */
|
||||
#define __INT_MIN (-0x7fffffff - 1) /* min value for an int */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define __ULONG_MAX 0xffffffffffffffff /* max for an unsigned long */
|
||||
#define __LONG_MAX 0x7fffffffffffffff /* max for a long */
|
||||
#define __LONG_MIN (-0x7fffffffffffffff - 1) /* min for a long */
|
||||
#else
|
||||
#define __ULONG_MAX 0xffffffffUL
|
||||
#define __LONG_MAX 0x7fffffffL
|
||||
#define __LONG_MIN (-0x7fffffffL - 1)
|
||||
#endif
|
||||
|
||||
/* max value for an unsigned long long */
|
||||
#define __ULLONG_MAX 0xffffffffffffffffULL
|
||||
#define __LLONG_MAX 0x7fffffffffffffffLL /* max value for a long long */
|
||||
#define __LLONG_MIN (-0x7fffffffffffffffLL - 1) /* min for a long long */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define __SSIZE_MAX __LONG_MAX /* max value for a ssize_t */
|
||||
#define __SIZE_T_MAX __ULONG_MAX /* max value for a size_t */
|
||||
#define __OFF_MAX __LONG_MAX /* max value for an off_t */
|
||||
#define __OFF_MIN __LONG_MIN /* min value for an off_t */
|
||||
/* Quads and longs are the same on the amd64. Ensure they stay in sync. */
|
||||
#define __UQUAD_MAX __ULONG_MAX /* max value for a uquad_t */
|
||||
#define __QUAD_MAX __LONG_MAX /* max value for a quad_t */
|
||||
#define __QUAD_MIN __LONG_MIN /* min value for a quad_t */
|
||||
#define __LONG_BIT 64
|
||||
#else
|
||||
#define __SSIZE_MAX __INT_MAX
|
||||
#define __SIZE_T_MAX __UINT_MAX
|
||||
#define __OFF_MAX __LLONG_MAX
|
||||
#define __OFF_MIN __LLONG_MIN
|
||||
#define __UQUAD_MAX __ULLONG_MAX
|
||||
#define __QUAD_MAX __LLONG_MAX
|
||||
#define __QUAD_MIN __LLONG_MIN
|
||||
#define __LONG_BIT 32
|
||||
#endif
|
||||
|
||||
#define __WORD_BIT 32
|
||||
|
||||
/* Minimum signal stack size. */
|
||||
#define __MINSIGSTKSZ (512 * 4)
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* @(#)limits.h 8.3 (Berkeley) 1/4/94
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,207 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
#define _MACHINE__STDINT_H_
|
||||
|
||||
#include <arch/_limits.h>
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
|
||||
|
||||
#define INT8_C(c) (c)
|
||||
#define INT16_C(c) (c)
|
||||
#define INT32_C(c) (c)
|
||||
|
||||
#define UINT8_C(c) (c)
|
||||
#define UINT16_C(c) (c)
|
||||
#define UINT32_C(c) (c ## U)
|
||||
|
||||
#ifdef __LP64__
|
||||
#define INT64_C(c) (c ## L)
|
||||
#define UINT64_C(c) (c ## UL)
|
||||
#else
|
||||
#define INT64_C(c) (c ## LL)
|
||||
#define UINT64_C(c) (c ## ULL)
|
||||
#endif
|
||||
|
||||
#define INTMAX_C(c) INT64_C(c)
|
||||
#define UINTMAX_C(c) UINT64_C(c)
|
||||
|
||||
#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
|
||||
|
||||
/*
|
||||
* ISO/IEC 9899:1999
|
||||
* 7.18.2.1 Limits of exact-width integer types
|
||||
*/
|
||||
#define INT8_MIN (-0x7f-1)
|
||||
#define INT16_MIN (-0x7fff-1)
|
||||
#define INT32_MIN (-0x7fffffff-1)
|
||||
|
||||
#define INT8_MAX 0x7f
|
||||
#define INT16_MAX 0x7fff
|
||||
#define INT32_MAX 0x7fffffff
|
||||
|
||||
#define UINT8_MAX 0xff
|
||||
#define UINT16_MAX 0xffff
|
||||
#define UINT32_MAX 0xffffffffU
|
||||
|
||||
#ifdef __LP64__
|
||||
#define INT64_MIN (-0x7fffffffffffffff-1)
|
||||
#define INT64_MAX 0x7fffffffffffffff
|
||||
#define UINT64_MAX 0xffffffffffffffff
|
||||
#else
|
||||
#define INT64_MIN (-0x7fffffffffffffffLL-1)
|
||||
#define INT64_MAX 0x7fffffffffffffffLL
|
||||
#define UINT64_MAX 0xffffffffffffffffULL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ISO/IEC 9899:1999
|
||||
* 7.18.2.2 Limits of minimum-width integer types
|
||||
*/
|
||||
/* Minimum values of minimum-width signed integer types. */
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
|
||||
/* Maximum values of minimum-width signed integer types. */
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
|
||||
/* Maximum values of minimum-width unsigned integer types. */
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
/*
|
||||
* ISO/IEC 9899:1999
|
||||
* 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
*/
|
||||
/* Minimum values of fastest minimum-width signed integer types. */
|
||||
#define INT_FAST8_MIN INT32_MIN
|
||||
#define INT_FAST16_MIN INT32_MIN
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
|
||||
/* Maximum values of fastest minimum-width signed integer types. */
|
||||
#define INT_FAST8_MAX INT32_MAX
|
||||
#define INT_FAST16_MAX INT32_MAX
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
|
||||
/* Maximum values of fastest minimum-width unsigned integer types. */
|
||||
#define UINT_FAST8_MAX UINT32_MAX
|
||||
#define UINT_FAST16_MAX UINT32_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
/*
|
||||
* ISO/IEC 9899:1999
|
||||
* 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
*/
|
||||
#ifdef __LP64__
|
||||
#define INTPTR_MIN INT64_MIN
|
||||
#define INTPTR_MAX INT64_MAX
|
||||
#define UINTPTR_MAX UINT64_MAX
|
||||
#else
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ISO/IEC 9899:1999
|
||||
* 7.18.2.5 Limits of greatest-width integer types
|
||||
*/
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
/*
|
||||
* ISO/IEC 9899:1999
|
||||
* 7.18.3 Limits of other integer types
|
||||
*/
|
||||
#ifdef __LP64__
|
||||
/* Limits of ptrdiff_t. */
|
||||
#define PTRDIFF_MIN INT64_MIN
|
||||
#define PTRDIFF_MAX INT64_MAX
|
||||
|
||||
/* Limits of sig_atomic_t. */
|
||||
#define SIG_ATOMIC_MIN __LONG_MIN
|
||||
#define SIG_ATOMIC_MAX __LONG_MAX
|
||||
|
||||
/* Limit of size_t. */
|
||||
#define SIZE_MAX UINT64_MAX
|
||||
#else
|
||||
#define PTRDIFF_MIN INT32_MIN
|
||||
#define PTRDIFF_MAX INT32_MAX
|
||||
#define SIG_ATOMIC_MIN INT32_MIN
|
||||
#define SIG_ATOMIC_MAX INT32_MAX
|
||||
#define SIZE_MAX UINT32_MAX
|
||||
#endif
|
||||
|
||||
/* Limits of wint_t. */
|
||||
#define WINT_MIN INT32_MIN
|
||||
#define WINT_MAX INT32_MAX
|
||||
|
||||
#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2001, 2002 Mike Barcroft <mike@FreeBSD.org>
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Klaus Klein.
|
||||
*
|
||||
* 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 NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation 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 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,149 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _SYS_CDEFS_H_
|
||||
#error this file needs sys/cdefs.h as a prerequisite
|
||||
#endif
|
||||
|
||||
#include <arch/_limits.h>
|
||||
|
||||
#define __NO_STRICT_ALIGNMENT
|
||||
|
||||
/*
|
||||
* Basic types upon which most other types are built.
|
||||
*/
|
||||
typedef signed char __int8_t;
|
||||
typedef unsigned char __uint8_t;
|
||||
typedef short __int16_t;
|
||||
typedef unsigned short __uint16_t;
|
||||
typedef int __int32_t;
|
||||
typedef unsigned int __uint32_t;
|
||||
#ifdef __LP64__
|
||||
typedef long __int64_t;
|
||||
typedef unsigned long __uint64_t;
|
||||
#else
|
||||
__extension__
|
||||
typedef long long __int64_t;
|
||||
__extension__
|
||||
typedef unsigned long long __uint64_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Standard type definitions.
|
||||
*/
|
||||
#ifdef __LP64__
|
||||
typedef __int32_t __clock_t; /* clock()... */
|
||||
typedef __int64_t __critical_t;
|
||||
#ifndef _STANDALONE
|
||||
typedef double __double_t;
|
||||
typedef float __float_t;
|
||||
#endif
|
||||
typedef __int64_t __intfptr_t;
|
||||
typedef __int64_t __intptr_t;
|
||||
#else
|
||||
typedef unsigned long __clock_t;
|
||||
typedef __int32_t __critical_t;
|
||||
#ifndef _STANDALONE
|
||||
typedef long double __double_t;
|
||||
typedef long double __float_t;
|
||||
#endif
|
||||
typedef __int32_t __intfptr_t;
|
||||
typedef __int32_t __intptr_t;
|
||||
#endif
|
||||
typedef __int64_t __intmax_t;
|
||||
typedef __int32_t __int_fast8_t;
|
||||
typedef __int32_t __int_fast16_t;
|
||||
typedef __int32_t __int_fast32_t;
|
||||
typedef __int64_t __int_fast64_t;
|
||||
typedef __int8_t __int_least8_t;
|
||||
typedef __int16_t __int_least16_t;
|
||||
typedef __int32_t __int_least32_t;
|
||||
typedef __int64_t __int_least64_t;
|
||||
#ifdef __LP64__
|
||||
typedef __int64_t __ptrdiff_t; /* ptr1 - ptr2 */
|
||||
typedef __int64_t __register_t;
|
||||
typedef __int64_t __segsz_t; /* segment size (in pages) */
|
||||
typedef __uint64_t __size_t; /* sizeof() */
|
||||
typedef __int64_t __ssize_t; /* byte count or error */
|
||||
typedef __int64_t __time_t; /* time()... */
|
||||
typedef __uint64_t __uintfptr_t;
|
||||
typedef __uint64_t __uintptr_t;
|
||||
#else
|
||||
typedef __int32_t __ptrdiff_t;
|
||||
typedef __int32_t __register_t;
|
||||
typedef __int32_t __segsz_t;
|
||||
typedef __uint32_t __size_t;
|
||||
typedef __int32_t __ssize_t;
|
||||
typedef __int32_t __time_t;
|
||||
typedef __uint32_t __uintfptr_t;
|
||||
typedef __uint32_t __uintptr_t;
|
||||
#endif
|
||||
typedef __uint64_t __uintmax_t;
|
||||
typedef __uint32_t __uint_fast8_t;
|
||||
typedef __uint32_t __uint_fast16_t;
|
||||
typedef __uint32_t __uint_fast32_t;
|
||||
typedef __uint64_t __uint_fast64_t;
|
||||
typedef __uint8_t __uint_least8_t;
|
||||
typedef __uint16_t __uint_least16_t;
|
||||
typedef __uint32_t __uint_least32_t;
|
||||
typedef __uint64_t __uint_least64_t;
|
||||
#ifdef __LP64__
|
||||
typedef __uint64_t __u_register_t;
|
||||
typedef __uint64_t __vm_offset_t;
|
||||
typedef __uint64_t __vm_paddr_t;
|
||||
typedef __uint64_t __vm_size_t;
|
||||
#else
|
||||
typedef __uint32_t __u_register_t;
|
||||
typedef __uint32_t __vm_offset_t;
|
||||
typedef __uint64_t __vm_paddr_t;
|
||||
typedef __uint32_t __vm_size_t;
|
||||
#endif
|
||||
typedef int ___wchar_t;
|
||||
|
||||
#define __WCHAR_MIN __INT_MIN /* min value for a wchar_t */
|
||||
#define __WCHAR_MAX __INT_MAX /* max value for a wchar_t */
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,115 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* According to ANSI (section 2.2.4.2), the values below must be usable by
|
||||
* #if preprocessing directives. Additionally, the expression must have the
|
||||
* same type as would an expression that is an object of the corresponding
|
||||
* type converted according to the integral promotions. The subtraction for
|
||||
* INT_MIN, etc., is so the value is not unsigned; e.g., 0x80000000 is an
|
||||
* unsigned int for 32-bit two's complement ANSI compilers (section 3.1.3.2).
|
||||
*/
|
||||
|
||||
#define __CHAR_BIT 8 /* number of bits in a char */
|
||||
|
||||
#define __SCHAR_MAX 0x7f /* max value for a signed char */
|
||||
#define __SCHAR_MIN (-0x7f - 1) /* min value for a signed char */
|
||||
|
||||
#define __UCHAR_MAX 0xff /* max value for an unsigned char */
|
||||
|
||||
#define __USHRT_MAX 0xffff /* max value for an unsigned short */
|
||||
#define __SHRT_MAX 0x7fff /* max value for a short */
|
||||
#define __SHRT_MIN (-0x7fff - 1) /* min value for a short */
|
||||
|
||||
#define __UINT_MAX 0xffffffff /* max value for an unsigned int */
|
||||
#define __INT_MAX 0x7fffffff /* max value for an int */
|
||||
#define __INT_MIN (-0x7fffffff - 1) /* min value for an int */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define __ULONG_MAX 0xffffffffffffffff /* max for an unsigned long */
|
||||
#define __LONG_MAX 0x7fffffffffffffff /* max for a long */
|
||||
#define __LONG_MIN (-0x7fffffffffffffff - 1) /* min for a long */
|
||||
#else
|
||||
#define __ULONG_MAX 0xffffffffUL
|
||||
#define __LONG_MAX 0x7fffffffL
|
||||
#define __LONG_MIN (-0x7fffffffL - 1)
|
||||
#endif
|
||||
|
||||
/* max value for an unsigned long long */
|
||||
#define __ULLONG_MAX 0xffffffffffffffffULL
|
||||
#define __LLONG_MAX 0x7fffffffffffffffLL /* max value for a long long */
|
||||
#define __LLONG_MIN (-0x7fffffffffffffffLL - 1) /* min for a long long */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define __SSIZE_MAX __LONG_MAX /* max value for a ssize_t */
|
||||
#define __SIZE_T_MAX __ULONG_MAX /* max value for a size_t */
|
||||
#define __OFF_MAX __LONG_MAX /* max value for an off_t */
|
||||
#define __OFF_MIN __LONG_MIN /* min value for an off_t */
|
||||
/* Quads and longs are the same on the amd64. Ensure they stay in sync. */
|
||||
#define __UQUAD_MAX __ULONG_MAX /* max value for a uquad_t */
|
||||
#define __QUAD_MAX __LONG_MAX /* max value for a quad_t */
|
||||
#define __QUAD_MIN __LONG_MIN /* min value for a quad_t */
|
||||
#define __LONG_BIT 64
|
||||
#else
|
||||
#define __SSIZE_MAX __INT_MAX
|
||||
#define __SIZE_T_MAX __UINT_MAX
|
||||
#define __OFF_MAX __LLONG_MAX
|
||||
#define __OFF_MIN __LLONG_MIN
|
||||
#define __UQUAD_MAX __ULLONG_MAX
|
||||
#define __QUAD_MAX __LLONG_MAX
|
||||
#define __QUAD_MIN __LLONG_MIN
|
||||
#define __LONG_BIT 32
|
||||
#endif
|
||||
|
||||
#define __WORD_BIT 32
|
||||
|
||||
/* Minimum signal stack size. */
|
||||
#define __MINSIGSTKSZ (512 * 4)
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ===========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -1,102 +0,0 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
/**
|
||||
* @brief Copy `n` bytes from `src` to `dest`.
|
||||
*
|
||||
* @param dest The destination
|
||||
* @param src The source
|
||||
* @param n The amount of bytes to copy
|
||||
* @returns A pointer to `dest`
|
||||
*/
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* @brief Starting from `ptr`, fill `n` bytes with the constant byte `c`.
|
||||
*
|
||||
* @param ptr The start of the memory region
|
||||
* @param c The byte to fill with
|
||||
* @param n The amount of bytes to write
|
||||
* @returns A pointer to `ptr`
|
||||
*/
|
||||
void *memset(void *ptr, int c, size_t n);
|
||||
|
||||
/**
|
||||
* @brief Copy a memory area.
|
||||
* The two areas may overlap since the individual bytes are copied to a
|
||||
* temporary array first.
|
||||
*
|
||||
* @param dest The destination address
|
||||
* @param src The source address
|
||||
* @param n The amount of bytes to copy
|
||||
* @return a pointer to dest
|
||||
*/
|
||||
void *memmove(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* @brief Compare the two strings `s1` and `s2`.
|
||||
*
|
||||
* @param s1 The first string
|
||||
* @param s2 The second string
|
||||
* @returns `0` if both strings are equal, a positive value f `s1` is greater
|
||||
* than `s2`, and a negative value if `s1` is less than `s2`
|
||||
*/
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* @brief Copy a `NUL` terminated string from `src` to `dest`.
|
||||
*
|
||||
* @param dest The destination to copy to. The memory region must be able to
|
||||
* hold the entire string plus one byte for the terminator.
|
||||
* @param src The original string to copy from
|
||||
* @returns A pointer to the destination string
|
||||
*/
|
||||
char *strcpy(char *dest, const char *src);
|
||||
|
||||
/**
|
||||
* @brief Copy a `NUL` terminated string from `src` to `dest`, but at most `n` characters.
|
||||
* Note that this may cause `dest` to miss a `NUL` terminator.
|
||||
*
|
||||
* @param dest The destination to copy to. The memory region must be able to
|
||||
* hold the entire string plus one byte for the terminator.
|
||||
* @param src The original string to copy from
|
||||
* @param n The amount of characters to copy at most
|
||||
* @returns A pointer to the destination string
|
||||
*/
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
|
||||
/**
|
||||
* @brief Compute the length of the `NUL` terminated string `s`.
|
||||
*
|
||||
* @param s The string
|
||||
* @returns The length of `s` without the `NUL` terminator
|
||||
*/
|
||||
size_t strlen(const char *s);
|
||||
|
||||
#if _POSIX_C_SOURCE >= 200809L || _GAY_SOURCE >= 202109L
|
||||
/**
|
||||
* @brief Compute the length of the `NUL` terminated string `s`, but at most `maxlen` bytes.
|
||||
*
|
||||
* @param s The string
|
||||
* @param maxlen Maximum bytes after which to return
|
||||
* @returns The length of `s` without the `NUL` terminator, but at most `maxlen`
|
||||
*/
|
||||
size_t strnlen(const char *s, size_t maxlen);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,19 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#define alloca(size) __builtin_alloca(size)
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,209 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)errno.h 8.5 (Berkeley) 1/21/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ERRNO_H_
|
||||
#define _SYS_ERRNO_H_
|
||||
|
||||
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
||||
#include <sys/cdefs.h>
|
||||
__BEGIN_DECLS
|
||||
int * __error(void);
|
||||
__END_DECLS
|
||||
#define errno (* __error())
|
||||
#endif
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* Input/output error */
|
||||
#define ENXIO 6 /* Device not configured */
|
||||
#define E2BIG 7 /* Argument list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file descriptor */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EDEADLK 11 /* Resource deadlock avoided */
|
||||
/* 11 was EAGAIN */
|
||||
#define ENOMEM 12 /* Cannot allocate memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#endif
|
||||
#define EBUSY 16 /* Device busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* Operation not supported by device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* Too many open files in system */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Inappropriate ioctl for device */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#endif
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only filesystem */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
|
||||
/* math software */
|
||||
#define EDOM 33 /* Numerical argument out of domain */
|
||||
#define ERANGE 34 /* Result too large */
|
||||
|
||||
/* non-blocking and interrupt i/o */
|
||||
#define EAGAIN 35 /* Resource temporarily unavailable */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
#define EINPROGRESS 36 /* Operation now in progress */
|
||||
#define EALREADY 37 /* Operation already in progress */
|
||||
|
||||
/* ipc/network software -- argument errors */
|
||||
#define ENOTSOCK 38 /* Socket operation on non-socket */
|
||||
#define EDESTADDRREQ 39 /* Destination address required */
|
||||
#define EMSGSIZE 40 /* Message too long */
|
||||
#define EPROTOTYPE 41 /* Protocol wrong type for socket */
|
||||
#define ENOPROTOOPT 42 /* Protocol not available */
|
||||
#define EPROTONOSUPPORT 43 /* Protocol not supported */
|
||||
#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
|
||||
#define EOPNOTSUPP 45 /* Operation not supported */
|
||||
#define ENOTSUP EOPNOTSUPP /* Operation not supported */
|
||||
#define EPFNOSUPPORT 46 /* Protocol family not supported */
|
||||
#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
|
||||
#define EADDRINUSE 48 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 49 /* Can't assign requested address */
|
||||
|
||||
/* ipc/network software -- operational errors */
|
||||
#define ENETDOWN 50 /* Network is down */
|
||||
#define ENETUNREACH 51 /* Network is unreachable */
|
||||
#define ENETRESET 52 /* Network dropped connection on reset */
|
||||
#define ECONNABORTED 53 /* Software caused connection abort */
|
||||
#define ECONNRESET 54 /* Connection reset by peer */
|
||||
#define ENOBUFS 55 /* No buffer space available */
|
||||
#define EISCONN 56 /* Socket is already connected */
|
||||
#define ENOTCONN 57 /* Socket is not connected */
|
||||
#define ESHUTDOWN 58 /* Can't send after socket shutdown */
|
||||
#define ETOOMANYREFS 59 /* Too many references: can't splice */
|
||||
#define ETIMEDOUT 60 /* Operation timed out */
|
||||
#define ECONNREFUSED 61 /* Connection refused */
|
||||
|
||||
#define ELOOP 62 /* Too many levels of symbolic links */
|
||||
#endif /* _POSIX_SOURCE */
|
||||
#define ENAMETOOLONG 63 /* File name too long */
|
||||
|
||||
/* should be rearranged */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define EHOSTDOWN 64 /* Host is down */
|
||||
#define EHOSTUNREACH 65 /* No route to host */
|
||||
#endif /* _POSIX_SOURCE */
|
||||
#define ENOTEMPTY 66 /* Directory not empty */
|
||||
|
||||
/* quotas & mush */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define EPROCLIM 67 /* Too many processes */
|
||||
#define EUSERS 68 /* Too many users */
|
||||
#define EDQUOT 69 /* Disc quota exceeded */
|
||||
|
||||
/* Network File System */
|
||||
#define ESTALE 70 /* Stale NFS file handle */
|
||||
#define EREMOTE 71 /* Too many levels of remote in path */
|
||||
#define EBADRPC 72 /* RPC struct is bad */
|
||||
#define ERPCMISMATCH 73 /* RPC version wrong */
|
||||
#define EPROGUNAVAIL 74 /* RPC prog. not avail */
|
||||
#define EPROGMISMATCH 75 /* Program version wrong */
|
||||
#define EPROCUNAVAIL 76 /* Bad procedure for program */
|
||||
#endif /* _POSIX_SOURCE */
|
||||
|
||||
#define ENOLCK 77 /* No locks available */
|
||||
#define ENOSYS 78 /* Function not implemented */
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define EFTYPE 79 /* Inappropriate file type or format */
|
||||
#define EAUTH 80 /* Authentication error */
|
||||
#define ENEEDAUTH 81 /* Need authenticator */
|
||||
#define EIDRM 82 /* Identifier removed */
|
||||
#define ENOMSG 83 /* No message of desired type */
|
||||
#define EOVERFLOW 84 /* Value too large to be stored in data type */
|
||||
#define ECANCELED 85 /* Operation canceled */
|
||||
#define EILSEQ 86 /* Illegal byte sequence */
|
||||
#define ENOATTR 87 /* Attribute not found */
|
||||
|
||||
#define EDOOFUS 88 /* Programming error */
|
||||
#endif /* _POSIX_SOURCE */
|
||||
|
||||
#define EBADMSG 89 /* Bad message */
|
||||
#define EMULTIHOP 90 /* Multihop attempted */
|
||||
#define ENOLINK 91 /* Link has been severed */
|
||||
#define EPROTO 92 /* Protocol error */
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define ENOTCAPABLE 93 /* Capabilities insufficient */
|
||||
#define ECAPMODE 94 /* Not permitted in capability mode */
|
||||
#define ENOTRECOVERABLE 95 /* State not recoverable */
|
||||
#define EOWNERDEAD 96 /* Previous owner died */
|
||||
#define EINTEGRITY 97 /* Integrity check failed */
|
||||
#endif /* _POSIX_SOURCE */
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define ELAST 97 /* Must be equal largest errno */
|
||||
#endif /* _POSIX_SOURCE */
|
||||
|
||||
#if defined(_KERNEL) || defined(_WANT_KERNEL_ERRNO) || defined(_STANDALONE)
|
||||
/* pseudo-errors returned inside kernel to modify return to process */
|
||||
#define ERESTART (-1) /* restart syscall */
|
||||
#define EJUSTRETURN (-2) /* don't modify regs, just return */
|
||||
#define ENOIOCTL (-3) /* ioctl not handled by this layer */
|
||||
#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */
|
||||
#define ERELOOKUP (-5) /* retry the directory lookup */
|
||||
#endif
|
||||
|
||||
#ifndef _KERNEL
|
||||
#if __EXT1_VISIBLE
|
||||
/* ISO/IEC 9899:2011 K.3.2.2 */
|
||||
#ifndef _ERRNO_T_DEFINED
|
||||
#define _ERRNO_T_DEFINED
|
||||
typedef int errno_t;
|
||||
#endif
|
||||
#endif /* __EXT1_VISIBLE */
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,112 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arch/limits.h>
|
||||
|
||||
#define CHAR_BIT __CHAR_BIT /* number of bits in a char */
|
||||
|
||||
#define SCHAR_MAX __SCHAR_MAX /* max value for a signed char */
|
||||
#define SCHAR_MIN __SCHAR_MIN /* min value for a signed char */
|
||||
|
||||
#define UCHAR_MAX __UCHAR_MAX /* max value for an unsigned char */
|
||||
|
||||
#ifdef __CHAR_UNSIGNED__
|
||||
#define CHAR_MAX UCHAR_MAX /* max value for a char */
|
||||
#define CHAR_MIN 0 /* min value for a char */
|
||||
#else
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#endif
|
||||
|
||||
#define USHRT_MAX __USHRT_MAX /* max value for an unsigned short */
|
||||
#define SHRT_MAX __SHRT_MAX /* max value for a short */
|
||||
#define SHRT_MIN __SHRT_MIN /* min value for a short */
|
||||
|
||||
#define UINT_MAX __UINT_MAX /* max value for an unsigned int */
|
||||
#define INT_MAX __INT_MAX /* max value for an int */
|
||||
#define INT_MIN __INT_MIN /* min value for an int */
|
||||
|
||||
#define ULONG_MAX __ULONG_MAX /* max for an unsigned long */
|
||||
#define LONG_MAX __LONG_MAX /* max for a long */
|
||||
#define LONG_MIN __LONG_MIN /* min for a long */
|
||||
|
||||
#ifdef __LONG_LONG_SUPPORTED
|
||||
#define ULLONG_MAX __ULLONG_MAX /* max for an unsigned long long */
|
||||
#define LLONG_MAX __LLONG_MAX /* max for a long long */
|
||||
#define LLONG_MIN __LLONG_MIN /* min for a long long */
|
||||
#endif
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || _POSIX_C_SOURCE
|
||||
#define SSIZE_MAX __SSIZE_MAX /* max value for an ssize_t */
|
||||
#endif
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || _POSIX_C_SOURCE >= 200112
|
||||
#define SIZE_T_MAX __SIZE_T_MAX /* max value for a size_t */
|
||||
|
||||
#define OFF_MAX __OFF_MAX /* max value for an off_t */
|
||||
#define OFF_MIN __OFF_MIN /* min value for an off_t */
|
||||
#endif
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
#define GID_MAX UINT_MAX /* max value for a gid_t */
|
||||
#define UID_MAX UINT_MAX /* max value for a uid_t */
|
||||
|
||||
#define UQUAD_MAX (__UQUAD_MAX) /* max value for a uquad_t */
|
||||
#define QUAD_MAX (__QUAD_MAX) /* max value for a quad_t */
|
||||
#define QUAD_MIN (__QUAD_MIN) /* min value for a quad_t */
|
||||
#endif
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || _POSIX_C_SOURCE >= 200809 || __BSD_VISIBLE
|
||||
#define LONG_BIT __LONG_BIT
|
||||
#define WORD_BIT __WORD_BIT
|
||||
#endif
|
||||
|
||||
#if _POSIX_C_SOURCE
|
||||
#define MQ_PRIO_MAX 64
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*/
|
@ -0,0 +1,27 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef __builtin_va_list va_list;
|
||||
|
||||
#define va_start(ap, arg) __builtin_va_start(ap, arg)
|
||||
#define va_end(ap) __builtin_va_end(ap)
|
||||
#define va_arg(ap, type) __builtin_va_arg(ap, type)
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __STDC_VERSION__ >= 199900L
|
||||
#define va_copy(dest, src) __builtin_va_copy(dest, src)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,355 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
#include <gay/types.h>
|
||||
|
||||
/**
|
||||
* @brief Copy up to `n` bytes from `src` to `dest`, but stop when the byte `c` is found.
|
||||
* The regions `src` and `dest` must not overlap.
|
||||
*
|
||||
* @param dest Destination address
|
||||
* @param src Source address
|
||||
* @param c Stop character
|
||||
* @param n Maximum number of bytes
|
||||
* @return A pointer to the next character after `c`, or `NULL` if `c` was not
|
||||
* encountered within the first `n` bytes
|
||||
*/
|
||||
void *memccpy(void *__restrict dest, const void *__restrict src, int c, usize n);
|
||||
|
||||
/**
|
||||
* @brief Return the first occurrence of byte `c` within the first `n` bytes of `src`.
|
||||
*
|
||||
* @param src Start of buffer to search through
|
||||
* @param c Character to search for
|
||||
* @param n Maximum amount of bytes to search, starting from `src`
|
||||
* @return The address of the found byte, or `NULL` if it was not found
|
||||
* @note Because the run time of this function is not constant with respect
|
||||
* to `n`, it should not be used in cryptographic operations.
|
||||
*/
|
||||
__pure void *memchr(const void *src, int c, usize n);
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
/**
|
||||
* @brief Return the last occurrence of byte `c` within the first `n` bytes of `src`.
|
||||
* This function does the same thing as `memchr()` but in reverse direction.
|
||||
*
|
||||
* @param src Start of buffer to search through
|
||||
* @param c Character to search for
|
||||
* @param n Maximum amount of bytes to search, starting from `src`
|
||||
* @return The address of the found byte, or `NULL` if it was not found
|
||||
* @note Because the run time of this function is not constant with respect
|
||||
* to `n`, it should not be used in cryptographic operations.
|
||||
*/
|
||||
__pure void *memrchr(const void *src, int c, usize n);
|
||||
#endif /* _GAY_SOURCE >= 202109L || __BSD_VISIBLE */
|
||||
|
||||
/**
|
||||
* @brief Copy `n` bytes from `src` to `dest`.
|
||||
* The regions `src` and `dest` must not overlap.
|
||||
*
|
||||
* @param dest The destination
|
||||
* @param src The source
|
||||
* @param n The amount of bytes to copy
|
||||
* @returns A pointer to `dest`
|
||||
*/
|
||||
void *memcpy(void *__restrict dest, const void *__restrict src, usize n);
|
||||
|
||||
/**
|
||||
* @brief Compare two memory regions of size `n` for equality.
|
||||
*
|
||||
* @param s1 The first memory region
|
||||
* @param s2 The second memory region
|
||||
* @param n Amount of bytes to compare
|
||||
* @return 0 if the first `n` bytes in `s1` and `s2` are found to be equal,
|
||||
* or the difference between the first non equal bytes (interpreted as an
|
||||
* `unsigned char`) such that the value is positive if the byte in `s1`
|
||||
* is greater than the one in `s2`
|
||||
* @note Because the run time of this function is not constant with respect
|
||||
* to `n`, it should not be used in cryptographic operations.
|
||||
*/
|
||||
__pure int memcmp(const void *s1, const void *s2, usize n);
|
||||
|
||||
/**
|
||||
* @brief Starting from `ptr`, fill `n` bytes with the constant byte `c`.
|
||||
*
|
||||
* @param ptr The start of the memory region
|
||||
* @param c The byte to fill with
|
||||
* @param n The amount of bytes to write
|
||||
* @returns A pointer to `ptr`
|
||||
*/
|
||||
void *memset(void *ptr, int c, usize n);
|
||||
|
||||
/**
|
||||
* @brief Copy a memory area.
|
||||
* The two areas may overlap since the individual bytes are copied to a
|
||||
* temporary array first.
|
||||
*
|
||||
* @param dest The destination address
|
||||
* @param src The source address
|
||||
* @param n The amount of bytes to copy
|
||||
* @return a pointer to dest
|
||||
*/
|
||||
void *memmove(void *dest, const void *src, usize n);
|
||||
|
||||
/**
|
||||
* @brief Compare the two strings `s1` and `s2`.
|
||||
*
|
||||
* @param s1 The first string
|
||||
* @param s2 The second string
|
||||
* @returns `0` if both strings are equal, a positive value f `s1` is greater
|
||||
* than `s2`, and a negative value if `s1` is less than `s2`
|
||||
*/
|
||||
__pure int strcmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* @brief Copy a `NUL` terminated string from `src` to `dest`.
|
||||
* The `dest` and `src` regions must not overlap.
|
||||
*
|
||||
* @param dest The destination to copy to. The memory region must be able to
|
||||
* hold the entire string plus one byte for the terminator.
|
||||
* @param src The original string to copy from
|
||||
* @returns A pointer to the destination string
|
||||
*/
|
||||
char *strcpy(char *dest, const char *src);
|
||||
|
||||
/**
|
||||
* @brief Copy a `NUL` terminated string from `src` to `dest`, but at most `n` characters.
|
||||
* Note that this may cause `dest` to miss a `NUL` terminator.
|
||||
* The `dest` and `src` regions must not overlap.
|
||||
*
|
||||
* @param dest The destination to copy to. The memory region must be able to
|
||||
* hold the entire string plus one byte for the terminator.
|
||||
* @param src The original string to copy from
|
||||
* @param n The amount of characters to copy at most
|
||||
* @returns A pointer to the destination string
|
||||
*/
|
||||
char *strncpy(char *dest, const char *src, usize n);
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || _POSIX_C_SOURCE >= 200809L
|
||||
/** @brief The same as `strcpy()`, but the returned pointer is the NUL terminator of `dest`. */
|
||||
char *stpcpy(char *__restrict dest, const char *__restrict src);
|
||||
|
||||
/** @brief The same as `strncpy()`, but the returned pointer is the NUL terminator of `dest`. */
|
||||
char *stpncpy(char *__restrict dest, const char *__restrict src, usize n);
|
||||
#endif /* _GAY_SOURCE >= 202109L || _POSIX_C_SOURCE >= 200809L */
|
||||
|
||||
/**
|
||||
* @brief Append a NUL terminated string to another string.
|
||||
* `s` must be sufficiently large to hold both strings.
|
||||
*
|
||||
* @param s String to append the other string to
|
||||
* @param append String to append to `s`
|
||||
* @return A pointer to `s`
|
||||
*/
|
||||
char *strcat(char *__restrict s, const char *__restrict append);
|
||||
|
||||
/**
|
||||
* @brief Append a NUL terminated string to another string, but at most `count` bytes.
|
||||
*
|
||||
* @param s String to be appended to
|
||||
* @param append String to append to `s`
|
||||
* @param count Maximum amount of bytes to append, excluding the NUL terminator
|
||||
* which is always appended at the end
|
||||
* @return A pointer to `s`
|
||||
*/
|
||||
char *strncat(char *__restrict s, const char *__restrict append, usize count);
|
||||
|
||||
/**
|
||||
* @brief Compare two strings for equality.
|
||||
*
|
||||
* @param s1 First string to compare
|
||||
* @param s2 Second string to compare
|
||||
* @param n Maximum amount of bytes (characters) to check. If a NUL terminator
|
||||
* is encountered before this limit is reached, the comparison ends early.
|
||||
* @return 0 if the strings are equal up to byte `n`, or the difference between
|
||||
* the first non equal characters cast to an `unsigned char` (such that the
|
||||
* return value becomes positive if the character in `s1` has a greater
|
||||
* numerical value as the one in `s2`)
|
||||
*/
|
||||
int strncmp(const char *s1, const char *s2, usize n);
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
/**
|
||||
* @brief Append a NUL terminated string to another string, such that the
|
||||
* resulting string is at most `dstsize` bytes long (including the NUL terminator) .
|
||||
*
|
||||
* @param s String to be appended to
|
||||
* @param append String to append to `s`
|
||||
* @param n Maximum total length of `s` in bytes
|
||||
* @return A pointer to `s`
|
||||
*/
|
||||
usize strlcat(char *__restrict s, const char *__restrict append, usize dstsize);
|
||||
|
||||
/**
|
||||
* @brief Copy the NUL terminated string `src` into dest, but at most `dstsize`
|
||||
* bytes (including the NUL terminator, which is always appended).
|
||||
*
|
||||
* @param dest Destination address
|
||||
* @param src Source string to copy from
|
||||
* @param dstsize Maximum bytes (including NUL) to write to `dest`
|
||||
* @return The amount of characters copied, including the NUL terminator
|
||||
*/
|
||||
usize strlcpy(char *__restrict dest, const char *__restrict src, usize dstsize);
|
||||
#endif /* _GAY_SOURCE >= 202109L || __BSD_VISIBLE */
|
||||
|
||||
/**
|
||||
* @brief Compute the length of the `NUL` terminated string `s`.
|
||||
*
|
||||
* @param s The string
|
||||
* @returns The length of `s` without the `NUL` terminator
|
||||
*/
|
||||
__pure usize strlen(const char *s);
|
||||
|
||||
#if _POSIX_C_SOURCE >= 200809L || _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
/**
|
||||
* @brief Compute the length of the `NUL` terminated string `s`, but at most `maxlen` bytes.
|
||||
*
|
||||
* @param s The string
|
||||
* @param maxlen Maximum bytes after which to return
|
||||
* @returns The length of `s` without the `NUL` terminator, but at most `maxlen`
|
||||
*/
|
||||
__pure size_t strnlen(const char *s, usize maxlen);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Search a string for any in a set of characters (excluding NUL).
|
||||
*
|
||||
* @param s String to search through
|
||||
* @param find A set of characters to search for in `s`
|
||||
* @return The first occurrence of one of the characters of `find` in `s`,
|
||||
* or `NULL` if none were found
|
||||
*/
|
||||
__pure char *strpbrk(const char *s, const char *find);
|
||||
|
||||
/**
|
||||
* @brief Span a string.
|
||||
*
|
||||
* @param s String to span
|
||||
* @param charset Set of characters that should appear in `s`
|
||||
* @return A pointer to the first character in `s` that *is not* within `charset`.
|
||||
* @see `strcspn()`
|
||||
*/
|
||||
__pure usize strspn(const char *s, const char *charset);
|
||||
|
||||
/**
|
||||
* @brief Span a string.
|
||||
*
|
||||
* @param s String to span
|
||||
* @param charset Set of characters that may *not* appear in `s`
|
||||
* @return A pointer to the first character in `s` that *is* within `charset`.
|
||||
* @see `strspn()`
|
||||
*/
|
||||
__pure usize strcspn(const char *s, const char *charset);
|
||||
|
||||
/**
|
||||
* @brief Find the first occurrence of `find` within `s`.
|
||||
*
|
||||
* @param s Haystack to search through
|
||||
* @param find Needle to find
|
||||
* @return A pointer to the beginning of the first occurrence of `find` in `s`,
|
||||
* or `NULL` if it was not found
|
||||
*/
|
||||
__pure char *strstr(const char *s, const char *find);
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
/**
|
||||
* @brief Find the first occurrence of `find` within the first `slen` characters of `s`.
|
||||
* If A NUL terminator is encountered in `s`, the search is aborted early.
|
||||
*
|
||||
* @param s Haystack to search through
|
||||
* @param find Needle to find
|
||||
* @param slen Maximum characters to search in `s`
|
||||
* @return A pointer to the beginning of the first occurrence of `find` in `s`,
|
||||
* or `NULL` if it was not found
|
||||
*/
|
||||
__pure char *strnstr(const char *s, const char *find, usize slen);
|
||||
#endif /* _GAY_SOURCE >= 202109L || __BSD_VISIBLE */
|
||||
|
||||
/**
|
||||
* @brief Duplicate a string.
|
||||
*
|
||||
* @param s String to duplicate
|
||||
* @return A newly allocated copy of the string, or `NULL` if OOM
|
||||
*/
|
||||
__attribute__(( malloc ))
|
||||
char *strdup(const char *s);
|
||||
|
||||
#if _POSIX_C_SOURCE >= 200809L
|
||||
/**
|
||||
* @brief Duplicate a string, but copy at most `maxlen` bytes (including NUL).
|
||||
* New memory will be allocated.
|
||||
*
|
||||
* @param s String to duplicate
|
||||
* @param maxlen Maximum length of the copied string in bytes
|
||||
*/
|
||||
__attribute__(( malloc ))
|
||||
char *strndup(const char *s, usize maxlen);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Locate a character in a string.
|
||||
*
|
||||
* @param s String to search through
|
||||
* @param c Character to search for
|
||||
* @return The position of the *first* occurrence of `c` within `s`,
|
||||
* or `NULL` if the character was not found
|
||||
*/
|
||||
__pure char *strchr(const char *s, int c);
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
/**
|
||||
* @brief Locate a character in a string in reverse order.
|
||||
*
|
||||
* @param s String to search through
|
||||
* @param c Character to search for
|
||||
* @return The position of the *last* occurrence of `c` within `s`,
|
||||
* or `NULL` if the character was not found
|
||||
*/
|
||||
__pure char *strrchr(const char *s, int c);
|
||||
|
||||
/**
|
||||
* @brief Locate a character in a string.
|
||||
*
|
||||
* @param s String to search through
|
||||
* @param c Character to search for
|
||||
* @return The position of the first occurrence of `c` within `s`,
|
||||
* or the NUL terminator of `s` if the character was not not found
|
||||
*/
|
||||
__pure char *strchrnul(const char *s, int c);
|
||||
|
||||
/**
|
||||
* @brief Separate a string into individual tokens.
|
||||
* This is a slightly more sane replacement for `strtok()`.
|
||||
*
|
||||
* @param stringp Pointer to a `char *`, which will be advanced to one character
|
||||
* after the first occurrence of one of the characters in `delim` (or NUL).
|
||||
* The found delimiter is replaced with a NUL byte.
|
||||
* @param delim A set of delimiter tokens
|
||||
* @return The original value of `*stringp`, or `NULL` if it was `NULL`.
|
||||
* If this points to a NUL terminator, the end of the string was reached.
|
||||
*/
|
||||
char *strsep(char **stringp, const char *delim);
|
||||
#endif /* _GAY_SOURCE >= 202109L || __BSD_VISIBLE */
|
||||
|
||||
#ifndef __KERNEL__ /* we *really* don't want this anywhere in kernel code */
|
||||
char *strtok(char *__restrict s, const char *__restrict tok);
|
||||
# if _POSIX_C_SOURCE >= 199506L
|
||||
char *strtok_r(char *s, const char *delim, char **last);
|
||||
# endif /* _POSIX_C_SOURCE >= 199506L */
|
||||
#endif /* not __KERNEL__ */
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,80 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
#include <gay/types.h>
|
||||
|
||||
#if __BSD_VISIBLE || _POSIX_C_SOURCE <= 200112L
|
||||
__pure int bcmp(const void *, const void *, usize); /* LEGACY */
|
||||
void bcopy(const void *, void *, usize); /* LEGACY */
|
||||
void bzero(void *, usize); /* LEGACY */
|
||||
__pure char *index(const char *, int); /* LEGACY */
|
||||
__pure char *rindex(const char *, int); /* LEGACY */
|
||||
#endif /* __BSD_VISIBLE || _POSIX_C_SOURCE <= 200112L */
|
||||
|
||||
#if _GAY_SOURCE >= 202109L || __BSD_VISIBLE
|
||||
|
||||
/**
|
||||
* @brief Find the first set bit in a bitmask.
|
||||
*
|
||||
* @param mask The bitmask
|
||||
* @return The 0-based index of the first 1 bit, or 0 if `mask` was zero.
|
||||
*/
|
||||
__pure2 int ffs(int mask);
|
||||
|
||||
/**
|
||||
* @brief Find the first set bit in a bitmask.
|
||||
*
|
||||
* @param mask The bitmask
|
||||
* @return The 0-based index of the first 1 bit, or 0 if `mask` was zero.
|
||||
*/
|
||||
__pure2 int ffsl(long mask);
|
||||
|
||||
/**
|
||||
* @brief Find the first set bit in a bitmask.
|
||||
*
|
||||
* @param mask The bitmask
|
||||
* @return The 0-based index of the first 1 bit, or 0 if `mask` was zero.
|
||||
*/
|
||||
__pure2 int ffsll(long long mask);
|
||||
|
||||
/**
|
||||
* @brief Find the last set bit in a bitmask.
|
||||
*
|
||||
* @param mask The bitmask
|
||||
* @return The 0-based index of the last 1 bit, or 0 if `mask` was zero.
|
||||
*/
|
||||
__pure2 int fls(int mask);
|
||||
|
||||
/**
|
||||
* @brief Find the last set bit in a bitmask.
|
||||
*
|
||||
* @param mask The bitmask
|
||||
* @return The 0-based index of the last 1 bit, or 0 if `mask` was zero.
|
||||
*/
|
||||
__pure2 int flsl(long mask);
|
||||
|
||||
/**
|
||||
* @brief Find the last set bit in a bitmask.
|
||||
*
|
||||
* @param mask The bitmask
|
||||
* @return The 0-based index of the last 1 bit, or 0 if `mask` was zero.
|
||||
*/
|
||||
__pure2 int flsll(long long mask);
|
||||
|
||||
#endif /* _GAY_SOURCE >= 202109L || __BSD_VISIBLE */
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,21 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
void swab(const void *__restrict from, void *__restrict to, isize len);
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,77 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
/*
|
||||
* i'm *really* tired right now and i don't see a real reason to write fucking
|
||||
* documentation for these because they are completely POSIX conforming anyway,
|
||||
* so i'll just defer that to later(TM).
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arch/limits.h>
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
wchar_t *wcpcpy(wchar_t *__restrict to, const wchar_t *__restrict from);
|
||||
|
||||
wchar_t *wcpncpy(wchar_t *__restrict dst, const wchar_t *__restrict src, usize n);
|
||||
|
||||
wchar_t *wcscat(wchar_t *__restrict s1, const wchar_t *__restrict s2);
|
||||
|
||||
wchar_t *wcschr(const wchar_t *s, wchar_t c);
|
||||
|
||||
int wcscmp(const wchar_t *s1, const wchar_t *s2);
|
||||
|
||||
wchar_t *wcscpy(wchar_t *__restrict s1, const wchar_t *__restrict s2);
|
||||
|
||||
usize wcscspn(const wchar_t *s, const wchar_t *set);
|
||||
|
||||
wchar_t *wcsdup(const wchar_t *s);
|
||||
|
||||
usize wcslcat(wchar_t *dst, const wchar_t *src, usize siz);
|
||||
|
||||
usize wcslcpy(wchar_t *dst, const wchar_t *src, usize siz);
|
||||
|
||||
usize wcslen(const wchar_t *s);
|
||||
|
||||
wchar_t *wcsncat(wchar_t *__restrict s1, const wchar_t *__restrict s2, usize n);
|
||||
|
||||
int wcsncmp(const wchar_t *s1, const wchar_t *s2, usize n);
|
||||
|
||||
wchar_t *wcsncpy(wchar_t *__restrict dst, const wchar_t *__restrict src, usize n);
|
||||
|
||||
usize wcsnlen(const wchar_t *s, usize maxlen);
|
||||
|
||||
wchar_t *wcspbrk(const wchar_t *s, const wchar_t *set);
|
||||
|
||||
wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
|
||||
|
||||
usize wcsspn(const wchar_t *s, const wchar_t *set);
|
||||
|
||||
wchar_t *wcsstr(const wchar_t *__restrict s, const wchar_t *__restrict find);
|
||||
|
||||
wchar_t *wcstok(wchar_t *__restrict s, const wchar_t *__restrict delim, wchar_t **__restrict last);
|
||||
|
||||
wchar_t *wmemchr(const wchar_t *s, wchar_t c, usize n);
|
||||
|
||||
int wmemcmp(const wchar_t *s1, const wchar_t *s2, usize n);
|
||||
|
||||
wchar_t *wmemcpy(wchar_t *__restrict d, const wchar_t *__restrict s, usize n);
|
||||
|
||||
wchar_t *wmemmove(wchar_t *d, const wchar_t *s, usize n);
|
||||
|
||||
wchar_t *wmemset(wchar_t *s, wchar_t c, usize n);
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -1,127 +0,0 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
int delta = 0;
|
||||
|
||||
while (n-- > 0) {
|
||||
/* POSIX explicitly wants a cast to unsigned char */
|
||||
delta = *(const unsigned char *)s1++ - *(const unsigned char *)s2++;
|
||||
if (delta != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
u8 *tmp = (u8 *)dest;
|
||||
|
||||
while (n-- > 0)
|
||||
*tmp++ = *(const u8 *)src++;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memset(void *ptr, int c, size_t n)
|
||||
{
|
||||
char *tmp = (char *)ptr;
|
||||
|
||||
while (n-- > 0)
|
||||
*tmp++ = (char)c;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *tmp = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if (dest == src)
|
||||
return dest;
|
||||
|
||||
if (dest < src) {
|
||||
while (n-- != 0)
|
||||
*tmp++ = *s++;
|
||||
} else {
|
||||
tmp += n;
|
||||
s += n;
|
||||
while (n-- != 0)
|
||||
*--tmp = *--s;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == '\0' || *s2++ == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
/* POSIX explicitly wants a cast to unsigned char */
|
||||
return *((const unsigned char *)s1) - *((const unsigned char *)s2);
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *tmp = dest;
|
||||
|
||||
while ((*tmp++ = *src++) != '\0');
|
||||
/* nothing */
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
char *tmp = dest;
|
||||
|
||||
while (n-- != 0) {
|
||||
if ((*tmp++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *tmp = s;
|
||||
|
||||
while (*tmp++ != '\0');
|
||||
/* nothing */
|
||||
|
||||
return (size_t)tmp - (size_t)s - 1;
|
||||
}
|
||||
|
||||
size_t strnlen(const char *s, size_t maxlen)
|
||||
{
|
||||
const char *tmp = s;
|
||||
|
||||
while (*tmp++ != '\0' && maxlen-- > 0);
|
||||
/* nothing */
|
||||
|
||||
return (size_t)tmp - (size_t)s - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,83 @@
|
||||
# See the end of this file for copyright and license terms.
|
||||
|
||||
target_sources(c PRIVATE
|
||||
bcmp.c
|
||||
bcopy.c
|
||||
bzero.c
|
||||
ffs.c
|
||||
ffsl.c
|
||||
ffsll.c
|
||||
fls.c
|
||||
flsl.c
|
||||
flsll.c
|
||||
memccpy.c
|
||||
memchr.c
|
||||
memcmp.c
|
||||
memcpy.c
|
||||
memmem.c
|
||||
memmove.c
|
||||
memrchr.c
|
||||
memset.c
|
||||
stpcpy.c
|
||||
stpncpy.c
|
||||
strcat.c
|
||||
strchr.c
|
||||
strchrnul.c
|
||||
strcmp.c
|
||||
strcpy.c
|
||||
strcspn.c
|
||||
strdup.c
|
||||
strlcat.c
|
||||
strlcpy.c
|
||||
strlen.c
|
||||
strncat.c
|
||||
strncmp.c
|
||||
strncpy.c
|
||||
strndup.c
|
||||
strnlen.c
|
||||
strnstr.c
|
||||
strpbrk.c
|
||||
strrchr.c
|
||||
strsep.c
|
||||
strspn.c
|
||||
strstr.c
|
||||
strtok.c
|
||||
swab.c
|
||||
wcpcpy.c
|
||||
wcpncpy.c
|
||||
wcscat.c
|
||||
wcschr.c
|
||||
wcscmp.c
|
||||
wcscpy.c
|
||||
wcscspn.c
|
||||
wcsdup.c
|
||||
wcslcat.c
|
||||
wcslcpy.c
|
||||
wcslen.c
|
||||
wcsncat.c
|
||||
wcsncmp.c
|
||||
wcsncpy.c
|
||||
wcsnlen.c
|
||||
wcspbrk.c
|
||||
wcsrchr.c
|
||||
wcsspn.c
|
||||
wcsstr.c
|
||||
wcstok.c
|
||||
wmemchr.c
|
||||
wmemcmp.c
|
||||
wmemcpy.c
|
||||
wmemmove.c
|
||||
wmemset.c
|
||||
)
|
||||
|
||||
# This file is part of GayBSD.
|
||||
# Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
#
|
||||
# GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
# modify it under the terms of the Cooperative Nonviolent Public License
|
||||
# (CNPL) as found in the LICENSE file in the source code root directory
|
||||
# or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
# of the license, or (at your option) any later version.
|
||||
#
|
||||
# GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
# permitted by applicable law. See the CNPL for details.
|
@ -0,0 +1,70 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* bcmp -- vax cmpc3 instruction
|
||||
*/
|
||||
int bcmp(const void *b1, const void *b2, usize length)
|
||||
{
|
||||
if (length == 0)
|
||||
return 0;
|
||||
|
||||
char *p1 = (char *)b1;
|
||||
char *p2 = (char *)b2;
|
||||
do {
|
||||
if (*p1++ != *p2++)
|
||||
break;
|
||||
} while (--length);
|
||||
|
||||
return (int)length;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1987, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,147 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#define wsize sizeof(word_t)
|
||||
#define wmask (wsize - 1)
|
||||
|
||||
/*
|
||||
* Copy a block of memory, handling overlap.
|
||||
* This is the routine that actually implements
|
||||
* (the portable versions of) bcopy, memcpy, and memmove.
|
||||
*/
|
||||
#if defined(MEMCOPY) || defined(MEMMOVE)
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
#ifdef MEMCOPY
|
||||
memcpy
|
||||
#else
|
||||
memmove
|
||||
#endif
|
||||
(void *dst0, const void *src0, size_t length)
|
||||
#else
|
||||
#include <strings.h>
|
||||
|
||||
void
|
||||
bcopy(const void *src0, void *dst0, usize length)
|
||||
#endif
|
||||
{
|
||||
char *dst = dst0;
|
||||
const char *src = src0;
|
||||
usize t;
|
||||
|
||||
if (length == 0 || dst == src) /* nothing to do */
|
||||
goto done;
|
||||
|
||||
/*
|
||||
* Macros: loop-t-times; and loop-t-times, t>0
|
||||
*/
|
||||
#define TLOOP(s) if (t) TLOOP1(s)
|
||||
#define TLOOP1(s) do { s; } while (--t)
|
||||
|
||||
if ((unsigned long)dst < (unsigned long)src) {
|
||||
/*
|
||||
* Copy forward.
|
||||
*/
|
||||
t = (uintptr_t)src; /* only need low bits */
|
||||
if ((t | (uintptr_t)dst) & wmask) {
|
||||
/*
|
||||
* Try to align operands. This cannot be done
|
||||
* unless the low bits match.
|
||||
*/
|
||||
if ((t ^ (uintptr_t)dst) & wmask || length < wsize)
|
||||
t = length;
|
||||
else
|
||||
t = wsize - (t & wmask);
|
||||
length -= t;
|
||||
TLOOP1(*dst++ = *src++);
|
||||
}
|
||||
/*
|
||||
* Copy whole words, then mop up any trailing bytes.
|
||||
*/
|
||||
t = length / wsize;
|
||||
TLOOP(*(word_t *)(void *)dst = *(const word_t *)(const void *)src;
|
||||
src += wsize; dst += wsize);
|
||||
t = length & wmask;
|
||||
TLOOP(*dst++ = *src++);
|
||||
} else {
|
||||
/*
|
||||
* Copy backwards. Otherwise essentially the same.
|
||||
* Alignment works as before, except that it takes
|
||||
* (t&wmask) bytes to align, not wsize-(t&wmask).
|
||||
*/
|
||||
src += length;
|
||||
dst += length;
|
||||
t = (uintptr_t)src;
|
||||
if ((t | (uintptr_t)dst) & wmask) {
|
||||
if ((t ^ (uintptr_t)dst) & wmask || length <= wsize)
|
||||
t = length;
|
||||
else
|
||||
t &= wmask;
|
||||
length -= t;
|
||||
TLOOP1(*--dst = *--src);
|
||||
}
|
||||
t = length / wsize;
|
||||
TLOOP(src -= wsize; dst -= wsize;
|
||||
*(word_t *)(void *)dst = *(const word_t *)(const void *)src);
|
||||
t = length & wmask;
|
||||
TLOOP(*--dst = *--src);
|
||||
}
|
||||
done:
|
||||
#if defined(MEMCOPY) || defined(MEMMOVE)
|
||||
return dst0;
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,2 @@
|
||||
#define BZERO
|
||||
#include "memset.c"
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* Find First Set bit
|
||||
*/
|
||||
int ffs(int mask)
|
||||
{
|
||||
int bit = 0;
|
||||
|
||||
if (mask != 0) {
|
||||
for (bit = 1; !(mask & 1); bit++)
|
||||
mask = (unsigned int)mask >> 1; /* NOLINT */
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* Find First Set bit
|
||||
*/
|
||||
int ffsl(long mask)
|
||||
{
|
||||
int bit = 0;
|
||||
|
||||
if (mask != 0) {
|
||||
for (bit = 1; !(mask & 1); bit++)
|
||||
mask = (unsigned long)mask >> 1; /* NOLINT */
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* Find First Set bit
|
||||
*/
|
||||
int ffsll(long long mask)
|
||||
{
|
||||
int bit = 0;
|
||||
|
||||
if (mask != 0) {
|
||||
for (bit = 1; !(mask & 1); bit++)
|
||||
mask = (unsigned long long)mask >> 1; /* NOLINT */
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* Find Last Set bit
|
||||
*/
|
||||
int fls(int mask)
|
||||
{
|
||||
int bit = 0;
|
||||
|
||||
if (mask != 0) {
|
||||
for (bit = 1; mask != 1; bit++)
|
||||
mask = (unsigned int)mask >> 1; /* NOLINT */
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* Find Last Set bit
|
||||
*/
|
||||
int flsl(long mask)
|
||||
{
|
||||
int bit = 0;
|
||||
|
||||
if (mask != 0) {
|
||||
for (bit = 1; mask != 1; bit++)
|
||||
mask = (unsigned long)mask >> 1; /* NOLINT */
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
* Find Last Set bit
|
||||
*/
|
||||
int flsll(long long mask)
|
||||
{
|
||||
int bit = 0;
|
||||
|
||||
if (mask != 0) {
|
||||
for (bit = 1; mask != 1; bit++)
|
||||
mask = (unsigned long long)mask >> 1; /* NOLINT */
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,68 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *memccpy(void *t, const void *f, int c, usize n)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,75 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SS (sizeof(size_t))
|
||||
#define ALIGN (sizeof(size_t) - 1)
|
||||
#define ONES ((size_t)-1 / UCHAR_MAX)
|
||||
#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
|
||||
#define HASZERO(x) (((x)-ONES) & ~(x)&HIGHS)
|
||||
|
||||
void *memchr(const void *src, int c, usize n)
|
||||
{
|
||||
const unsigned char *s = src;
|
||||
c = (unsigned char)c;
|
||||
#ifdef __GNUC__
|
||||
for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--)
|
||||
;
|
||||
if (n && *s != c) {
|
||||
typedef usize __attribute__((__may_alias__)) word;
|
||||
const word *w;
|
||||
usize k = ONES * c;
|
||||
for (w = (const void *)s; n >= SS && !HASZERO(*w ^ k);
|
||||
w++, n -= SS)
|
||||
;
|
||||
s = (const void *)w;
|
||||
}
|
||||
#endif
|
||||
for (; n && *s != c; s++, n--)
|
||||
;
|
||||
return n ? (void *)s : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005-2014 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,72 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Compare memory regions.
|
||||
*/
|
||||
int memcmp(const void *s1, const void *s2, usize n)
|
||||
{
|
||||
if (n != 0) {
|
||||
const unsigned char *p1 = s1, *p2 = s2;
|
||||
|
||||
do {
|
||||
if (*p1++ != *p2++)
|
||||
return (*--p1 - *--p2);
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,2 @@
|
||||
#define MEMCOPY
|
||||
#include "bcopy.c"
|
@ -0,0 +1,227 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
#include <gay/util.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static char *twobyte_memmem(const unsigned char *h, usize k, const unsigned char *n)
|
||||
{
|
||||
u16 nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1];
|
||||
for (h += 2, k -= 2; k; k--, hw = hw << 8 | *h++) {
|
||||
if (hw == nw)
|
||||
return (char *)h - 2;
|
||||
}
|
||||
return hw == nw ? (char *)h - 2 : 0;
|
||||
}
|
||||
|
||||
static char *threebyte_memmem(const unsigned char *h, usize k, const unsigned char *n)
|
||||
{
|
||||
u32 nw = (u32)n[0] << 24 | n[1] << 16 | n[2] << 8;
|
||||
u32 hw = (u32)h[0] << 24 | h[1] << 16 | h[2] << 8;
|
||||
for (h += 3, k -= 3; k; k--, hw = (hw | *h++) << 8) {
|
||||
if (hw == nw)
|
||||
return (char *)h - 3;
|
||||
}
|
||||
return hw == nw ? (char *)h - 3 : 0;
|
||||
}
|
||||
|
||||
static char *fourbyte_memmem(const unsigned char *h, usize k, const unsigned char *n)
|
||||
{
|
||||
u32 nw = (u32)n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
|
||||
u32 hw = (u32)h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
|
||||
for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++) {
|
||||
if (hw == nw)
|
||||
return (char *)h - 4;
|
||||
}
|
||||
return hw == nw ? (char *)h - 4 : 0;
|
||||
}
|
||||
|
||||
#define BITOP(a, b, op) \
|
||||
((a)[(size_t)(b) / (8 * sizeof *(a))] op \
|
||||
(size_t)1 << ((size_t)(b) % (8 * sizeof *(a))))
|
||||
|
||||
/*
|
||||
* Two Way string search algorithm, with a bad shift table applied to the last
|
||||
* byte of the window. A bit array marks which entries in the shift table are
|
||||
* initialized to avoid fully initializing a 1kb/2kb table.
|
||||
*
|
||||
* Reference: CROCHEMORE M., PERRIN D., 1991, Two-way string-matching,
|
||||
* Journal of the ACM 38(3):651-675
|
||||
*/
|
||||
static char *twoway_memmem(const unsigned char *h, const unsigned char *z,
|
||||
const unsigned char *n, usize l)
|
||||
{
|
||||
usize i, ip, jp, k, p, ms, p0, mem, mem0;
|
||||
usize byteset[32 / sizeof(usize)] = { 0 };
|
||||
usize shift[256];
|
||||
|
||||
/* Computing length of needle and fill shift table */
|
||||
for (i = 0; i < l; i++)
|
||||
BITOP(byteset, n[i], |=), shift[n[i]] = i + 1;
|
||||
|
||||
/* Compute maximal suffix */
|
||||
ip = -1;
|
||||
jp = 0;
|
||||
k = p = 1;
|
||||
while (jp + k < l) {
|
||||
if (n[ip + k] == n[jp + k]) {
|
||||
if (k == p) {
|
||||
jp += p;
|
||||
k = 1;
|
||||
} else
|
||||
k++;
|
||||
} else if (n[ip + k] > n[jp + k]) {
|
||||
jp += k;
|
||||
k = 1;
|
||||
p = jp - ip;
|
||||
} else {
|
||||
ip = jp++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
ms = ip;
|
||||
p0 = p;
|
||||
|
||||
/* And with the opposite comparison */
|
||||
ip = -1;
|
||||
jp = 0;
|
||||
k = p = 1;
|
||||
while (jp + k < l) {
|
||||
if (n[ip + k] == n[jp + k]) {
|
||||
if (k == p) {
|
||||
jp += p;
|
||||
k = 1;
|
||||
} else
|
||||
k++;
|
||||
} else if (n[ip + k] < n[jp + k]) {
|
||||
jp += k;
|
||||
k = 1;
|
||||
p = jp - ip;
|
||||
} else {
|
||||
ip = jp++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
if (ip + 1 > ms + 1)
|
||||
ms = ip;
|
||||
else
|
||||
p = p0;
|
||||
|
||||
/* Periodic needle? */
|
||||
if (memcmp(n, n + p, ms + 1) != 0) {
|
||||
mem0 = 0;
|
||||
p = max(ms, l - ms - 1) + 1;
|
||||
} else
|
||||
mem0 = l - p;
|
||||
mem = 0;
|
||||
|
||||
/* Search loop */
|
||||
for (;;) {
|
||||
/* If remainder of haystack is shorter than needle, done */
|
||||
if (z - h < l)
|
||||
return 0;
|
||||
|
||||
/* Check last byte first; advance by shift on mismatch */
|
||||
if (BITOP(byteset, h[l - 1], &)) {
|
||||
k = l - shift[h[l - 1]];
|
||||
if (k) {
|
||||
if (k < mem)
|
||||
k = mem;
|
||||
h += k;
|
||||
mem = 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
h += l;
|
||||
mem = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Compare right half */
|
||||
for (k = max(ms + 1, mem); k < l && n[k] == h[k]; k++)
|
||||
;
|
||||
if (k < l) {
|
||||
h += k - ms;
|
||||
mem = 0;
|
||||
continue;
|
||||
}
|
||||
/* Compare left half */
|
||||
for (k = ms + 1; k > mem && n[k - 1] == h[k - 1]; k--)
|
||||
;
|
||||
if (k <= mem)
|
||||
return (char *)h;
|
||||
h += p;
|
||||
mem = mem0;
|
||||
}
|
||||
}
|
||||
|
||||
void *memmem(const void *h0, usize k, const void *n0, usize l)
|
||||
{
|
||||
const unsigned char *h = h0, *n = n0;
|
||||
|
||||
/* Return immediately on empty needle */
|
||||
if (!l)
|
||||
return (void *)h;
|
||||
|
||||
/* Return immediately when needle is longer than haystack */
|
||||
if (k < l)
|
||||
return 0;
|
||||
|
||||
/* Use faster algorithms for short needles */
|
||||
h = memchr(h0, *n, k);
|
||||
if (!h || l == 1)
|
||||
return (void *)h;
|
||||
k -= h - (const unsigned char *)h0;
|
||||
if (k < l)
|
||||
return 0;
|
||||
if (l == 2)
|
||||
return twobyte_memmem(h, k, n);
|
||||
if (l == 3)
|
||||
return threebyte_memmem(h, k, n);
|
||||
if (l == 4)
|
||||
return fourbyte_memmem(h, k, n);
|
||||
|
||||
return twoway_memmem(h, h + k, n, l);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005-2014 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,2 @@
|
||||
#define MEMMOVE
|
||||
#include "bcopy.c"
|
@ -0,0 +1,59 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Reverse memchr()
|
||||
* Find the last occurrence of 'c' in the buffer 's' of size 'n'.
|
||||
*/
|
||||
void *memrchr(const void *s, int c, usize n)
|
||||
{
|
||||
const unsigned char *cp = NULL;
|
||||
|
||||
if (n != 0) {
|
||||
cp = (unsigned char *)s + n;
|
||||
do {
|
||||
if (*(--cp) == (unsigned char)c)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
return (void *)cp;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2007 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.
|
||||
*
|
||||
* $OpenBSD: memrchr.c,v 1.2 2007/11/27 16:22:12 martynas Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,144 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define wsize sizeof(unsigned long)
|
||||
#define wmask (wsize - 1)
|
||||
|
||||
#ifdef BZERO
|
||||
#include <strings.h>
|
||||
|
||||
#define RETURN return
|
||||
#define VAL 0
|
||||
#define WIDEVAL 0
|
||||
|
||||
void bzero(void *dst0, usize length)
|
||||
#else
|
||||
#include <string.h>
|
||||
|
||||
#define RETURN return (dst0)
|
||||
#define VAL c0
|
||||
#define WIDEVAL c
|
||||
|
||||
void *memset(void *dst0, int c0, usize length)
|
||||
#endif
|
||||
{
|
||||
usize t;
|
||||
#ifndef BZERO
|
||||
unsigned long c;
|
||||
#endif
|
||||
unsigned char *dst;
|
||||
|
||||
dst = dst0;
|
||||
/*
|
||||
* If not enough words, just fill bytes. A length >= 2 words
|
||||
* guarantees that at least one of them is `complete' after
|
||||
* any necessary alignment. For instance:
|
||||
*
|
||||
* |-----------|-----------|-----------|
|
||||
* |00|01|02|03|04|05|06|07|08|09|0A|00|
|
||||
* ^---------------------^
|
||||
* dst dst+length-1
|
||||
*
|
||||
* but we use a minimum of 3 here since the overhead of the code
|
||||
* to do word writes is substantial.
|
||||
*
|
||||
* TODO: This threshold might not be sensible for 64-bit u_long.
|
||||
* We should benchmark and revisit this decision.
|
||||
*/
|
||||
if (length < 3 * wsize) {
|
||||
while (length != 0) {
|
||||
*dst++ = VAL;
|
||||
--length;
|
||||
}
|
||||
RETURN;
|
||||
}
|
||||
|
||||
#ifndef BZERO
|
||||
if ((c = (unsigned char)c0) != 0) { /* Fill the word. */
|
||||
c = (c << 8) | c; /* u_long is 16 bits. */
|
||||
#if ULONG_MAX > 0xffff
|
||||
c = (c << 16) | c; /* u_long is 32 bits. */
|
||||
#endif
|
||||
#if ULONG_MAX > 0xffffffff
|
||||
c = (c << 32) | c; /* u_long is 64 bits. */
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/* Align destination by filling in bytes. */
|
||||
if ((t = (long)dst & wmask) != 0) {
|
||||
t = wsize - t;
|
||||
length -= t;
|
||||
do {
|
||||
*dst++ = VAL;
|
||||
} while (--t != 0);
|
||||
}
|
||||
|
||||
/* Fill words. Length was >= 2*words so we know t >= 1 here. */
|
||||
t = length / wsize;
|
||||
do {
|
||||
*(unsigned long *)(void *)dst = WIDEVAL;
|
||||
dst += wsize;
|
||||
} while (--t != 0);
|
||||
|
||||
/* Mop up trailing bytes, if any. */
|
||||
t = length & wmask;
|
||||
if (t != 0) {
|
||||
do {
|
||||
*dst++ = VAL;
|
||||
} while (--t != 0);
|
||||
}
|
||||
RETURN;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Mike Hibler and 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,58 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *stpcpy(char *restrict to, const char *restrict from)
|
||||
{
|
||||
for (; (*to = *from); ++from, ++to);
|
||||
return to;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1999
|
||||
* David E. O'Brien
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,62 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *stpncpy(char *restrict dst, const char *restrict src, usize n)
|
||||
{
|
||||
for (; n--; dst++, src++) {
|
||||
if (!(*dst = *src)) {
|
||||
char *ret = dst;
|
||||
while (n--)
|
||||
*++dst = '\0';
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,63 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strcat(char *restrict s, const char *restrict append)
|
||||
{
|
||||
char *save = s;
|
||||
|
||||
for (; *s != '\0'; ++s)
|
||||
/* nothing */;
|
||||
|
||||
while ((*s++ = *append++))
|
||||
/* nothing */;
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,57 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
char *__strchrnul(const char *, int);
|
||||
|
||||
char *strchr(const char *s, int c)
|
||||
{
|
||||
char *r = __strchrnul(s, c);
|
||||
return *(unsigned char *)r == (unsigned char)c ? r : NULL;
|
||||
}
|
||||
|
||||
__weak __alias(strchr) char *index(const char *, int);
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005-2014 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,79 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ALIGN (sizeof(usize))
|
||||
#define ONES ((usize)-1 / UCHAR_MAX)
|
||||
#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
|
||||
#define HASZERO(x) ( ((x) - ONES) & ~(x) & HIGHS )
|
||||
|
||||
char *__strchrnul(const char *, int);
|
||||
|
||||
char *__strchrnul(const char *s, int c)
|
||||
{
|
||||
c = (unsigned char)c;
|
||||
if (!c)
|
||||
return (char *)s + strlen(s);
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef usize __attribute__((__may_alias__)) word;
|
||||
const word *w;
|
||||
for (; (uintptr_t)s % ALIGN; s++)
|
||||
if (!*s || *(unsigned char *)s == c)
|
||||
return (char *)s;
|
||||
usize k = ONES * c;
|
||||
for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w ^ k); w++)
|
||||
;
|
||||
s = (void *)w;
|
||||
#endif
|
||||
for (; *s && *(unsigned char *)s != c; s++)
|
||||
;
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
__weak __alias(__strchrnul) char *strchrnul(const char *, int);
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005-2014 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Compare strings.
|
||||
*/
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 == *s2++) {
|
||||
if (*s1++ == '\0')
|
||||
return 0;
|
||||
}
|
||||
return *(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,70 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WEAK_STRCPY
|
||||
__weak_reference(__strcpy, strcpy);
|
||||
#endif
|
||||
|
||||
char *
|
||||
#ifdef WEAK_STRCPY
|
||||
__strcpy
|
||||
#else
|
||||
strcpy
|
||||
#endif
|
||||
(char *restrict to, const char *restrict from)
|
||||
{
|
||||
char *save = to;
|
||||
|
||||
for (; (*to = *from); ++from, ++to)
|
||||
/* nothing */;
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,89 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#define IDX(c) ((unsigned char)(c) / LONG_BIT)
|
||||
#define BIT(c) ((unsigned long)1 << ((unsigned char)(c) % LONG_BIT))
|
||||
|
||||
usize strcspn(const char *s, const char *charset)
|
||||
{
|
||||
/*
|
||||
* NB: idx and bit are temporaries whose use causes gcc 3.4.2 to
|
||||
* generate better code. Without them, gcc gets a little confused.
|
||||
*/
|
||||
const char *s1;
|
||||
unsigned long bit;
|
||||
unsigned long tbl[(UCHAR_MAX + 1) / LONG_BIT];
|
||||
int idx;
|
||||
|
||||
if(*s == '\0')
|
||||
return (0);
|
||||
|
||||
#if LONG_BIT == 64 /* always better to unroll on 64-bit architectures */
|
||||
tbl[0] = 1;
|
||||
tbl[3] = tbl[2] = tbl[1] = 0;
|
||||
#else
|
||||
for (tbl[0] = idx = 1; idx < sizeof(tbl) / sizeof(tbl[0]); idx++)
|
||||
tbl[idx] = 0;
|
||||
#endif
|
||||
for (; *charset != '\0'; charset++) {
|
||||
idx = IDX(*charset);
|
||||
bit = BIT(*charset);
|
||||
tbl[idx] |= bit;
|
||||
}
|
||||
|
||||
for(s1 = s; ; s1++) {
|
||||
idx = IDX(*s1);
|
||||
bit = BIT(*s1);
|
||||
if ((tbl[idx] & bit) != 0)
|
||||
break;
|
||||
}
|
||||
return (s1 - s);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/mm.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strdup(const char *str)
|
||||
{
|
||||
usize len;
|
||||
char *copy;
|
||||
|
||||
len = strlen(str) + 1;
|
||||
if ((copy = kmalloc(len, MM_KERNEL)) == NULL)
|
||||
return NULL;
|
||||
|
||||
memcpy(copy, str, len);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,75 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||
* If retval >= dsize, truncation occurred.
|
||||
*/
|
||||
usize strlcat(char *restrict dst, const char *restrict src, usize dsize)
|
||||
{
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
usize n = dsize;
|
||||
usize dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != '\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n-- == 0)
|
||||
return dlen + strlen(src);
|
||||
|
||||
while (*src != '\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
return dlen + (src - osrc); /* count does not include NUL */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1998, 2015 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.
|
||||
*
|
||||
* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,69 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||
*/
|
||||
usize strlcpy(char *restrict dst, const char *restrict src, usize dsize)
|
||||
{
|
||||
const char *osrc = src;
|
||||
usize nleft = dsize;
|
||||
|
||||
/* Copy as many bytes as will fit. */
|
||||
if (nleft != 0) {
|
||||
while (--nleft != 0) {
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||
if (nleft == 0) {
|
||||
if (dsize != 0)
|
||||
*dst = '\0'; /* NUL-terminate dst */
|
||||
while (*src++)
|
||||
/* nothing */;
|
||||
}
|
||||
|
||||
return src - osrc - 1; /* count does not include NUL */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1998, 2015 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.
|
||||
*
|
||||
* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,141 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Portable strlen() for 32-bit and 64-bit systems.
|
||||
*
|
||||
* The expression:
|
||||
*
|
||||
* ((x - 0x01....01) & ~x & 0x80....80)
|
||||
*
|
||||
* would evaluate to a non-zero value iff any of the bytes in the
|
||||
* original word is zero.
|
||||
*
|
||||
* The algorithm above is found on "Hacker's Delight" by
|
||||
* Henry S. Warren, Jr.
|
||||
*
|
||||
* Note: this leaves performance on the table and each architecture
|
||||
* would be best served with a tailor made routine instead, even if
|
||||
* using the same trick.
|
||||
*/
|
||||
|
||||
/* Magic numbers for the algorithm */
|
||||
#if LONG_BIT == 32
|
||||
static const unsigned long mask01 = 0x01010101;
|
||||
static const unsigned long mask80 = 0x80808080;
|
||||
#elif LONG_BIT == 64
|
||||
static const unsigned long mask01 = 0x0101010101010101;
|
||||
static const unsigned long mask80 = 0x8080808080808080;
|
||||
#else
|
||||
#error "Unsupported word size"
|
||||
#endif
|
||||
|
||||
#define LONGPTR_MASK (sizeof(long) - 1)
|
||||
|
||||
/*
|
||||
* Helper macro to return string length if we caught the zero
|
||||
* byte.
|
||||
*/
|
||||
#define testbyte(x) \
|
||||
do { \
|
||||
if (p[x] == '\0') \
|
||||
return (p - str + x); \
|
||||
} while (0)
|
||||
|
||||
usize strlen(const char *str)
|
||||
{
|
||||
const char *p;
|
||||
const unsigned long *lp;
|
||||
long va, vb;
|
||||
|
||||
/*
|
||||
* Before trying the hard (unaligned byte-by-byte access) way
|
||||
* to figure out whether there is a nul character, try to see
|
||||
* if there is a nul character is within this accessible word
|
||||
* first.
|
||||
*
|
||||
* p and (p & ~LONGPTR_MASK) must be equally accessible since
|
||||
* they always fall in the same memory page, as long as page
|
||||
* boundaries is integral multiple of word size.
|
||||
*/
|
||||
lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK);
|
||||
va = (*lp - mask01); /* NOLINT */
|
||||
vb = ((~*lp) & mask80); /* NOLINT */
|
||||
lp++;
|
||||
if (va & vb) {
|
||||
/* Check if we have \0 in the first part */
|
||||
for (p = str; p < (const char *)lp; p++) {
|
||||
if (*p == '\0')
|
||||
return (p - str);
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan the rest of the string using word sized operation */
|
||||
for (; ; lp++) {
|
||||
va = (*lp - mask01); /* NOLINT */
|
||||
vb = ((~*lp) & mask80); /* NOLINT */
|
||||
if (va & vb) {
|
||||
p = (const char *)(lp);
|
||||
testbyte(0);
|
||||
testbyte(1);
|
||||
testbyte(2);
|
||||
testbyte(3);
|
||||
#if (LONG_BIT >= 64)
|
||||
testbyte(4);
|
||||
testbyte(5);
|
||||
testbyte(6);
|
||||
testbyte(7);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2009, 2010 Xin LI <delphij@FreeBSD.org>
|
||||
*
|
||||
* 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 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,77 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes
|
||||
* are written at dst (at most n+1 bytes being appended). Return dst.
|
||||
*/
|
||||
char *strncat(char *restrict dst, const char *restrict src, usize n)
|
||||
{
|
||||
if (n != 0) {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
||||
while (*d != 0)
|
||||
d++;
|
||||
do {
|
||||
if ((*d = *s++) == 0)
|
||||
break;
|
||||
d++;
|
||||
} while (--n != 0);
|
||||
*d = 0;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strncmp(const char *s1, const char *s2, usize n)
|
||||
{
|
||||
if (n == 0)
|
||||
return 0;
|
||||
do {
|
||||
if (*s1 != *s2++)
|
||||
return *(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1);
|
||||
if (*s1++ == '\0')
|
||||
break;
|
||||
} while (--n != 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,84 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy src to dst, truncating or null-padding to always copy n bytes.
|
||||
* Return dst.
|
||||
*/
|
||||
#ifdef WEAK_STRNCPY
|
||||
__weak __alias(__strncpy) char *strncpy(char *restrict, const char *restrict, usize);
|
||||
#define FUNC_NAME __strncpy
|
||||
#else
|
||||
#define FUNC_NAME strncpy
|
||||
#endif
|
||||
|
||||
char *FUNC_NAME(char *restrict dst, const char *restrict src, usize n)
|
||||
{
|
||||
if (n != 0) {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
||||
do {
|
||||
if ((*d++ = *s++) == '\0') {
|
||||
/* NUL pad the remaining n-1 bytes */
|
||||
while (--n != 0)
|
||||
*d++ = '\0';
|
||||
break;
|
||||
}
|
||||
} while (--n != 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,57 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/mm.h>
|
||||
#include <gay/types.h>
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <string.h>
|
||||
|
||||
char *strndup(const char *str, usize maxlen)
|
||||
{
|
||||
char *copy;
|
||||
usize len;
|
||||
|
||||
len = strnlen(str, maxlen);
|
||||
copy = kmalloc(len + 1, MM_KERNEL);
|
||||
if (copy != NULL) {
|
||||
memcpy(copy, str, len);
|
||||
copy[len] = '\0';
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*
|
||||
* $OpenBSD: strndup.c,v 1.1 2010/05/18 22:24:55 tedu Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,61 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
usize strnlen(const char *s, usize maxlen)
|
||||
{
|
||||
usize len;
|
||||
|
||||
for (len = 0; len < maxlen; len++, s++) {
|
||||
if (*s == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,81 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, where the search is limited to the
|
||||
* first slen characters of s.
|
||||
*/
|
||||
char *strnstr(const char *s, const char *find, usize slen)
|
||||
{
|
||||
char c, sc;
|
||||
usize len;
|
||||
|
||||
if ((c = *find++) != '\0') {
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if (slen-- < 1 || (sc = *s++) == '\0')
|
||||
return (NULL);
|
||||
} while (sc != c);
|
||||
if (len > slen)
|
||||
return (NULL);
|
||||
} while (strncmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,69 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Find the first occurrence in s of a character in charset (excluding NUL).
|
||||
*/
|
||||
char *strpbrk(const char *s, const char *charset)
|
||||
{
|
||||
const char *scanp;
|
||||
int c, sc;
|
||||
|
||||
while ((c = *s++) != 0) { /* NOLINT */
|
||||
for (scanp = charset; (sc = *scanp++) != '\0';) /* NOLINT */
|
||||
if (sc == c)
|
||||
return ((char *)(s - 1));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1985, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,69 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strrchr(const char *p, int ch)
|
||||
{
|
||||
char *save;
|
||||
char c;
|
||||
|
||||
c = ch; /* NOLINT */
|
||||
for (save = NULL;; ++p) {
|
||||
if (*p == c)
|
||||
save = (char *)p;
|
||||
if (*p == '\0')
|
||||
return save;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
__weak __alias(strrchr) char *rindex(const char *, int);
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,89 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 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++; /* NOLINT */
|
||||
spanp = delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) { /* NOLINT */
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
*stringp = s;
|
||||
return tok;
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,88 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#define IDX(c) ((unsigned char)(c) / LONG_BIT)
|
||||
#define BIT(c) ((unsigned long)1 << ((unsigned char)(c) % LONG_BIT))
|
||||
|
||||
usize strspn(const char *s, const char *charset)
|
||||
{
|
||||
/*
|
||||
* NB: idx and bit are temporaries whose use causes gcc 3.4.2 to
|
||||
* generate better code. Without them, gcc gets a little confused.
|
||||
*/
|
||||
const char *s1;
|
||||
unsigned long bit;
|
||||
unsigned long tbl[(UCHAR_MAX + 1) / LONG_BIT];
|
||||
int idx;
|
||||
|
||||
if(*s == '\0')
|
||||
return (0);
|
||||
|
||||
#if LONG_BIT == 64 /* always better to unroll on 64-bit architectures */
|
||||
tbl[3] = tbl[2] = tbl[1] = tbl[0] = 0;
|
||||
#else
|
||||
for (idx = 0; idx < sizeof(tbl) / sizeof(tbl[0]); idx++)
|
||||
tbl[idx] = 0;
|
||||
#endif
|
||||
for (; *charset != '\0'; charset++) {
|
||||
idx = IDX(*charset);
|
||||
bit = BIT(*charset);
|
||||
tbl[idx] |= bit;
|
||||
}
|
||||
|
||||
for(s1 = s; ; s1++) {
|
||||
idx = IDX(*s1);
|
||||
bit = BIT(*s1);
|
||||
if ((tbl[idx] & bit) == 0)
|
||||
break;
|
||||
}
|
||||
return (s1 - s);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,232 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
#include <gay/util.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static char *twobyte_strstr(const unsigned char *h, const unsigned char *n)
|
||||
{
|
||||
u16 nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1];
|
||||
for (h++; *h && hw != nw; hw = hw << 8 | *++h)
|
||||
/* nothing */;
|
||||
return *h ? (char *)h - 1 : 0;
|
||||
}
|
||||
|
||||
static char *threebyte_strstr(const unsigned char *h, const unsigned char *n)
|
||||
{
|
||||
u32 nw = (u32)n[0] << 24 | n[1] << 16 | n[2] << 8;
|
||||
u32 hw = (u32)h[0] << 24 | h[1] << 16 | h[2] << 8;
|
||||
for (h += 2; *h && hw != nw; hw = (hw | *++h) << 8)
|
||||
/* nothing */;
|
||||
return *h ? (char *)h - 2 : 0;
|
||||
}
|
||||
|
||||
static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n)
|
||||
{
|
||||
u32 nw = (u32)n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
|
||||
u32 hw = (u32)h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
|
||||
for (h += 3; *h && hw != nw; hw = hw << 8 | *++h)
|
||||
/* nothing */;
|
||||
return *h ? (char *)h - 3 : 0;
|
||||
}
|
||||
|
||||
#define BITOP(a, b, op) \
|
||||
((a)[(usize)(b) / (8 * sizeof *(a))] op \
|
||||
(usize)1 << ((usize)(b) % (8 * sizeof *(a))))
|
||||
|
||||
/*
|
||||
* Two Way string search algorithm, with a bad shift table applied to the last
|
||||
* byte of the window. A bit array marks which entries in the shift table are
|
||||
* initialized to avoid fully initializing a 1kb/2kb table.
|
||||
*
|
||||
* Reference: CROCHEMORE M., PERRIN D., 1991, Two-way string-matching,
|
||||
* Journal of the ACM 38(3):651-675
|
||||
*/
|
||||
static char *twoway_strstr(const unsigned char *h, const unsigned char *n)
|
||||
{
|
||||
const unsigned char *z;
|
||||
usize l, ip, jp, k, p, ms, p0, mem, mem0;
|
||||
usize byteset[32 / sizeof(usize)] = { 0 };
|
||||
usize shift[256];
|
||||
|
||||
/* Computing length of needle and fill shift table */
|
||||
for (l = 0; n[l] && h[l]; l++)
|
||||
BITOP(byteset, n[l], |=), shift[n[l]] = l + 1;
|
||||
if (n[l])
|
||||
return 0; /* hit the end of h */
|
||||
|
||||
/* Compute maximal suffix */
|
||||
ip = -1;
|
||||
jp = 0;
|
||||
k = p = 1;
|
||||
while (jp + k < l) {
|
||||
if (n[ip + k] == n[jp + k]) {
|
||||
if (k == p) {
|
||||
jp += p;
|
||||
k = 1;
|
||||
} else
|
||||
k++;
|
||||
} else if (n[ip + k] > n[jp + k]) {
|
||||
jp += k;
|
||||
k = 1;
|
||||
p = jp - ip;
|
||||
} else {
|
||||
ip = jp++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
ms = ip;
|
||||
p0 = p;
|
||||
|
||||
/* And with the opposite comparison */
|
||||
ip = -1;
|
||||
jp = 0;
|
||||
k = p = 1;
|
||||
while (jp + k < l) {
|
||||
if (n[ip + k] == n[jp + k]) {
|
||||
if (k == p) {
|
||||
jp += p;
|
||||
k = 1;
|
||||
} else
|
||||
k++;
|
||||
} else if (n[ip + k] < n[jp + k]) {
|
||||
jp += k;
|
||||
k = 1;
|
||||
p = jp - ip;
|
||||
} else {
|
||||
ip = jp++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
if (ip + 1 > ms + 1)
|
||||
ms = ip;
|
||||
else
|
||||
p = p0;
|
||||
|
||||
/* Periodic needle? */
|
||||
if (memcmp(n, n + p, ms + 1) != 0) {
|
||||
mem0 = 0;
|
||||
p = max(ms, l - ms - 1) + 1;
|
||||
} else
|
||||
mem0 = l - p;
|
||||
mem = 0;
|
||||
|
||||
/* Initialize incremental end-of-haystack pointer */
|
||||
z = h;
|
||||
|
||||
/* Search loop */
|
||||
for (;;) {
|
||||
/* Update incremental end-of-haystack pointer */
|
||||
if (z - h < l) {
|
||||
/* Fast estimate for MIN(l,63) */
|
||||
usize grow = l | 63;
|
||||
const unsigned char *z2 = memchr(z, 0, grow);
|
||||
if (z2) {
|
||||
z = z2;
|
||||
if (z - h < l)
|
||||
return 0;
|
||||
} else
|
||||
z += grow;
|
||||
}
|
||||
|
||||
/* Check last byte first; advance by shift on mismatch */
|
||||
if (BITOP(byteset, h[l - 1], &)) {
|
||||
k = l - shift[h[l - 1]];
|
||||
if (k) {
|
||||
if (k < mem)
|
||||
k = mem;
|
||||
h += k;
|
||||
mem = 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
h += l;
|
||||
mem = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Compare right half */
|
||||
for (k = max(ms + 1, mem); n[k] && n[k] == h[k]; k++)
|
||||
/* nothing */;
|
||||
if (n[k]) {
|
||||
h += k - ms;
|
||||
mem = 0;
|
||||
continue;
|
||||
}
|
||||
/* Compare left half */
|
||||
for (k = ms + 1; k > mem && n[k - 1] == h[k - 1]; k--)
|
||||
;
|
||||
if (k <= mem)
|
||||
return (char *)h;
|
||||
h += p;
|
||||
mem = mem0;
|
||||
}
|
||||
}
|
||||
|
||||
char *strstr(const char *h, const char *n)
|
||||
{
|
||||
/* Return immediately on empty needle */
|
||||
if (!n[0])
|
||||
return (char *)h;
|
||||
|
||||
/* Use faster algorithms for short needles */
|
||||
h = strchr(h, *n);
|
||||
if (!h || !n[1])
|
||||
return (char *)h;
|
||||
if (!h[1])
|
||||
return 0;
|
||||
if (!n[2])
|
||||
return twobyte_strstr((void *)h, (void *)n);
|
||||
if (!h[2])
|
||||
return 0;
|
||||
if (!n[3])
|
||||
return threebyte_strstr((void *)h, (void *)n);
|
||||
if (!h[3])
|
||||
return 0;
|
||||
if (!n[4])
|
||||
return fourbyte_strstr((void *)h, (void *)n);
|
||||
|
||||
return twoway_strstr((void *)h, (void *)n);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005-2014 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,114 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <string.h>
|
||||
|
||||
char *__strtok_r(char *s, const char *delim, char **last)
|
||||
{
|
||||
char *spanp, *tok;
|
||||
int c, sc;
|
||||
|
||||
if (s == NULL && (s = *last) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
|
||||
if (c == sc)
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (c == 0) { /* no non-delimiter characters */
|
||||
*last = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for (;;) {
|
||||
c = *s++;
|
||||
spanp = (char *)delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = '\0';
|
||||
*last = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
__weak __alias(__strtok_r) char * strtok_r(char *, const char *, char **);
|
||||
|
||||
char *strtok(char *s, const char *delim)
|
||||
{
|
||||
static char *last;
|
||||
|
||||
return __strtok_r(s, delim, &last);
|
||||
}
|
||||
|
||||
#endif /* not __KERNEL__ */
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1998 Softweyr LLC. All rights reserved.
|
||||
*
|
||||
* strtok_r, from Berkeley strtok
|
||||
* Oct 13, 1998 by Wes Peters <wes@softweyr.com>
|
||||
*
|
||||
* Copyright (c) 1988, 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
|
||||
* notices, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notices, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,76 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void swab(const void *restrict from, void *restrict to, isize len)
|
||||
{
|
||||
unsigned long temp;
|
||||
int n;
|
||||
char *fp, *tp;
|
||||
|
||||
if (len <= 0)
|
||||
return;
|
||||
n = len >> 1;
|
||||
fp = (char *)from;
|
||||
tp = (char *)to;
|
||||
#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp /* NOLINT */
|
||||
/* round to multiple of 8 */
|
||||
for (; n & 0x7; --n)
|
||||
STEP;
|
||||
for (n >>= 3; n > 0; --n) {
|
||||
STEP; STEP; STEP; STEP;
|
||||
STEP; STEP; STEP; STEP;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Jeffrey Mogul.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,59 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcpcpy(wchar_t *restrict to, const wchar_t *restrict from)
|
||||
{
|
||||
for (; (*to = *from); ++from, ++to)
|
||||
/* nothing */;
|
||||
return to;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1999
|
||||
* David E. O'Brien
|
||||
* Copyright (c) 1988, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,62 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcpncpy(wchar_t *restrict dst, const wchar_t *restrict src, usize n)
|
||||
{
|
||||
for (; n--; dst++, src++) {
|
||||
if (!(*dst = *src)) {
|
||||
wchar_t *ret = dst;
|
||||
while (n--)
|
||||
*++dst = L'\0';
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,63 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcscat(wchar_t *restrict s1, const wchar_t *restrict s2)
|
||||
{
|
||||
wchar_t *cp;
|
||||
|
||||
cp = s1;
|
||||
while (*cp != L'\0')
|
||||
cp++;
|
||||
while ((*cp++ = *s2++) != L'\0')
|
||||
/* nothing */;
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,58 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcschr(const wchar_t *s, wchar_t c)
|
||||
{
|
||||
while (*s != c && *s != L'\0')
|
||||
s++;
|
||||
if (*s == c)
|
||||
return (wchar_t *)s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2002 Tim J. Robbins
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,68 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Compare strings.
|
||||
*/
|
||||
int wcscmp(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
while (*s1 == *s2++) {
|
||||
if (*s1++ == '\0')
|
||||
return (0);
|
||||
}
|
||||
/* XXX assumes wchar_t = int */
|
||||
return *(const unsigned int *)s1 - *(const unsigned int *)--s2; /* NOLINT */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,60 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcscpy(wchar_t *restrict s1, const wchar_t *restrict s2)
|
||||
{
|
||||
wchar_t *cp = s1;
|
||||
|
||||
while ((*cp++ = *s2++) != L'\0')
|
||||
/* nothing */;
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,69 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
usize wcscspn(const wchar_t *s, const wchar_t *set)
|
||||
{
|
||||
const wchar_t *p = s;
|
||||
const wchar_t *q;
|
||||
|
||||
while (*p) {
|
||||
q = set;
|
||||
while (*q) {
|
||||
if (*p == *q)
|
||||
goto done;
|
||||
q++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
done:
|
||||
return p - s;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,62 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/mm.h>
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcsdup(const wchar_t *s)
|
||||
{
|
||||
wchar_t *copy;
|
||||
size_t len;
|
||||
|
||||
len = wcslen(s) + 1;
|
||||
if ((copy = kmalloc(len * sizeof(wchar_t), MM_KERNEL)) == NULL)
|
||||
return (NULL);
|
||||
return wmemcpy(copy, s, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2005 Tim J. Robbins.
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,85 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike wcsncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns wcslen(initial dst) + wcslen(src); if retval >= siz,
|
||||
* truncation occurred.
|
||||
*/
|
||||
usize wcslcat(wchar_t *dst, const wchar_t *src, usize siz)
|
||||
{
|
||||
wchar_t *d = dst;
|
||||
const wchar_t *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return dlen + wcslen(s);
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return dlen + (s - src); /* count does not include NUL */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,81 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns wcslen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
usize wcslcpy(wchar_t *dst, const wchar_t *src, usize siz)
|
||||
{
|
||||
wchar_t *d = dst;
|
||||
const wchar_t *s = src;
|
||||
usize n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0 && --n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
/* nothing */;
|
||||
}
|
||||
|
||||
return s - src - 1; /* count does not include NUL */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,60 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
usize wcslen(const wchar_t *s)
|
||||
{
|
||||
const wchar_t *p = s;
|
||||
|
||||
while (*p)
|
||||
p++;
|
||||
|
||||
return p - s;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,67 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcsncat(wchar_t *restrict s1, const wchar_t *restrict s2, usize n)
|
||||
{
|
||||
wchar_t *p = s1;
|
||||
wchar_t *q;
|
||||
const wchar_t *r = s2;
|
||||
|
||||
while (*p)
|
||||
p++;
|
||||
q = p;
|
||||
while (n && *r) {
|
||||
*q++ = *r++;
|
||||
n--;
|
||||
}
|
||||
*q = '\0';
|
||||
return s1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,68 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
int wcsncmp(const wchar_t *s1, const wchar_t *s2, usize n)
|
||||
{
|
||||
if (n == 0)
|
||||
return (0);
|
||||
do {
|
||||
if (*s1 != *s2++) {
|
||||
/* XXX assumes wchar_t = int */
|
||||
return (*(const unsigned int *)s1 -
|
||||
*(const unsigned int *)--s2);
|
||||
}
|
||||
if (*s1++ == 0)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,77 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Copy src to dst, truncating or null-padding to always copy n bytes.
|
||||
* Return dst.
|
||||
*/
|
||||
wchar_t *wcsncpy(wchar_t *restrict dst, const wchar_t *restrict src, usize n)
|
||||
{
|
||||
if (n != 0) {
|
||||
wchar_t *d = dst;
|
||||
const wchar_t *s = src;
|
||||
|
||||
do {
|
||||
if ((*d++ = *s++) == L'\0') {
|
||||
/* NUL pad the remaining n-1 bytes */
|
||||
while (--n != 0)
|
||||
*d++ = L'\0';
|
||||
break;
|
||||
}
|
||||
} while (--n != 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,61 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
usize wcsnlen(const wchar_t *s, usize maxlen)
|
||||
{
|
||||
usize len;
|
||||
|
||||
for (len = 0; len < maxlen; len++, s++) {
|
||||
if (!*s)
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,70 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcspbrk(const wchar_t *s, const wchar_t *set)
|
||||
{
|
||||
const wchar_t *p;
|
||||
const wchar_t *q;
|
||||
|
||||
p = s;
|
||||
while (*p) {
|
||||
q = set;
|
||||
while (*q) {
|
||||
if (*p == *q) {
|
||||
/* LINTED interface specification */
|
||||
return (wchar_t *)p;
|
||||
}
|
||||
q++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,64 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcsrchr(const wchar_t *s, wchar_t c)
|
||||
{
|
||||
const wchar_t *last = NULL;
|
||||
|
||||
for (;;) {
|
||||
if (*s == c)
|
||||
last = s;
|
||||
if (*s == L'\0')
|
||||
break;
|
||||
s++;
|
||||
}
|
||||
|
||||
return (wchar_t *)last;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 2002 Tim J. Robbins
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,72 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
usize wcsspn(const wchar_t *s, const wchar_t *set)
|
||||
{
|
||||
const wchar_t *p;
|
||||
const wchar_t *q;
|
||||
|
||||
p = s;
|
||||
while (*p) {
|
||||
q = set;
|
||||
while (*q) {
|
||||
if (*p == *q)
|
||||
break;
|
||||
q++;
|
||||
}
|
||||
if (!*q)
|
||||
goto done;
|
||||
p++;
|
||||
}
|
||||
|
||||
done:
|
||||
return (p - s);
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,76 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s.
|
||||
*/
|
||||
wchar_t *wcsstr(const wchar_t *restrict s, const wchar_t *restrict find)
|
||||
{
|
||||
wchar_t c, sc;
|
||||
usize len;
|
||||
|
||||
if ((c = *find++) != L'\0') {
|
||||
len = wcslen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == L'\0')
|
||||
return NULL;
|
||||
} while (sc != c);
|
||||
} while (wcsncmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return (wchar_t *)s;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,103 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict delim, wchar_t **restrict last)
|
||||
{
|
||||
const wchar_t *spanp;
|
||||
wchar_t *tok;
|
||||
wchar_t c, sc;
|
||||
|
||||
if (s == NULL && (s = *last) == NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += wcsspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = delim; (sc = *spanp++) != L'\0';) {
|
||||
if (c == sc)
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (c == L'\0') { /* no non-delimiter characters */
|
||||
*last = NULL;
|
||||
return NULL;
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += wcscspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for (;;) {
|
||||
c = *s++;
|
||||
spanp = delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == L'\0')
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = L'\0';
|
||||
*last = s;
|
||||
return tok;
|
||||
}
|
||||
} while (sc != L'\0');
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c) 1998 Softweyr LLC. All rights reserved.
|
||||
*
|
||||
* strtok_r, from Berkeley strtok
|
||||
* Oct 13, 1998 by Wes Peters <wes@softweyr.com>
|
||||
*
|
||||
* Copyright (c) 1988, 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
|
||||
* notices, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notices, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,65 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wmemchr(const wchar_t *s, wchar_t c, usize n)
|
||||
{
|
||||
usize i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (*s == c) {
|
||||
/* LINTED const castaway */
|
||||
return (wchar_t *)s;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,64 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
int wmemcmp(const wchar_t *s1, const wchar_t *s2, usize n)
|
||||
{
|
||||
for (usize i = 0; i < n; i++) {
|
||||
if (*s1 != *s2) {
|
||||
/* wchar might be unsigned */
|
||||
return *s1 > *s2 ? 1 : -1;
|
||||
}
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,56 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wmemcpy(wchar_t *__restrict d, const wchar_t *__restrict s, usize n)
|
||||
{
|
||||
return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t));
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
@ -0,0 +1,63 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <gay/types.h>
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *wmemset(wchar_t *s, wchar_t c, usize n)
|
||||
{
|
||||
usize i;
|
||||
wchar_t *p;
|
||||
|
||||
p = (wchar_t *)s;
|
||||
for (i = 0; i < n; i++) {
|
||||
*p = c;
|
||||
p++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*
|
||||
* ==========================================================================
|
||||
*
|
||||
* This file is derived from FreeBSD source code.
|
||||
*
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp
|
||||
* $FreeBSD$
|
||||
*/
|
Loading…
Reference in New Issue