2021-11-26 07:18:08 +03:00
|
|
|
/**
|
|
|
|
* @brief Utility functions.
|
|
|
|
*
|
|
|
|
* Kind of a barebones libc.
|
|
|
|
*
|
|
|
|
* @copyright
|
|
|
|
* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2018-2021 K. Lange
|
|
|
|
*/
|
2021-06-14 05:11:37 +03:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
int strcmp(const char * l, const char * r) {
|
|
|
|
for (; *l == *r && *l; l++, r++);
|
|
|
|
return *(unsigned char *)l - *(unsigned char *)r;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * strchr(const char * s, int c) {
|
|
|
|
while (*s) {
|
|
|
|
if (*s == c) {
|
|
|
|
return (char *)s;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-21 01:55:48 +03:00
|
|
|
unsigned long strlen(const char *s) {
|
|
|
|
unsigned long out = 0;
|
|
|
|
while (*s) {
|
|
|
|
out++;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2021-06-14 05:11:37 +03:00
|
|
|
char * strcat(char *dest, const char *src) {
|
|
|
|
char * end = dest;
|
|
|
|
while (*end != '\0') {
|
|
|
|
++end;
|
|
|
|
}
|
|
|
|
while (*src) {
|
|
|
|
*end = *src;
|
|
|
|
end++;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
*end = '\0';
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|