The Pedigree Project 0.1
def.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
25/*
26 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without modification,
30 * are permitted provided that the following conditions are met:
31 *
32 * 1. Redistributions of source code must retain the above copyright notice,
33 * this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 * 3. The name of the author may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49 * OF SUCH DAMAGE.
50 *
51 * This file is part of the lwIP TCP/IP stack.
52 *
53 * Author: Adam Dunkels <adam@sics.se>
54 *
55 */
56#ifndef LWIP_HDR_DEF_H
57#define LWIP_HDR_DEF_H
58
59/* arch.h might define NULL already */
60#include "lwip/arch.h"
61#include "lwip/opt.h"
62#if LWIP_PERF
63#include "arch/perf.h"
64#else /* LWIP_PERF */
65#define PERF_START /* null definition */
66#define PERF_STOP(x) /* null definition */
67#endif /* LWIP_PERF */
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
74#define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
75
76/* Get the number of entries in an array ('x' must NOT be a pointer!) */
77#define LWIP_ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0]))
78
80#define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \
81 ((u32_t)((b) & 0xff) << 16) | \
82 ((u32_t)((c) & 0xff) << 8) | \
83 (u32_t)((d) & 0xff))
84
85#ifndef NULL
86#ifdef __cplusplus
87#define NULL 0
88#else
89#define NULL ((void *)0)
90#endif
91#endif
92
93#if BYTE_ORDER == BIG_ENDIAN
94#define lwip_htons(x) (x)
95#define lwip_ntohs(x) (x)
96#define lwip_htonl(x) (x)
97#define lwip_ntohl(x) (x)
98#define PP_HTONS(x) (x)
99#define PP_NTOHS(x) (x)
100#define PP_HTONL(x) (x)
101#define PP_NTOHL(x) (x)
102#else /* BYTE_ORDER != BIG_ENDIAN */
103#ifndef lwip_htons
104u16_t lwip_htons(u16_t x);
105#endif
106#define lwip_ntohs(x) lwip_htons(x)
107
108#ifndef lwip_htonl
109u32_t lwip_htonl(u32_t x);
110#endif
111#define lwip_ntohl(x) lwip_htonl(x)
112
113/* Provide usual function names as macros for users, but this can be turned off */
114#ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
115#define htons(x) lwip_htons(x)
116#define ntohs(x) lwip_ntohs(x)
117#define htonl(x) lwip_htonl(x)
118#define ntohl(x) lwip_ntohl(x)
119#endif
120
121/* These macros should be calculated by the preprocessor and are used
122 with compile-time constants only (so that there is no little-endian
123 overhead at runtime). */
124#define PP_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
125#define PP_NTOHS(x) PP_HTONS(x)
126#define PP_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \
127 (((x) & 0x0000ff00UL) << 8) | \
128 (((x) & 0x00ff0000UL) >> 8) | \
129 (((x) & 0xff000000UL) >> 24))
130#define PP_NTOHL(x) PP_HTONL(x)
131
132#endif /* BYTE_ORDER == BIG_ENDIAN */
133
134/* Functions that are not available as standard implementations.
135 * In cc.h, you can #define these to implementations available on
136 * your platform to save some code bytes if you use these functions
137 * in your application, too.
138 */
139
140#ifndef lwip_itoa
141/* This can be #defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform */
142void lwip_itoa(char* result, size_t bufsize, int number);
143#endif
144#ifndef lwip_strnicmp
145/* This can be #defined to strnicmp() or strncasecmp() depending on your platform */
146int lwip_strnicmp(const char* str1, const char* str2, size_t len);
147#endif
148#ifndef lwip_stricmp
149/* This can be #defined to stricmp() or strcasecmp() depending on your platform */
150int lwip_stricmp(const char* str1, const char* str2);
151#endif
152#ifndef lwip_strnstr
153/* This can be #defined to strnstr() depending on your platform */
154char* lwip_strnstr(const char* buffer, const char* token, size_t n);
155#endif
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif /* LWIP_HDR_DEF_H */
int lwip_stricmp(const char *str1, const char *str2)
Definition def.c:147
int lwip_strnicmp(const char *str1, const char *str2, size_t len)
Definition def.c:182
char * lwip_strnstr(const char *buffer, const char *token, size_t n)
Definition def.c:124
void lwip_itoa(char *result, size_t bufsize, int number)
Definition def.c:217