source: rtems-libbsd/freebsd/sys/sys/libkern.h @ 524990c

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 524990c was 524990c, checked in by Sebastian Huber <sebastian.huber@…>, on 10/30/15 at 13:14:46

Provide ffs() and ffsl() via builtins

  • Property mode set to 100644
File size: 7.0 KB
Line 
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 <rtems/bsd/sys/types.h>
38#ifdef _KERNEL
39#include <sys/systm.h>
40#endif
41
42#ifndef __rtems__
43#ifndef LIBKERN_INLINE
44#define LIBKERN_INLINE  static __inline
45#define LIBKERN_BODY
46#endif
47#else /* __rtems__ */
48#define LIBKERN_INLINE
49#endif /* __rtems__ */
50
51/* BCD conversions. */
52extern u_char const     bcd2bin_data[];
53extern u_char const     bin2bcd_data[];
54extern char const       hex2ascii_data[];
55
56#define bcd2bin(bcd)    (bcd2bin_data[bcd])
57#define bin2bcd(bin)    (bin2bcd_data[bin])
58#define hex2ascii(hex)  (hex2ascii_data[hex])
59
60static __inline int imax(int a, int b) { return (a > b ? a : b); }
61static __inline int imin(int a, int b) { return (a < b ? a : b); }
62static __inline long lmax(long a, long b) { return (a > b ? a : b); }
63static __inline long lmin(long a, long b) { return (a < b ? a : b); }
64static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
65static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
66static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
67static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
68static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
69static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
70static __inline off_t omax(off_t a, off_t b) { return (a > b ? a : b); }
71static __inline off_t omin(off_t a, off_t b) { return (a < b ? a : b); }
72
73#ifndef __rtems__
74static __inline int abs(int a) { return (a < 0 ? -a : a); }
75static __inline long labs(long a) { return (a < 0 ? -a : a); }
76#endif /* __rtems__ */
77static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); }
78
79#define ARC4_ENTR_NONE  0       /* Don't have entropy yet. */
80#define ARC4_ENTR_HAVE  1       /* Have entropy. */
81#define ARC4_ENTR_SEED  2       /* Reseeding. */
82extern int arc4rand_iniseed_state;
83
84/* Prototypes for non-quad routines. */
85struct malloc_type;
86uint32_t arc4random(void);
87void     arc4rand(void *ptr, u_int len, int reseed);
88int      bcmp(const void *, const void *, size_t);
89void    *bsearch(const void *, const void *, size_t,
90            size_t, int (*)(const void *, const void *));
91#ifndef __rtems__
92#ifndef HAVE_INLINE_FFS
93int      ffs(int);
94#endif
95#ifndef HAVE_INLINE_FFSL
96int      ffsl(long);
97#endif
98#else /* __rtems__ */
99#define ffs(_x) __builtin_ffs((unsigned int)(_x))
100#define ffsl(_x) __builtin_ffsl((unsigned long)(_x))
101#endif /* __rtems__ */
102#ifndef HAVE_INLINE_FLS
103int      fls(int);
104#endif
105#ifndef HAVE_INLINE_FLSL
106int      flsl(long);
107#endif
108int      fnmatch(const char *, const char *, int);
109int      locc(int, char *, u_int);
110void    *memchr(const void *s, int c, size_t n);
111int      memcmp(const void *b1, const void *b2, size_t len);
112void     qsort(void *base, size_t nmemb, size_t size,
113            int (*compar)(const void *, const void *));
114void     qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
115            int (*compar)(void *, const void *, const void *));
116u_long   random(void);
117char    *index(const char *, int);
118char    *rindex(const char *, int);
119int      scanc(u_int, const u_char *, const u_char *, int);
120int      skpc(int, int, char *);
121void     srandom(u_long);
122int      strcasecmp(const char *, const char *);
123char    *strcat(char * __restrict, const char * __restrict);
124int      strcmp(const char *, const char *);
125char    *strcpy(char * __restrict, const char * __restrict);
126size_t   strcspn(const char * __restrict, const char * __restrict) __pure;
127#ifdef __rtems__
128#include <string.h>
129#define strdup _bsd_strdup
130#endif /* __rtems__ */
131char    *strdup(const char *__restrict, struct malloc_type *);
132size_t   strlcat(char *, const char *, size_t);
133size_t   strlcpy(char *, const char *, size_t);
134size_t   strlen(const char *);
135int      strncasecmp(const char *, const char *, size_t);
136int      strncmp(const char *, const char *, size_t);
137char    *strncpy(char * __restrict, const char * __restrict, size_t);
138size_t   strnlen(const char *, size_t);
139char    *strsep(char **, const char *delim);
140size_t   strspn(const char *, const char *);
141char    *strstr(const char *, const char *);
142int      strvalid(const char *, size_t);
143
144extern uint32_t crc32_tab[];
145
146static __inline uint32_t
147crc32_raw(const void *buf, size_t size, uint32_t crc)
148{
149        const uint8_t *p = (const uint8_t *)buf;
150
151        while (size--)
152                crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
153        return (crc);
154}
155
156static __inline uint32_t
157crc32(const void *buf, size_t size)
158{
159        uint32_t crc;
160
161        crc = crc32_raw(buf, size, ~0U);
162        return (crc ^ ~0U);
163}
164
165uint32_t
166calculate_crc32c(uint32_t crc32c, const unsigned char *buffer,
167        unsigned int length);
168
169
170LIBKERN_INLINE void *memset(void *, int, size_t);
171#ifdef LIBKERN_BODY
172LIBKERN_INLINE void *
173memset(void *b, int c, size_t len)
174{
175        char *bb;
176
177        if (c == 0)
178                bzero(b, len);
179        else
180                for (bb = (char *)b; len--; )
181                        *bb++ = c;
182        return (b);
183}
184#endif
185
186#ifndef __rtems__
187static __inline char *
188strchr(const char *p, int ch)
189{
190        return (index(p, ch));
191}
192
193static __inline char *
194strrchr(const char *p, int ch)
195{
196        return (rindex(p, ch));
197}
198#endif /* __rtems__ */
199
200/* fnmatch() return values. */
201#define FNM_NOMATCH     1       /* Match failed. */
202
203/* fnmatch() flags. */
204#define FNM_NOESCAPE    0x01    /* Disable backslash escaping. */
205#define FNM_PATHNAME    0x02    /* Slash must be matched by slash. */
206#define FNM_PERIOD      0x04    /* Period must be matched by period. */
207#define FNM_LEADING_DIR 0x08    /* Ignore /<tail> after Imatch. */
208#define FNM_CASEFOLD    0x10    /* Case insensitive search. */
209#define FNM_IGNORECASE  FNM_CASEFOLD
210#define FNM_FILE_NAME   FNM_PATHNAME
211
212#endif /* !_SYS_LIBKERN_H_ */
Note: See TracBrowser for help on using the repository browser.