diff options
author | Freya Murphy <freya@freyacat.org> | 2024-01-27 03:38:27 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-01-27 03:38:34 -0500 |
commit | eec8119eeea0ef0e226bd3541eebc9294cdd79b1 (patch) | |
tree | 83b3fe6d45d0cef2de587f27dd9a26f2b5b8c6d9 | |
parent | Ununfixed kmain, fixed boot.S (diff) | |
download | corn-eec8119eeea0ef0e226bd3541eebc9294cdd79b1.tar.gz corn-eec8119eeea0ef0e226bd3541eebc9294cdd79b1.tar.bz2 corn-eec8119eeea0ef0e226bd3541eebc9294cdd79b1.zip |
more lib fns
-rw-r--r-- | include/lib.h | 12 | ||||
-rw-r--r-- | src/lib.c | 11 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/lib.h b/include/lib.h index b368636..43b95a6 100644 --- a/include/lib.h +++ b/include/lib.h @@ -32,6 +32,18 @@ extern void *memset(void *restrict dest, int c, unsigned long n); extern int strncmp(const char *restrict s1, const char *restrict s2, unsigned long n); /** + * Copys the string pointed to by src , into a string at the buffer pointer to by dest. + * The dest buffer must be long enough to hold src. + */ +extern char *strcpy(char *restrict dest, const char *restrict src); + +/** + * Copys the string pointed to by src , into a string at the buffer pointer to by dest. + * The dest buffer must be long enough to hold src or size n. + */ +extern char *strncpy(char *restrict dest, const char *restrict src, unsigned long n); + +/** * @returns 1 if c is a space */ extern int isspace(int c); @@ -43,6 +43,17 @@ int strncmp(const char *restrict lhs, const char *restrict rhs, unsigned long n) return *l - *r; } +char *strcpy(char *restrict dest, const char *restrict src) { + for(; (*dest = *src); dest++, src++); + return dest; +} + +char *strncpy(char *restrict dest, const char *restrict src, unsigned long n) { + for(; (*dest = *src) && n; dest++, src++, n--); + memset(dest, 0, n); + return dest; +} + int isspace(int c) { switch (c) { case ' ': |