The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/libkern.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1992, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 4. Neither the name of the University nor the names of its contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  *      @(#)libkern.h   8.1 (Berkeley) 6/10/93
   30  * $FreeBSD: releng/11.0/sys/sys/libkern.h 298714 2016-04-27 19:09:21Z jkim $
   31  */
   32 
   33 #ifndef _SYS_LIBKERN_H_
   34 #define _SYS_LIBKERN_H_
   35 
   36 #include <sys/cdefs.h>
   37 #include <sys/types.h>
   38 #ifdef _KERNEL
   39 #include <sys/systm.h>
   40 #endif
   41 
   42 #ifndef LIBKERN_INLINE
   43 #define LIBKERN_INLINE  static __inline
   44 #define LIBKERN_BODY
   45 #endif
   46 
   47 /* BCD conversions. */
   48 extern u_char const     bcd2bin_data[];
   49 extern u_char const     bin2bcd_data[];
   50 extern char const       hex2ascii_data[];
   51 
   52 #define bcd2bin(bcd)    (bcd2bin_data[bcd])
   53 #define bin2bcd(bin)    (bin2bcd_data[bin])
   54 #define hex2ascii(hex)  (hex2ascii_data[hex])
   55 
   56 static __inline int imax(int a, int b) { return (a > b ? a : b); }
   57 static __inline int imin(int a, int b) { return (a < b ? a : b); }
   58 static __inline long lmax(long a, long b) { return (a > b ? a : b); }
   59 static __inline long lmin(long a, long b) { return (a < b ? a : b); }
   60 static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
   61 static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
   62 static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
   63 static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
   64 static __inline u_quad_t uqmax(u_quad_t a, u_quad_t b) { return (a > b ? a : b); }
   65 static __inline u_quad_t uqmin(u_quad_t a, u_quad_t b) { return (a < b ? a : b); }
   66 static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
   67 static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
   68 static __inline __uintmax_t ummax(__uintmax_t a, __uintmax_t b)
   69 {
   70 
   71         return (a > b ? a : b);
   72 }
   73 static __inline __uintmax_t ummin(__uintmax_t a, __uintmax_t b)
   74 {
   75 
   76         return (a < b ? a : b);
   77 }
   78 static __inline off_t omax(off_t a, off_t b) { return (a > b ? a : b); }
   79 static __inline off_t omin(off_t a, off_t b) { return (a < b ? a : b); }
   80 
   81 static __inline int abs(int a) { return (a < 0 ? -a : a); }
   82 static __inline long labs(long a) { return (a < 0 ? -a : a); }
   83 static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); }
   84 
   85 #define ARC4_ENTR_NONE  0       /* Don't have entropy yet. */
   86 #define ARC4_ENTR_HAVE  1       /* Have entropy. */
   87 #define ARC4_ENTR_SEED  2       /* Reseeding. */
   88 extern int arc4rand_iniseed_state;
   89 
   90 /* Prototypes for non-quad routines. */
   91 struct malloc_type;
   92 uint32_t arc4random(void);
   93 void     arc4rand(void *ptr, u_int len, int reseed);
   94 int      bcmp(const void *, const void *, size_t);
   95 int      timingsafe_bcmp(const void *, const void *, size_t);
   96 void    *bsearch(const void *, const void *, size_t,
   97             size_t, int (*)(const void *, const void *));
   98 #ifndef HAVE_INLINE_FFS
   99 int      ffs(int);
  100 #endif
  101 #ifndef HAVE_INLINE_FFSL
  102 int      ffsl(long);
  103 #endif
  104 #ifndef HAVE_INLINE_FFSLL
  105 int      ffsll(long long);
  106 #endif
  107 #ifndef HAVE_INLINE_FLS
  108 int      fls(int);
  109 #endif
  110 #ifndef HAVE_INLINE_FLSL
  111 int      flsl(long);
  112 #endif
  113 #ifndef HAVE_INLINE_FLSLL
  114 int      flsll(long long);
  115 #endif
  116 #define bitcount64(x)   __bitcount64((uint64_t)(x))
  117 #define bitcount32(x)   __bitcount32((uint32_t)(x))
  118 #define bitcount16(x)   __bitcount16((uint16_t)(x))
  119 #define bitcountl(x)    __bitcountl((u_long)(x))
  120 #define bitcount(x)     __bitcount((u_int)(x))
  121 
  122 int      fnmatch(const char *, const char *, int);
  123 int      locc(int, char *, u_int);
  124 void    *memchr(const void *s, int c, size_t n);
  125 void    *memcchr(const void *s, int c, size_t n);
  126 int      memcmp(const void *b1, const void *b2, size_t len);
  127 void    *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
  128 void     qsort(void *base, size_t nmemb, size_t size,
  129             int (*compar)(const void *, const void *));
  130 void     qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
  131             int (*compar)(void *, const void *, const void *));
  132 u_long   random(void);
  133 int      scanc(u_int, const u_char *, const u_char *, int);
  134 void     srandom(u_long);
  135 int      strcasecmp(const char *, const char *);
  136 char    *strcat(char * __restrict, const char * __restrict);
  137 char    *strchr(const char *, int);
  138 int      strcmp(const char *, const char *);
  139 char    *strcpy(char * __restrict, const char * __restrict);
  140 size_t   strcspn(const char * __restrict, const char * __restrict) __pure;
  141 char    *strdup(const char *__restrict, struct malloc_type *);
  142 char    *strncat(char *, const char *, size_t);
  143 char    *strndup(const char *__restrict, size_t, struct malloc_type *);
  144 size_t   strlcat(char *, const char *, size_t);
  145 size_t   strlcpy(char *, const char *, size_t);
  146 size_t   strlen(const char *);
  147 int      strncasecmp(const char *, const char *, size_t);
  148 int      strncmp(const char *, const char *, size_t);
  149 char    *strncpy(char * __restrict, const char * __restrict, size_t);
  150 size_t   strnlen(const char *, size_t);
  151 char    *strrchr(const char *, int);
  152 char    *strsep(char **, const char *delim);
  153 size_t   strspn(const char *, const char *);
  154 char    *strstr(const char *, const char *);
  155 int      strvalid(const char *, size_t);
  156 
  157 extern const uint32_t crc32_tab[];
  158 
  159 static __inline uint32_t
  160 crc32_raw(const void *buf, size_t size, uint32_t crc)
  161 {
  162         const uint8_t *p = (const uint8_t *)buf;
  163 
  164         while (size--)
  165                 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
  166         return (crc);
  167 }
  168 
  169 static __inline uint32_t
  170 crc32(const void *buf, size_t size)
  171 {
  172         uint32_t crc;
  173 
  174         crc = crc32_raw(buf, size, ~0U);
  175         return (crc ^ ~0U);
  176 }
  177 
  178 uint32_t
  179 calculate_crc32c(uint32_t crc32c, const unsigned char *buffer,
  180     unsigned int length);
  181 
  182 
  183 LIBKERN_INLINE void *memset(void *, int, size_t);
  184 #ifdef LIBKERN_BODY
  185 LIBKERN_INLINE void *
  186 memset(void *b, int c, size_t len)
  187 {
  188         char *bb;
  189 
  190         if (c == 0)
  191                 bzero(b, len);
  192         else
  193                 for (bb = (char *)b; len--; )
  194                         *bb++ = c;
  195         return (b);
  196 }
  197 #endif
  198 
  199 static __inline char *
  200 index(const char *p, int ch)
  201 {
  202 
  203         return (strchr(p, ch));
  204 }
  205 
  206 static __inline char *
  207 rindex(const char *p, int ch)
  208 {
  209 
  210         return (strrchr(p, ch));
  211 }
  212 
  213 /* fnmatch() return values. */
  214 #define FNM_NOMATCH     1       /* Match failed. */
  215 
  216 /* fnmatch() flags. */
  217 #define FNM_NOESCAPE    0x01    /* Disable backslash escaping. */
  218 #define FNM_PATHNAME    0x02    /* Slash must be matched by slash. */
  219 #define FNM_PERIOD      0x04    /* Period must be matched by period. */
  220 #define FNM_LEADING_DIR 0x08    /* Ignore /<tail> after Imatch. */
  221 #define FNM_CASEFOLD    0x10    /* Case insensitive search. */
  222 #define FNM_IGNORECASE  FNM_CASEFOLD
  223 #define FNM_FILE_NAME   FNM_PATHNAME
  224 
  225 #endif /* !_SYS_LIBKERN_H_ */

Cache object: 70c032e3a2bc8ffd9110071dadfa93f5


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.