more lib fns

This commit is contained in:
Freya Murphy 2024-01-27 03:38:27 -05:00
parent 90c70043be
commit eec8119eee
Signed by: freya
GPG key ID: 744AB800E383AE52
2 changed files with 23 additions and 0 deletions

View file

@ -31,6 +31,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); 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 * @returns 1 if c is a space
*/ */

View file

@ -43,6 +43,17 @@ int strncmp(const char *restrict lhs, const char *restrict rhs, unsigned long n)
return *l - *r; 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) { int isspace(int c) {
switch (c) { switch (c) {
case ' ': case ' ':