9int snprintf(
char *s,
size_t n,
const char *fmt, ...);
12static inline void *
memmove(
void *dest,
const void *src,
size_t n)
18 *(
char *) dest++ = *(
char *) src++;
22 *((
char *) dest + n) = *((
char *) src + n);
30static inline void *
memcpy(
void *dest,
const void *src,
size_t n)
34 *(
char *) dest++ = *(
char *) src++;
40static inline void *
memset(
void *s,
int c,
size_t n)
45 *(
char *) s++ = (
char) c;
53static inline int memcmp(
const void *s1,
const void *s2,
size_t n)
55 const unsigned char *a = s1, *b = s2;
57 for (; n; --n, ++a, ++b)
66static inline int strcmp(
const char *s1,
const char *s2)
68 while (*s1 !=
'\0' && *s2 !=
'\0' && *s1 == *s2) {s1++; s2++;}
70 return (
int)(*s1 - *s2);
74static inline int strncmp(
const char *s1,
const char *s2,
size_t n)
76 for (; n != 0; --n, ++s1, ++s2) {
78 return (
int) *(
const unsigned char *) s1 - (
int) *(
const unsigned char *) s2;
88static inline int strlen(
const char *s)
97static inline size_t strnlen(
const char *s,
size_t max)
100 while (n < max && s[n]) n++;
109 char *ret =
kmalloc(len + 1, &M_BUFFER, 0);
114 (void)
memcpy(ret, s, len + 1);
119static inline char *
strcpy(
char *dst,
const char *src)
133static inline char *
stpcpy(
char *dst,
const char *src)
135 while ((*dst = *src++))
147static inline char **
tokenize(
const char *s,
char c)
149 if (s ==
NULL || *s ==
'\0')
166 char **ret =
kmalloc(
sizeof(
char *), &M_BUFFER, 0);
175 for (i = 0; i < len; ++i) {
176 if (tokens[i] == c) {
185 char **ret =
kmalloc(
sizeof(
char *) * (count + 1), &M_BUFFER, 0);
195 for (i = 0; i <
strlen(s) - 1; ++i)
197 ret[j++] = &tokens[i+1];
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
int memcmp(const void *a, const void *b, size_t n)
Compares n bytes.
void * memmove(void *dst, const void *src, size_t n)
Copies n bytes; dst and src may overlap.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
int snprintf(char *s, size_t n, const char *fmt,...)
Formats a string into a buffer.
static int strcmp(const char *s1, const char *s2)
Compares two strings, as the C library's strcmp().
static size_t strnlen(const char *s, size_t max)
Returns the length of a string, or max if there is no NUL in its first max bytes.
static int strncmp(const char *s1, const char *s2, size_t n)
Compares at most n characters of two strings.
static char ** tokenize(const char *s, char c)
Splits a string at each c, leading ones skipped.
static int strlen(const char *s)
Returns the length of a string.
static char * strcpy(char *dst, const char *src)
Copies a string, with its NUL, and returns dst.
static char * strdup(const char *s)
Returns a copy of a string, from kmalloc(), or NULL if there's no memory for it.
static char * stpcpy(char *dst, const char *src)
Copies a string, as strcpy(), but returns the end of dst (its NUL).
static void free_tokens(char **ptr)
Frees what tokenize() returned.