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-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
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$
   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 /* BCD conversions. */
   43 extern u_char const     bcd2bin_data[];
   44 extern u_char const     bin2bcd_data[];
   45 extern char const       hex2ascii_data[];
   46 
   47 #define bcd2bin(bcd)    (bcd2bin_data[bcd])
   48 #define bin2bcd(bin)    (bin2bcd_data[bin])
   49 #define hex2ascii(hex)  (hex2ascii_data[hex])
   50 
   51 static __inline int imax(int a, int b) { return (a > b ? a : b); }
   52 static __inline int imin(int a, int b) { return (a < b ? a : b); }
   53 static __inline long lmax(long a, long b) { return (a > b ? a : b); }
   54 static __inline long lmin(long a, long b) { return (a < b ? a : b); }
   55 static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
   56 static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
   57 static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
   58 static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
   59 static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
   60 static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
   61 
   62 static __inline int abs(int a) { return (a < 0 ? -a : a); }
   63 static __inline long labs(long a) { return (a < 0 ? -a : a); }
   64 static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); }
   65 
   66 /* Prototypes for non-quad routines. */
   67 struct malloc_type;
   68 uint32_t arc4random(void);
   69 void     arc4rand(void *ptr, u_int len, int reseed);
   70 int      bcmp(const void *, const void *, size_t);
   71 void    *bsearch(const void *, const void *, size_t,
   72             size_t, int (*)(const void *, const void *));
   73 #ifndef HAVE_INLINE_FFS
   74 int      ffs(int);
   75 #endif
   76 #ifndef HAVE_INLINE_FFSL
   77 int      ffsl(long);
   78 #endif
   79 #ifndef HAVE_INLINE_FLS
   80 int      fls(int);
   81 #endif
   82 #ifndef HAVE_INLINE_FLSL
   83 int      flsl(long);
   84 #endif
   85 int      fnmatch(const char *, const char *, int);
   86 void     gets(char *, size_t, int);
   87 int      locc(int, char *, u_int);
   88 void     qsort(void *base, size_t nmemb, size_t size,
   89             int (*compar)(const void *, const void *));
   90 void     qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
   91             int (*compar)(void *, const void *, const void *));
   92 u_long   random(void);
   93 char    *index(const char *, int);
   94 char    *rindex(const char *, int);
   95 int      scanc(u_int, const u_char *, const u_char *, int);
   96 int      skpc(int, int, char *);
   97 void     srandom(u_long);
   98 int      strcasecmp(const char *, const char *);
   99 char    *strcat(char * __restrict, const char * __restrict);
  100 int      strcmp(const char *, const char *);
  101 char    *strcpy(char * __restrict, const char * __restrict);
  102 char    *strdup(const char *__restrict, struct malloc_type *);
  103 size_t   strlcat(char *, const char *, size_t);
  104 size_t   strlcpy(char *, const char *, size_t);
  105 size_t   strlen(const char *);
  106 int      strncasecmp(const char *, const char *, size_t);
  107 int      strncmp(const char *, const char *, size_t);
  108 char    *strncpy(char * __restrict, const char * __restrict, size_t);
  109 char    *strsep(char **, const char *delim);
  110 size_t   strspn(const char *, const char *);
  111 char    *strstr(const char *, const char *);
  112 int      strvalid(const char *, size_t);
  113 
  114 extern uint32_t crc32_tab[];
  115 
  116 static __inline uint32_t
  117 crc32_raw(const void *buf, size_t size, uint32_t crc)
  118 {
  119         const uint8_t *p = buf;
  120 
  121         while (size--)
  122                 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
  123         return (crc);
  124 }
  125 
  126 static __inline uint32_t
  127 crc32(const void *buf, size_t size)
  128 {
  129         uint32_t crc;
  130 
  131         crc = crc32_raw(buf, size, ~0U);
  132         return (crc ^ ~0U);
  133 }
  134 
  135 static __inline int
  136 memcmp(const void *b1, const void *b2, size_t len)
  137 {
  138         return (bcmp(b1, b2, len));
  139 }
  140 
  141 static __inline void *
  142 memset(void *b, int c, size_t len)
  143 {
  144         char *bb;
  145 
  146         if (c == 0)
  147                 bzero(b, len);
  148         else
  149                 for (bb = (char *)b; len--; )
  150                         *bb++ = c;
  151         return (b);
  152 }
  153 
  154 /* fnmatch() return values. */
  155 #define FNM_NOMATCH     1       /* Match failed. */
  156 
  157 /* fnmatch() flags. */
  158 #define FNM_NOESCAPE    0x01    /* Disable backslash escaping. */
  159 #define FNM_PATHNAME    0x02    /* Slash must be matched by slash. */
  160 #define FNM_PERIOD      0x04    /* Period must be matched by period. */
  161 #define FNM_LEADING_DIR 0x08    /* Ignore /<tail> after Imatch. */
  162 #define FNM_CASEFOLD    0x10    /* Case insensitive search. */
  163 #define FNM_IGNORECASE  FNM_CASEFOLD
  164 #define FNM_FILE_NAME   FNM_PATHNAME
  165 
  166 #endif /* !_SYS_LIBKERN_H_ */

Cache object: b26e84d7c4406f0147c5a145aff18a8f


[ 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.