revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / kern / amiga_subr.h
blobc1672aa7b8f0e3553c350f5f36b7c41403cbdea6
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
5 * Copyright (C) 2005 Neil Cafferkey
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
23 #ifndef AMIGA_SUBR_H
24 #define AMIGA_SUBR_H
26 #ifndef AMIGA_INCLUDES_H
27 #include <kern/amiga_includes.h>
28 #endif
30 #if __SASC
31 #define _ANSI_SOURCE /* NC */
32 /*#if 1*/ /* NC */
34 * Using builtin functions (string.h included in kern/amiga_includes.h)
36 #define imin(a,b) min(a,b)
37 #define MIN(a,b) min(a,b)
38 #define lmin(a,b) min(a,b)
39 #define ulmin(a,b) min(a,b)
41 #define imax(a,b) max(a,b)
42 #define MAX(a,b) max(a,b)
43 #define lmax(a,b) max(a,b)
44 #define ulmax(a,b) max(a,b)
46 * bcopy(), bcmp() and bzero() are defined in string.h
48 * NOTE: bcopy is infact ovbcopy(). Optimize this when all other works!
51 #undef bcopy
52 #define bcopy(a,b,c) CopyMem((APTR)(a),b,c)
53 #define ovbcopy(a,b,c) memmove(b,a,c)
55 #else
56 #ifndef SYS_CDEFS_H
57 #include <sys/cdefs.h>
58 #endif
60 static inline int
61 imin(int a, int b)
63 return (a < b ? a : b);
66 //#ifndef MIN
67 //#define MIN(a,b) imin(a,b)
68 //#endif
70 static inline int
71 imax(int a, int b)
73 return (a > b ? a : b);
76 #if !defined(__AROS__)
77 static inline unsigned int
78 min(unsigned int a, unsigned int b)
80 return (a < b ? a : b);
83 static inline unsigned int
84 max(unsigned int a, unsigned int b)
86 return (a > b ? a : b);
88 #endif
90 static inline long
91 lmin(long a, long b)
93 return (a < b ? a : b);
96 static inline long
97 lmax(long a, long b)
99 return (a > b ? a : b);
102 static inline unsigned long
103 ulmin(unsigned long a, unsigned long b)
105 return (a < b ? a : b);
108 static inline unsigned long
109 ulmax(unsigned long a, unsigned long b)
111 return (a > b ? a : b);
114 static inline void
115 ovbcopy(const void *v1, void *v2, register unsigned len)
117 const register u_char *s1 = v1;
118 register u_char *s2 = v2;
120 if (s1 < s2) {
122 * copy possibly destroying s1 (if overlap), copy backwards
124 s1 += len;
125 s2 += len;
126 while (len--)
127 *(--s2) = *(--s1);
129 else
130 while (len--)
131 *s2++ = *s1++;
134 #if 0 /* NC: using string.h instead */
135 static inline int
136 bcmp(const void *v1, const void *v2, register unsigned len)
138 const register u_char *s1 = v1, *s2 = v2;
140 while (len--)
141 if (*s1++ != *s2++)
142 return (1);
143 return (0);
146 static inline void
147 bzero(void *buf, register unsigned len)
149 register char *s = buf;
151 while(len--)
152 *s++ = '\0';
155 static inline void
156 bcopy(const void *v1, void *v2, register unsigned len)
158 const register u_char *s1 = v1;
159 register u_char *s2 = v2;
161 while (len--)
162 *s2++ = *s1++;
165 static inline int
166 strlen(register const char *s1)
168 register int len;
170 for (len = 0; *s1++ != '\0'; len++)
172 return (len);
175 static inline char *
176 strcpy(register char *s1, register const char *s2)
178 register char *s = s1;
179 while(*s++ = *s2++)
181 return (s1);
184 strcmp(char *, char*);
186 static inline char *
187 strncpy(register char *s1, register const char *s2, register unsigned int len)
189 register char *s = s1;
190 while(len-- && (*s++ = *s2++))
192 return (s1);
194 #endif
195 #endif /* __SASC */
198 * These are for both environments
201 #ifndef USE_ALIGNED_COPIES
202 #define aligned_bcopy_const bcopy
203 #define aligned_bcopy bcopy
204 #define aligned_bzero_const bzero
205 #define aligned_bzero bzero
206 #else
208 * clear an aligned memory area of constant length to zero
210 static inline void
211 aligned_bzero_const(void *buf, long size)
213 short lcount;
214 long *lbuf = (long *)buf;
215 short *sbuf;
217 lcount = (size >> 2);
218 if (lcount--) {
220 * unroll the loop if short enough
222 if (lcount < 6) {
223 *lbuf++ = 0;
224 if (--lcount >= 0)
225 *lbuf++ = 0;
226 if (--lcount >= 0)
227 *lbuf++ = 0;
228 if (--lcount >= 0)
229 *lbuf++ = 0;
230 if (--lcount >= 0)
231 *lbuf++ = 0;
232 if (--lcount >= 0)
233 *lbuf++ = 0;
235 else {
236 do {
237 *lbuf++ = 0;
238 } while (--lcount >= 0);
242 sbuf = (short *)lbuf;
243 if (size & 0x2)
244 *sbuf++ = 0;
246 if (size & 0x1)
247 *(char *)sbuf = 0;
250 static inline void
251 aligned_bzero(void *buf, long size)
253 short lcount;
254 long *lbuf = (long *)buf;
255 short *sbuf;
257 lcount = (size >> 2);
258 if (lcount--) {
259 do {
260 *lbuf++ = 0;
261 } while (--lcount >= 0);
264 sbuf = (short *)lbuf;
265 if (size & 0x2)
266 *sbuf++ = 0;
268 if (size & 0x1)
269 *(char *)sbuf = 0;
272 static inline void
273 aligned_bcopy_const(const void *src, void *dst, long size)
275 short lcount;
276 long *ldst = (long *)dst;
277 short *sdst;
278 long *lsrc = (long *)src;
279 short *ssrc;
281 lcount = (size >> 2);
282 if (lcount--) {
284 * unroll the loop if short enough
286 if (lcount < 6) {
287 *ldst++ = *lsrc++;
288 if (--lcount >= 0)
289 *ldst++ = *lsrc++;
290 if (--lcount >= 0)
291 *ldst++ = *lsrc++;
292 if (--lcount >= 0)
293 *ldst++ = *lsrc++;
294 if (--lcount >= 0)
295 *ldst++ = *lsrc++;
296 if (--lcount >= 0)
297 *ldst++ = *lsrc++;
299 else {
300 do {
301 *ldst++ = *lsrc++;
302 } while (--lcount >= 0);
306 sdst = (short *)ldst;
307 ssrc = (short *)lsrc;
308 if (size & 0x2)
309 *sdst++ = *ssrc++;
311 if (size & 0x1)
312 *(char *)sdst = *(char *)ssrc;
315 static inline void
316 aligned_bcopy(const void *src, void *dst, long size)
318 short lcount;
319 long *ldst = (long *)dst;
320 short *sdst;
321 long *lsrc = (long *)src;
322 short *ssrc;
324 lcount = (size >> 2);
325 if (lcount--) {
326 do {
327 *ldst++ = *lsrc++;
328 } while (--lcount >= 0);
331 sdst = (short *)ldst;
332 ssrc = (short *)lsrc;
333 if (size & 0x2)
334 *sdst++ = *ssrc++;
336 if (size & 0x1)
337 *(char *)sdst = *(char *)ssrc;
339 #endif /* USE_ALIGNED_COPIES */
340 #endif /* AMIGA_SUBR_H */