Home | History | Annotate | Line # | Download | only in libkern
libkern.h revision 1.106.2.2
      1  1.106.2.1       tls /*	$NetBSD: libkern.h,v 1.106.2.2 2017/12/03 11:38:46 jdolecek Exp $	*/
      2        1.3       cgd 
      3        1.1       cgd /*-
      4        1.1       cgd  * Copyright (c) 1992, 1993
      5        1.1       cgd  *	The Regents of the University of California.  All rights reserved.
      6        1.1       cgd  *
      7        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8        1.1       cgd  * modification, are permitted provided that the following conditions
      9        1.1       cgd  * are met:
     10        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15       1.49       agc  * 3. Neither the name of the University nor the names of its contributors
     16        1.1       cgd  *    may be used to endorse or promote products derived from this software
     17        1.1       cgd  *    without specific prior written permission.
     18        1.1       cgd  *
     19        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.1       cgd  * SUCH DAMAGE.
     30        1.1       cgd  *
     31       1.21      fvdl  *	@(#)libkern.h	8.2 (Berkeley) 8/5/94
     32        1.1       cgd  */
     33        1.1       cgd 
     34       1.29    simonb #ifndef _LIB_LIBKERN_LIBKERN_H_
     35       1.29    simonb #define _LIB_LIBKERN_LIBKERN_H_
     36       1.29    simonb 
     37  1.106.2.2  jdolecek #ifdef _KERNEL_OPT
     38  1.106.2.2  jdolecek #include "opt_diagnostic.h"
     39  1.106.2.2  jdolecek #endif
     40  1.106.2.2  jdolecek 
     41        1.1       cgd #include <sys/types.h>
     42       1.62   thorpej #include <sys/inttypes.h>
     43       1.52  christos #include <sys/null.h>
     44        1.4       cgd 
     45        1.7  christos #ifndef LIBKERN_INLINE
     46       1.55     perry #define LIBKERN_INLINE	static __inline
     47        1.7  christos #define LIBKERN_BODY
     48        1.7  christos #endif
     49        1.7  christos 
     50       1.86       dsl LIBKERN_INLINE int imax(int, int) __unused;
     51       1.86       dsl LIBKERN_INLINE int imin(int, int) __unused;
     52       1.86       dsl LIBKERN_INLINE u_int max(u_int, u_int) __unused;
     53       1.86       dsl LIBKERN_INLINE u_int min(u_int, u_int) __unused;
     54       1.86       dsl LIBKERN_INLINE long lmax(long, long) __unused;
     55       1.86       dsl LIBKERN_INLINE long lmin(long, long) __unused;
     56       1.86       dsl LIBKERN_INLINE u_long ulmax(u_long, u_long) __unused;
     57       1.86       dsl LIBKERN_INLINE u_long ulmin(u_long, u_long) __unused;
     58       1.86       dsl LIBKERN_INLINE int abs(int) __unused;
     59  1.106.2.1       tls LIBKERN_INLINE long labs(long) __unused;
     60  1.106.2.1       tls LIBKERN_INLINE long long llabs(long long) __unused;
     61  1.106.2.1       tls LIBKERN_INLINE intmax_t imaxabs(intmax_t) __unused;
     62       1.86       dsl 
     63       1.86       dsl LIBKERN_INLINE int isspace(int) __unused;
     64       1.86       dsl LIBKERN_INLINE int isascii(int) __unused;
     65       1.86       dsl LIBKERN_INLINE int isupper(int) __unused;
     66       1.86       dsl LIBKERN_INLINE int islower(int) __unused;
     67       1.86       dsl LIBKERN_INLINE int isalpha(int) __unused;
     68  1.106.2.1       tls LIBKERN_INLINE int isalnum(int) __unused;
     69       1.86       dsl LIBKERN_INLINE int isdigit(int) __unused;
     70       1.86       dsl LIBKERN_INLINE int isxdigit(int) __unused;
     71  1.106.2.1       tls LIBKERN_INLINE int iscntrl(int) __unused;
     72  1.106.2.1       tls LIBKERN_INLINE int isgraph(int) __unused;
     73  1.106.2.1       tls LIBKERN_INLINE int isprint(int) __unused;
     74  1.106.2.1       tls LIBKERN_INLINE int ispunct(int) __unused;
     75       1.86       dsl LIBKERN_INLINE int toupper(int) __unused;
     76       1.86       dsl LIBKERN_INLINE int tolower(int) __unused;
     77       1.33   thorpej 
     78        1.7  christos #ifdef LIBKERN_BODY
     79        1.7  christos LIBKERN_INLINE int
     80       1.44      matt imax(int a, int b)
     81        1.1       cgd {
     82        1.1       cgd 	return (a > b ? a : b);
     83        1.1       cgd }
     84        1.7  christos LIBKERN_INLINE int
     85       1.44      matt imin(int a, int b)
     86        1.1       cgd {
     87        1.1       cgd 	return (a < b ? a : b);
     88        1.1       cgd }
     89        1.7  christos LIBKERN_INLINE long
     90       1.44      matt lmax(long a, long b)
     91        1.1       cgd {
     92        1.1       cgd 	return (a > b ? a : b);
     93        1.1       cgd }
     94        1.7  christos LIBKERN_INLINE long
     95       1.44      matt lmin(long a, long b)
     96        1.1       cgd {
     97        1.1       cgd 	return (a < b ? a : b);
     98        1.1       cgd }
     99        1.7  christos LIBKERN_INLINE u_int
    100       1.44      matt max(u_int a, u_int b)
    101        1.1       cgd {
    102        1.1       cgd 	return (a > b ? a : b);
    103        1.1       cgd }
    104        1.7  christos LIBKERN_INLINE u_int
    105       1.44      matt min(u_int a, u_int b)
    106        1.1       cgd {
    107        1.1       cgd 	return (a < b ? a : b);
    108        1.1       cgd }
    109        1.7  christos LIBKERN_INLINE u_long
    110       1.44      matt ulmax(u_long a, u_long b)
    111        1.1       cgd {
    112        1.1       cgd 	return (a > b ? a : b);
    113        1.1       cgd }
    114        1.7  christos LIBKERN_INLINE u_long
    115       1.44      matt ulmin(u_long a, u_long b)
    116        1.1       cgd {
    117        1.1       cgd 	return (a < b ? a : b);
    118        1.5       leo }
    119        1.5       leo 
    120        1.7  christos LIBKERN_INLINE int
    121       1.44      matt abs(int j)
    122        1.5       leo {
    123        1.5       leo 	return(j < 0 ? -j : j);
    124       1.33   thorpej }
    125       1.33   thorpej 
    126  1.106.2.1       tls LIBKERN_INLINE long
    127  1.106.2.1       tls labs(long j)
    128  1.106.2.1       tls {
    129  1.106.2.1       tls 	return(j < 0 ? -j : j);
    130  1.106.2.1       tls }
    131  1.106.2.1       tls 
    132  1.106.2.1       tls LIBKERN_INLINE long long
    133  1.106.2.1       tls llabs(long long j)
    134  1.106.2.1       tls {
    135  1.106.2.1       tls 	return(j < 0 ? -j : j);
    136  1.106.2.1       tls }
    137  1.106.2.1       tls 
    138  1.106.2.1       tls LIBKERN_INLINE intmax_t
    139  1.106.2.1       tls imaxabs(intmax_t j)
    140  1.106.2.1       tls {
    141  1.106.2.1       tls 	return(j < 0 ? -j : j);
    142  1.106.2.1       tls }
    143  1.106.2.1       tls 
    144       1.33   thorpej LIBKERN_INLINE int
    145       1.44      matt isspace(int ch)
    146       1.33   thorpej {
    147       1.33   thorpej 	return (ch == ' ' || (ch >= '\t' && ch <= '\r'));
    148       1.33   thorpej }
    149       1.33   thorpej 
    150       1.33   thorpej LIBKERN_INLINE int
    151       1.44      matt isascii(int ch)
    152       1.33   thorpej {
    153       1.33   thorpej 	return ((ch & ~0x7f) == 0);
    154       1.33   thorpej }
    155       1.33   thorpej 
    156       1.33   thorpej LIBKERN_INLINE int
    157       1.44      matt isupper(int ch)
    158       1.33   thorpej {
    159       1.33   thorpej 	return (ch >= 'A' && ch <= 'Z');
    160       1.33   thorpej }
    161       1.33   thorpej 
    162       1.33   thorpej LIBKERN_INLINE int
    163       1.44      matt islower(int ch)
    164       1.33   thorpej {
    165       1.33   thorpej 	return (ch >= 'a' && ch <= 'z');
    166       1.33   thorpej }
    167       1.33   thorpej 
    168       1.33   thorpej LIBKERN_INLINE int
    169       1.44      matt isalpha(int ch)
    170       1.33   thorpej {
    171       1.33   thorpej 	return (isupper(ch) || islower(ch));
    172       1.33   thorpej }
    173       1.33   thorpej 
    174       1.33   thorpej LIBKERN_INLINE int
    175  1.106.2.1       tls isalnum(int ch)
    176  1.106.2.1       tls {
    177  1.106.2.1       tls 	return (isalpha(ch) || isdigit(ch));
    178  1.106.2.1       tls }
    179  1.106.2.1       tls 
    180  1.106.2.1       tls LIBKERN_INLINE int
    181       1.44      matt isdigit(int ch)
    182       1.33   thorpej {
    183       1.33   thorpej 	return (ch >= '0' && ch <= '9');
    184       1.33   thorpej }
    185       1.33   thorpej 
    186       1.33   thorpej LIBKERN_INLINE int
    187       1.44      matt isxdigit(int ch)
    188       1.33   thorpej {
    189       1.33   thorpej 	return (isdigit(ch) ||
    190       1.33   thorpej 	    (ch >= 'A' && ch <= 'F') ||
    191       1.33   thorpej 	    (ch >= 'a' && ch <= 'f'));
    192       1.33   thorpej }
    193       1.33   thorpej 
    194       1.33   thorpej LIBKERN_INLINE int
    195  1.106.2.1       tls iscntrl(int ch)
    196  1.106.2.1       tls {
    197  1.106.2.1       tls 	return ((ch >= 0x00 && ch <= 0x1F) || ch == 0x7F);
    198  1.106.2.1       tls }
    199  1.106.2.1       tls 
    200  1.106.2.1       tls LIBKERN_INLINE int
    201  1.106.2.1       tls isgraph(int ch)
    202  1.106.2.1       tls {
    203  1.106.2.1       tls 	return (ch != ' ' && isprint(ch));
    204  1.106.2.1       tls }
    205  1.106.2.1       tls 
    206  1.106.2.1       tls LIBKERN_INLINE int
    207  1.106.2.1       tls isprint(int ch)
    208  1.106.2.1       tls {
    209  1.106.2.1       tls 	return (ch >= 0x20 && ch <= 0x7E);
    210  1.106.2.1       tls }
    211  1.106.2.1       tls 
    212  1.106.2.1       tls LIBKERN_INLINE int
    213  1.106.2.1       tls ispunct(int ch)
    214  1.106.2.1       tls {
    215  1.106.2.1       tls 	return (isprint(ch) && ch != ' ' && !isalnum(ch));
    216  1.106.2.1       tls }
    217  1.106.2.1       tls 
    218  1.106.2.1       tls LIBKERN_INLINE int
    219       1.44      matt toupper(int ch)
    220       1.33   thorpej {
    221       1.33   thorpej 	if (islower(ch))
    222       1.33   thorpej 		return (ch - 0x20);
    223       1.33   thorpej 	return (ch);
    224       1.33   thorpej }
    225       1.33   thorpej 
    226       1.33   thorpej LIBKERN_INLINE int
    227       1.44      matt tolower(int ch)
    228       1.33   thorpej {
    229       1.33   thorpej 	if (isupper(ch))
    230       1.33   thorpej 		return (ch + 0x20);
    231       1.33   thorpej 	return (ch);
    232        1.1       cgd }
    233        1.7  christos #endif
    234        1.1       cgd 
    235       1.64      matt #define	__NULL_STMT		do { } while (/* CONSTCOND */ 0)
    236       1.59    dyoung 
    237      1.101       jym #define __KASSERTSTR  "kernel %sassertion \"%s\" failed: file \"%s\", line %d "
    238      1.101       jym 
    239        1.9       cgd #ifdef NDEBUG						/* tradition! */
    240        1.9       cgd #define	assert(e)	((void)0)
    241       1.10       cgd #else
    242       1.30   thorpej #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
    243      1.102  christos 			    kern_assert(__KASSERTSTR, "", #e, __FILE__, __LINE__))
    244        1.9       cgd #endif
    245        1.9       cgd 
    246       1.61  christos #ifdef __COVERITY__
    247       1.61  christos #ifndef DIAGNOSTIC
    248       1.61  christos #define DIAGNOSTIC
    249       1.61  christos #endif
    250       1.61  christos #endif
    251       1.61  christos 
    252  1.106.2.1       tls #ifndef	CTASSERT
    253       1.97      matt #define	CTASSERT(x)		__CTASSERT(x)
    254  1.106.2.1       tls #endif
    255  1.106.2.1       tls #ifndef	CTASSERT_SIGNED
    256      1.105     rmind #define	CTASSERT_SIGNED(x)	__CTASSERT(((typeof(x))-1) < 0)
    257  1.106.2.1       tls #endif
    258  1.106.2.1       tls #ifndef	CTASSERT_UNSIGNED
    259      1.105     rmind #define	CTASSERT_UNSIGNED(x)	__CTASSERT(((typeof(x))-1) >= 0)
    260  1.106.2.1       tls #endif
    261       1.80      matt 
    262       1.61  christos #ifndef DIAGNOSTIC
    263       1.52  christos #define _DIAGASSERT(a)	(void)0
    264       1.34     lukem #ifdef lint
    265      1.101       jym #define	KASSERTMSG(e, msg, ...)	/* NOTHING */
    266       1.81      matt #define	KASSERT(e)		/* NOTHING */
    267       1.34     lukem #else /* !lint */
    268      1.101       jym #define	KASSERTMSG(e, msg, ...)	((void)0)
    269       1.81      matt #define	KASSERT(e)		((void)0)
    270       1.34     lukem #endif /* !lint */
    271       1.61  christos #else /* DIAGNOSTIC */
    272       1.52  christos #define _DIAGASSERT(a)	assert(a)
    273      1.101       jym #define	KASSERTMSG(e, msg, ...)		\
    274      1.101       jym 			(__predict_true((e)) ? (void)0 :		    \
    275      1.102  christos 			    kern_assert(__KASSERTSTR msg, "diagnostic ", #e,	    \
    276      1.101       jym 				__FILE__, __LINE__, ## __VA_ARGS__))
    277      1.101       jym 
    278       1.30   thorpej #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    279      1.102  christos 			    kern_assert(__KASSERTSTR, "diagnostic ", #e,	    \
    280      1.101       jym 				__FILE__, __LINE__))
    281        1.9       cgd #endif
    282        1.9       cgd 
    283        1.9       cgd #ifndef DEBUG
    284       1.34     lukem #ifdef lint
    285      1.101       jym #define	KDASSERTMSG(e,msg, ...)	/* NOTHING */
    286       1.96      matt #define	KDASSERT(e)		/* NOTHING */
    287       1.34     lukem #else /* lint */
    288      1.101       jym #define	KDASSERTMSG(e,msg, ...)	((void)0)
    289       1.96      matt #define	KDASSERT(e)		((void)0)
    290       1.34     lukem #endif /* lint */
    291        1.9       cgd #else
    292      1.101       jym #define	KDASSERTMSG(e, msg, ...)	\
    293      1.101       jym 			(__predict_true((e)) ? (void)0 :		    \
    294      1.102  christos 			    kern_assert(__KASSERTSTR msg, "debugging ", #e,	    \
    295      1.101       jym 				__FILE__, __LINE__, ## __VA_ARGS__))
    296      1.101       jym 
    297       1.30   thorpej #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    298      1.102  christos 			    kern_assert(__KASSERTSTR, "debugging ", #e,	    \
    299      1.101       jym 				__FILE__, __LINE__))
    300        1.9       cgd #endif
    301      1.101       jym 
    302       1.53  christos /*
    303       1.53  christos  * XXX: For compatibility we use SMALL_RANDOM by default.
    304       1.53  christos  */
    305       1.53  christos #define SMALL_RANDOM
    306       1.19   thorpej 
    307       1.31   msaitoh #ifndef offsetof
    308       1.98      matt #if __GNUC_PREREQ__(4, 0)
    309       1.98      matt #define offsetof(type, member)	__builtin_offsetof(type, member)
    310       1.98      matt #else
    311       1.47  christos #define	offsetof(type, member) \
    312       1.47  christos     ((size_t)(unsigned long)(&(((type *)0)->member)))
    313       1.31   msaitoh #endif
    314       1.98      matt #endif
    315        1.9       cgd 
    316  1.106.2.2  jdolecek /*
    317  1.106.2.2  jdolecek  * Return the container of an embedded struct.  Given x = &c->f,
    318  1.106.2.2  jdolecek  * container_of(x, T, f) yields c, where T is the type of c.  Example:
    319  1.106.2.2  jdolecek  *
    320  1.106.2.2  jdolecek  *	struct foo { ... };
    321  1.106.2.2  jdolecek  *	struct bar {
    322  1.106.2.2  jdolecek  *		int b_x;
    323  1.106.2.2  jdolecek  *		struct foo b_foo;
    324  1.106.2.2  jdolecek  *		...
    325  1.106.2.2  jdolecek  *	};
    326  1.106.2.2  jdolecek  *
    327  1.106.2.2  jdolecek  *	struct bar b;
    328  1.106.2.2  jdolecek  *	struct foo *fp = b.b_foo;
    329  1.106.2.2  jdolecek  *
    330  1.106.2.2  jdolecek  * Now we can get at b from fp by:
    331  1.106.2.2  jdolecek  *
    332  1.106.2.2  jdolecek  *	struct bar *bp = container_of(fp, struct bar, b_foo);
    333  1.106.2.2  jdolecek  *
    334  1.106.2.2  jdolecek  * The 0*sizeof((PTR) - ...) causes the compiler to warn if the type of
    335  1.106.2.2  jdolecek  * *fp does not match the type of struct bar::b_foo.
    336  1.106.2.2  jdolecek  * We skip the validation for coverity runs to avoid warnings.
    337  1.106.2.2  jdolecek  */
    338  1.106.2.2  jdolecek #ifdef __COVERITY__
    339  1.106.2.2  jdolecek #define __validate_container_of(PTR, TYPE, FIELD) 0
    340  1.106.2.2  jdolecek #define __validate_const_container_of(PTR, TYPE, FIELD) 0
    341  1.106.2.2  jdolecek #else
    342  1.106.2.2  jdolecek #define __validate_container_of(PTR, TYPE, FIELD)			\
    343  1.106.2.2  jdolecek     (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) -			\
    344  1.106.2.2  jdolecek     offsetof(TYPE, FIELD)))->FIELD))
    345  1.106.2.2  jdolecek #define __validate_const_container_of(PTR, TYPE, FIELD)			\
    346  1.106.2.2  jdolecek     (0 * sizeof((PTR) - &((const TYPE *)(((const char *)(PTR)) -	\
    347  1.106.2.2  jdolecek     offsetof(TYPE, FIELD)))->FIELD))
    348  1.106.2.2  jdolecek #endif
    349  1.106.2.2  jdolecek 
    350  1.106.2.2  jdolecek #define	container_of(PTR, TYPE, FIELD)					\
    351  1.106.2.2  jdolecek     ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD))			\
    352  1.106.2.2  jdolecek 	+ __validate_container_of(PTR, TYPE, FIELD))
    353  1.106.2.2  jdolecek #define	const_container_of(PTR, TYPE, FIELD)				\
    354  1.106.2.2  jdolecek     ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD))	\
    355  1.106.2.2  jdolecek 	+ __validate_const_container_of(PTR, TYPE, FIELD))
    356  1.106.2.2  jdolecek 
    357       1.73      matt #define	MTPRNG_RLEN		624
    358       1.73      matt struct mtprng_state {
    359  1.106.2.2  jdolecek 	unsigned int mt_idx;
    360       1.73      matt 	uint32_t mt_elem[MTPRNG_RLEN];
    361       1.75      matt 	uint32_t mt_count;
    362       1.74      matt 	uint32_t mt_sparse[3];
    363       1.73      matt };
    364       1.73      matt 
    365       1.38   thorpej /* Prototypes for which GCC built-ins exist. */
    366       1.86       dsl void	*memcpy(void *, const void *, size_t);
    367       1.86       dsl int	 memcmp(const void *, const void *, size_t);
    368       1.86       dsl void	*memset(void *, int, size_t);
    369      1.103       chs #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE)
    370       1.38   thorpej #define	memcpy(d, s, l)		__builtin_memcpy(d, s, l)
    371       1.38   thorpej #define	memcmp(a, b, l)		__builtin_memcmp(a, b, l)
    372       1.63      matt #endif
    373      1.103       chs #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE)
    374       1.38   thorpej #define	memset(d, v, l)		__builtin_memset(d, v, l)
    375       1.38   thorpej #endif
    376       1.38   thorpej 
    377       1.86       dsl char	*strcpy(char *, const char *);
    378       1.86       dsl int	 strcmp(const char *, const char *);
    379       1.86       dsl size_t	 strlen(const char *);
    380       1.99       jym size_t	 strnlen(const char *, size_t);
    381       1.56    dyoung char	*strsep(char **, const char *);
    382       1.88   tsutsui #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE)
    383       1.38   thorpej #define	strcpy(d, s)		__builtin_strcpy(d, s)
    384       1.38   thorpej #define	strcmp(a, b)		__builtin_strcmp(a, b)
    385       1.38   thorpej #define	strlen(a)		__builtin_strlen(a)
    386       1.39   thorpej #endif
    387       1.39   thorpej 
    388       1.39   thorpej /* Functions for which we always use built-ins. */
    389       1.39   thorpej #ifdef __GNUC__
    390       1.39   thorpej #define	alloca(s)		__builtin_alloca(s)
    391       1.38   thorpej #endif
    392       1.38   thorpej 
    393       1.38   thorpej /* These exist in GCC 3.x, but we don't bother. */
    394       1.86       dsl char	*strcat(char *, const char *);
    395  1.106.2.1       tls size_t	 strcspn(const char *, const char *);
    396       1.86       dsl char	*strncpy(char *, const char *, size_t);
    397  1.106.2.1       tls char	*strncat(char *, const char *, size_t);
    398       1.86       dsl int	 strncmp(const char *, const char *, size_t);
    399       1.86       dsl char	*strchr(const char *, int);
    400       1.86       dsl char	*strrchr(const char *, int);
    401       1.86       dsl char	*strstr(const char *, const char *);
    402  1.106.2.1       tls char	*strpbrk(const char *, const char *);
    403  1.106.2.1       tls size_t	 strspn(const char *, const char *);
    404       1.38   thorpej 
    405       1.42     ragge /*
    406       1.42     ragge  * ffs is an instruction on vax.
    407       1.42     ragge  */
    408       1.86       dsl int	 ffs(int);
    409       1.69      matt #if __GNUC_PREREQ__(2, 95) && (!defined(__vax__) || __GNUC_PREREQ__(4,1))
    410       1.63      matt #define	ffs(x)		__builtin_ffs(x)
    411       1.41   thorpej #endif
    412       1.38   thorpej 
    413      1.102  christos void	 kern_assert(const char *, ...)
    414      1.102  christos     __attribute__((__format__(__printf__, 1, 2)));
    415       1.28    simonb u_int32_t
    416       1.86       dsl 	inet_addr(const char *);
    417       1.52  christos struct in_addr;
    418       1.86       dsl int	inet_aton(const char *, struct in_addr *);
    419       1.86       dsl char	*intoa(u_int32_t);
    420       1.28    simonb #define inet_ntoa(a) intoa((a).s_addr)
    421       1.86       dsl void	*memchr(const void *, int, size_t);
    422       1.86       dsl void	*memmove(void *, const void *, size_t);
    423       1.86       dsl int	 pmatch(const char *, const char *, const char **);
    424       1.53  christos #ifndef SMALL_RANDOM
    425       1.86       dsl void	 srandom(unsigned long);
    426       1.86       dsl char	*initstate(unsigned long, char *, size_t);
    427       1.86       dsl char	*setstate(char *);
    428       1.53  christos #endif /* SMALL_RANDOM */
    429       1.86       dsl long	 random(void);
    430  1.106.2.1       tls void	 mi_vector_hash(const void * __restrict, size_t, uint32_t,
    431  1.106.2.1       tls 	    uint32_t[3]);
    432       1.74      matt void	 mtprng_init32(struct mtprng_state *, uint32_t);
    433       1.74      matt void	 mtprng_initarray(struct mtprng_state *, const uint32_t *, size_t);
    434       1.74      matt uint32_t mtprng_rawrandom(struct mtprng_state *);
    435       1.74      matt uint32_t mtprng_random(struct mtprng_state *);
    436       1.86       dsl int	 scanc(u_int, const u_char *, const u_char *, int);
    437       1.86       dsl int	 skpc(int, size_t, u_char *);
    438       1.86       dsl int	 strcasecmp(const char *, const char *);
    439       1.86       dsl size_t	 strlcpy(char *, const char *, size_t);
    440       1.86       dsl size_t	 strlcat(char *, const char *, size_t);
    441       1.86       dsl int	 strncasecmp(const char *, const char *, size_t);
    442       1.86       dsl u_long	 strtoul(const char *, char **, int);
    443       1.86       dsl long long strtoll(const char *, char **, int);
    444       1.86       dsl unsigned long long strtoull(const char *, char **, int);
    445  1.106.2.1       tls intmax_t  strtoimax(const char *, char **, int);
    446       1.86       dsl uintmax_t strtoumax(const char *, char **, int);
    447  1.106.2.2  jdolecek intmax_t strtoi(const char * __restrict, char ** __restrict, int, intmax_t,
    448  1.106.2.2  jdolecek     intmax_t, int *);
    449  1.106.2.2  jdolecek uintmax_t strtou(const char * __restrict, char ** __restrict, int, uintmax_t,
    450  1.106.2.2  jdolecek     uintmax_t, int *);
    451  1.106.2.2  jdolecek 
    452       1.86       dsl int	 snprintb(char *, size_t, const char *, uint64_t);
    453       1.91  pgoyette int	 snprintb_m(char *, size_t, const char *, uint64_t, size_t);
    454       1.84        ad int	 kheapsort(void *, size_t, size_t, int (*)(const void *, const void *),
    455       1.84        ad 		   void *);
    456       1.90       tls uint32_t crc32(uint32_t, const uint8_t *, size_t);
    457  1.106.2.2  jdolecek #if __GNUC_PREREQ__(4, 5) \
    458  1.106.2.2  jdolecek     && (defined(__alpha_cix__) || defined(__mips_popcount))
    459  1.106.2.2  jdolecek #define	popcount	__builtin_popcount
    460  1.106.2.2  jdolecek #define	popcountl	__builtin_popcountl
    461  1.106.2.2  jdolecek #define	popcountll	__builtin_popcountll
    462  1.106.2.2  jdolecek #define	popcount32	__builtin_popcount
    463  1.106.2.2  jdolecek #define	popcount64	__builtin_popcountll
    464  1.106.2.2  jdolecek #else
    465       1.92     joerg unsigned int	popcount(unsigned int) __constfunc;
    466       1.92     joerg unsigned int	popcountl(unsigned long) __constfunc;
    467       1.92     joerg unsigned int	popcountll(unsigned long long) __constfunc;
    468       1.92     joerg unsigned int	popcount32(uint32_t) __constfunc;
    469       1.92     joerg unsigned int	popcount64(uint64_t) __constfunc;
    470  1.106.2.2  jdolecek #endif
    471      1.106  drochner 
    472  1.106.2.1       tls void	*explicit_memset(void *, int, size_t);
    473  1.106.2.1       tls int	consttime_memequal(const void *, const void *, size_t);
    474  1.106.2.2  jdolecek int	strnvisx(char *, size_t, const char *, size_t, int);
    475  1.106.2.2  jdolecek #define VIS_OCTAL	0x01
    476  1.106.2.2  jdolecek #define VIS_SAFE	0x20
    477  1.106.2.2  jdolecek #define VIS_TRIM	0x40
    478  1.106.2.1       tls 
    479  1.106.2.1       tls #ifdef notyet
    480  1.106.2.1       tls /*
    481  1.106.2.1       tls  * LZF hashtable/state size: on uncompressible data and on a system with
    482  1.106.2.1       tls  * a sufficiently large d-cache, a larger table produces a considerable
    483  1.106.2.1       tls  * speed benefit.  On systems with small memory and caches, however...
    484  1.106.2.1       tls  */
    485  1.106.2.1       tls #if defined(__vax__) || defined(__m68k__)
    486  1.106.2.1       tls #define LZF_HLOG 14
    487  1.106.2.1       tls #else
    488  1.106.2.1       tls #define LZF_HLOG 15
    489  1.106.2.1       tls #endif
    490  1.106.2.1       tls typedef const uint8_t *LZF_STATE[1 << LZF_HLOG];
    491  1.106.2.1       tls 
    492  1.106.2.1       tls unsigned int lzf_compress_r (const void *const, unsigned int, void *,
    493  1.106.2.1       tls 			     unsigned int, LZF_STATE);
    494  1.106.2.1       tls unsigned int lzf_decompress (const void *const, unsigned int, void *,
    495  1.106.2.1       tls 			     unsigned int);
    496  1.106.2.1       tls #endif
    497  1.106.2.1       tls 
    498       1.29    simonb #endif /* !_LIB_LIBKERN_LIBKERN_H_ */
    499