memory.c
700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <scot/memory.h>
#include <scot/scot_types.h>
SIZE_T
str_length (const char * str)
{
const char * s = str;
while (*(s++));
return s-str-1;
}
char *
str_copy (char * dest, const char * src)
{
char * d = dest;
while (*(d++) = *(src++));
return dest;
}
char *
strn_copy (char * dest, const char * src, SIZE_T size)
{
char * d = dest;
while ((d-dest) < size && (*(d++) = *(src++)));
return dest;
}
char *
str_char (const char * str, int ch)
{
while ((*str != ch) && *(str++));
return (*str)?(char *)str:NULL;
}
char *
strr_char (const char * str, int ch)
{
const char * s = str;
while (*(s++));
while ((*(--s) != ch) && (s != str));
return (s!=str)?(char *)s:NULL;
}