2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
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,
26 #ifndef AMIGA_INCLUDES_H
27 #include <kern/amiga_includes.h>
31 #define _ANSI_SOURCE /* 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!
52 #define bcopy(a,b,c) CopyMem((APTR)(a),b,c)
53 #define ovbcopy(a,b,c) memmove(b,a,c)
57 #include <sys/cdefs.h>
63 return (a
< b
? a
: b
);
67 //#define MIN(a,b) imin(a,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
);
93 return (a
< b
? a
: 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
);
115 ovbcopy(const void *v1
, void *v2
, register unsigned len
)
117 const register u_char
*s1
= v1
;
118 register u_char
*s2
= v2
;
122 * copy possibly destroying s1 (if overlap), copy backwards
134 #if 0 /* NC: using string.h instead */
136 bcmp(const void *v1
, const void *v2
, register unsigned len
)
138 const register u_char
*s1
= v1
, *s2
= v2
;
147 bzero(void *buf
, register unsigned len
)
149 register char *s
= buf
;
156 bcopy(const void *v1
, void *v2
, register unsigned len
)
158 const register u_char
*s1
= v1
;
159 register u_char
*s2
= v2
;
166 strlen(register const char *s1
)
170 for (len
= 0; *s1
++ != '\0'; len
++)
176 strcpy(register char *s1
, register const char *s2
)
178 register char *s
= s1
;
184 strcmp(char *, char*);
187 strncpy(register char *s1
, register const char *s2
, register unsigned int len
)
189 register char *s
= s1
;
190 while(len
-- && (*s
++ = *s2
++))
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
208 * clear an aligned memory area of constant length to zero
211 aligned_bzero_const(void *buf
, long size
)
214 long *lbuf
= (long *)buf
;
217 lcount
= (size
>> 2);
220 * unroll the loop if short enough
238 } while (--lcount
>= 0);
242 sbuf
= (short *)lbuf
;
251 aligned_bzero(void *buf
, long size
)
254 long *lbuf
= (long *)buf
;
257 lcount
= (size
>> 2);
261 } while (--lcount
>= 0);
264 sbuf
= (short *)lbuf
;
273 aligned_bcopy_const(const void *src
, void *dst
, long size
)
276 long *ldst
= (long *)dst
;
278 long *lsrc
= (long *)src
;
281 lcount
= (size
>> 2);
284 * unroll the loop if short enough
302 } while (--lcount
>= 0);
306 sdst
= (short *)ldst
;
307 ssrc
= (short *)lsrc
;
312 *(char *)sdst
= *(char *)ssrc
;
316 aligned_bcopy(const void *src
, void *dst
, long size
)
319 long *ldst
= (long *)dst
;
321 long *lsrc
= (long *)src
;
324 lcount
= (size
>> 2);
328 } while (--lcount
>= 0);
331 sdst
= (short *)ldst
;
332 ssrc
= (short *)lsrc
;
337 *(char *)sdst
= *(char *)ssrc
;
339 #endif /* USE_ALIGNED_COPIES */
340 #endif /* AMIGA_SUBR_H */