Loading [MathJax]/jax/input/TeX/config.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
string.h File Reference
#include <stdint.h>
Include dependency graph for string.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int memcmp (const void *b1, const void *b2, size_t len)
 
void * memcpy (void *dst, const void *src, size_t len)
 
void * memset (void *dst, int c, size_t len)
 
char * strchr (const char *s, int c)
 
int strcmp (const char *s1, const char *s2)
 
char * strcpy (char *to, const char *from)
 
size_t strlen (const char *str)
 
int strncmp (const char *s1, const char *s2, size_t len)
 
char * strncpy (char *to, const char *from, size_t len)
 
char * strcat (char *s, const char *append)
 
char * strncat (char *s, const char *append, size_t count)
 
char * strtok (char *str, const char *delim)
 
char * strtok_r (char *str, const char *delim, char **last)
 

Function Documentation

◆ memcmp()

int memcmp ( const void *  b1,
const void *  b2,
size_t  len 
)

Definition at line 192 of file string.c.

193{
194 int i;
195 const char *c1 = (const char *)b1;
196 const char *c2 = (const char *)b2;
197
198 for (i = 0; i < length; i++)
199 {
200 if (*c1 != *c2)
201 return *c2 - *c1;
202 c1++;
203 c2++;
204 }
205
206 return 0;
207}
Here is the caller graph for this function:

◆ memcpy()

void * memcpy ( void *  dst,
const void *  src,
size_t  len 
)

Definition at line 177 of file string.c.

178{
179 uint8_t *d = (uint8_t *)dst;
180 const uint8_t *s = (const uint8_t *)src;
181
182 while (length-- != 0) {
183 *d = *s;
184 d += 1;
185 s += 1;
186 };
187
188 return dst;
189}
unsigned char uint8_t
Definition: types.h:10
Here is the caller graph for this function:

◆ memset()

void * memset ( void *  dst,
int  c,
size_t  len 
)

Definition at line 164 of file string.c.

165{
166 uint8_t *p = (uint8_t *)dst;
167
168 while (length-- != 0) {
169 *p = c;
170 p += 1;
171 };
172
173 return dst;
174}
Here is the caller graph for this function:

◆ strcat()

char * strcat ( char *  s,
const char *  append 
)

Definition at line 46 of file string.c.

47{
48 char *save = s;
49
50 for (; *s; ++s);
51 while ((*s++ = *append++));
52
53 return save;
54}
Here is the caller graph for this function:

◆ strchr()

char * strchr ( const char *  s,
int  c 
)

Definition at line 11 of file string.c.

12{
13 int i;
14 for (i = 0; ; i++)
15 {
16 if (s[i] == c)
17 return (char *)s + i;
18 if (s[i] == '\0')
19 return NULL;
20 }
21}
#define NULL
Definition: stddef.h:6
Here is the caller graph for this function:

◆ strcmp()

int strcmp ( const char *  s1,
const char *  s2 
)

Definition at line 81 of file string.c.

82{
83 while (*s1 == *s2++)
84 if (*s1++ == 0)
85 return 0;
86
87 return (*(const uint8_t *)s1 - *(const uint8_t *)(s2 - 1));
88}
Here is the caller graph for this function:

◆ strcpy()

char * strcpy ( char *  to,
const char *  from 
)

Definition at line 24 of file string.c.

25{
26 char *save = to;
27
28 for (; (*to = *from); ++from, ++to);
29
30 return save;
31}
Here is the caller graph for this function:

◆ strlen()

size_t strlen ( const char *  str)

Definition at line 112 of file string.c.

113{
114 const char *s;
115
116 for (s = str; *s; ++s);
117
118 return (s - str);
119}
Here is the caller graph for this function:

◆ strncat()

char * strncat ( char *  s,
const char *  append,
size_t  count 
)

Definition at line 58 of file string.c.

59{
60 if (n != 0) {
61 char *d = dst;
62 const char *s = src;
63
64 while (*d != 0)
65 d++;
66
67 do {
68 if ((*d = *s++) == 0)
69 break;
70
71 d++;
72 } while (--n != 0);
73
74 *d = 0;
75 }
76
77 return dst;
78}

◆ strncmp()

int strncmp ( const char *  s1,
const char *  s2,
size_t  len 
)

Definition at line 91 of file string.c.

92{
93 if (len == 0)
94 return 0;
95
96 while (*s1 == *s2) {
97 if (*s1 == 0)
98 return 0;
99
100 s1++;
101 s2++;
102
103 len--;
104 if (len == 0)
105 return 0;
106 }
107
108 return (*(const uint8_t *)s1 - *(const uint8_t *)s2);
109}
uint64_t len
Definition: multiboot.h:2
Here is the caller graph for this function:

◆ strncpy()

char * strncpy ( char *  to,
const char *  from,
size_t  len 
)

Definition at line 34 of file string.c.

35{
36 char *save = to;
37
38 for (; (*to = *from) != '\0' && length > 0; ++from, ++to, length--);
39
40 *to = '\0';
41
42 return save;
43}
Here is the caller graph for this function:

◆ strtok()

char * strtok ( char *  str,
const char *  delim 
)

Definition at line 156 of file string.c.

157{
158 static char *last;
159
160 return strtok_r(str, delim, &last);
161}
char * strtok_r(char *str, const char *delim, char **last)
Definition: string.c:122
Here is the call graph for this function:
Here is the caller graph for this function:

◆ strtok_r()

char * strtok_r ( char *  str,
const char *  delim,
char **  last 
)

Definition at line 122 of file string.c.

123{
124 char *rval;
125
126 if (str == NULL)
127 str = *last;
128
129 // Skip deliminaters in the front
130 while ((str[0] != '\0') && strchr(delim, str[0])) {
131 str++;
132 }
133
134 // We've reached the end of the string
135 if (str[0] == '\0')
136 return NULL;
137
138 // Return first non-delim until the next
139 rval = str;
140
141 // Skip deliminaters in the front
142 while ((str[0] != '\0') && !strchr(delim, str[0])) {
143 str++;
144 }
145
146 if (str[0] != '\0') {
147 str[0] = '\0';
148 str++;
149 }
150 *last = str;
151
152 return rval;
153}
char * strchr(const char *s, int c)
Definition: string.c:11
Here is the call graph for this function:
Here is the caller graph for this function: