3 * various utility macros
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * This file is part of the lwIP TCP/IP stack.
34 * Author: Adam Dunkels <adam@sics.se>
37 #ifndef LWIP_HDR_DEF_H
38 #define LWIP_HDR_DEF_H
40 /* arch.h might define NULL already */
41 #include "lwip/arch.h"
44 #include "arch/perf.h"
46 #define PERF_START /* null definition */
47 #define PERF_STOP(x) /* null definition */
48 #endif /* LWIP_PERF */
54 #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
55 #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
57 /* Get the number of entries in an array ('x' must NOT be a pointer!) */
58 #define LWIP_ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0]))
60 /** Create u32_t value from bytes */
61 #define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \
62 ((u32_t)((b) & 0xff) << 16) | \
63 ((u32_t)((c) & 0xff) << 8) | \
70 #define NULL ((void *)0)
74 #if BYTE_ORDER == BIG_ENDIAN
75 #define lwip_htons(x) (x)
76 #define lwip_ntohs(x) (x)
77 #define lwip_htonl(x) (x)
78 #define lwip_ntohl(x) (x)
79 #define PP_HTONS(x) (x)
80 #define PP_NTOHS(x) (x)
81 #define PP_HTONL(x) (x)
82 #define PP_NTOHL(x) (x)
83 #else /* BYTE_ORDER != BIG_ENDIAN */
85 u16_t
lwip_htons(u16_t x
);
87 #define lwip_ntohs(x) lwip_htons(x)
90 u32_t
lwip_htonl(u32_t x
);
92 #define lwip_ntohl(x) lwip_htonl(x)
94 /* Provide usual function names as macros for users, but this can be turned off */
95 #ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
96 #define htons(x) lwip_htons(x)
97 #define ntohs(x) lwip_ntohs(x)
98 #define htonl(x) lwip_htonl(x)
99 #define ntohl(x) lwip_ntohl(x)
102 /* These macros should be calculated by the preprocessor and are used
103 with compile-time constants only (so that there is no little-endian
104 overhead at runtime). */
105 #define PP_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
106 #define PP_NTOHS(x) PP_HTONS(x)
107 #define PP_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \
108 (((x) & 0x0000ff00UL) << 8) | \
109 (((x) & 0x00ff0000UL) >> 8) | \
110 (((x) & 0xff000000UL) >> 24))
111 #define PP_NTOHL(x) PP_HTONL(x)
113 #endif /* BYTE_ORDER == BIG_ENDIAN */
115 /* Functions that are not available as standard implementations.
116 * In cc.h, you can #define these to implementations available on
117 * your platform to save some code bytes if you use these functions
118 * in your application, too.
122 /* This can be #defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform */
123 void lwip_itoa(char* result
, size_t bufsize
, int number
);
125 #ifndef lwip_strnicmp
126 /* This can be #defined to strnicmp() or strncasecmp() depending on your platform */
127 int lwip_strnicmp(const char* str1
, const char* str2
, size_t len
);
130 /* This can be #defined to stricmp() or strcasecmp() depending on your platform */
131 int lwip_stricmp(const char* str1
, const char* str2
);
134 /* This can be #defined to strnstr() depending on your platform */
135 char* lwip_strnstr(const char* buffer
, const char* token
, size_t n
);
142 #endif /* LWIP_HDR_DEF_H */