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 |
|
---|
19 | void *memccpy(dst, src, ucharstop, size)
|
---|
20 | void * dst;
|
---|
21 | _CONST void * src;
|
---|
22 | int 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.