source: trunk/minix/lib/other/memccpy.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 857 bytes
Line 
1#include <lib.h>
2/* memccpy - copy bytes up to a certain char
3 *
4 * CHARBITS should be defined only if the compiler lacks "unsigned char".
5 * It should be a mask, e.g. 0377 for an 8-bit machine.
6 */
7
8#include <ansi.h>
9#include <stddef.h>
10
11_PROTOTYPE( void *memccpy, (void *dst, const void *src,
12 int ucharstop, size_t size));
13#ifndef CHARBITS
14# define UNSCHAR(c) ((unsigned char)(c))
15#else
16# define UNSCHAR(c) ((c)&CHARBITS)
17#endif
18
19void *memccpy(dst, src, ucharstop, size)
20void * dst;
21_CONST void * src;
22int ucharstop;
23_SIZET size;
24{
25 register char *d;
26 register _CONST char *s;
27 register _SIZET n;
28 register int uc;
29
30 if (size <= 0) return( (void *) NULL);
31
32 s = (char *) src;
33 d = (char *) dst;
34 uc = UNSCHAR(ucharstop);
35 for (n = size; n > 0; n--)
36 if (UNSCHAR(*d++ = *s++) == (char) uc) return( (void *) d);
37
38 return( (void *) NULL);
39}
Note: See TracBrowser for help on using the repository browser.