-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigstring.c
More file actions
90 lines (68 loc) · 1.17 KB
/
sigstring.c
File metadata and controls
90 lines (68 loc) · 1.17 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "sigstring.h"
size_t
sigstrlen(const char *s)
{
size_t i = 0;
while (s[i] != '\0') i++;
return i;
}
char *
sigstrcpy(char *dst, const char *src)
{
size_t i = 0;
do
{
dst[i] = src[i];
} while (src[i++] != '\0');
return dst;
}
char *
sigstrncpy(char *dst, const char *src, size_t len)
{
size_t i;
for (i = 0; i < len && src[i] != '\0'; i++)
dst[i] = src[i];
for (; i < len; i++)
dst[i] = '\0';
return dst;
}
char *
sigstrchr(const char *s, int c)
{
char ch = (char)c;
do
{
if (*s == ch) return (char *)s;
} while (*s++ != '\0');
return NULL;
}
void *
sigmemset(void *s, int c, size_t n)
{
char ch = (char)c;
size_t i;
for (i = 0; i < n; i++)
((unsigned char *)s)[i] = ch;
return s;
}
void *
sigmemcpy(void *dst, const void *src, size_t n)
{
size_t i;
for (i = 0; i < n; i++)
((unsigned char *)dst)[i] = ((const unsigned char *)src)[i];
return dst;
}
void *
sigmemmove(void *dst, const void *src, size_t n)
{
unsigned char *d = dst;
const unsigned char *s = src;
size_t i;
if (d == s || n == 0) return dst;
if (d < s)
for (i = 0; i < n; i++) d[i] = s[i];
else
for (i = n; i > 0; i--) d[i - 1] = s[i - 1];
return dst;
}