mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
string: strnlen
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
size_t strlen(const char *str);
|
size_t strlen(const char *str);
|
||||||
|
size_t strnlen(const char *str, size_t max);
|
||||||
char *strcpy(char *dest, const char *src);
|
char *strcpy(char *dest, const char *src);
|
||||||
char *strcat(char *dest, const char *str);
|
char *strcat(char *dest, const char *str);
|
||||||
void *memcpy(void *dest, const void *src, size_t size);
|
void *memcpy(void *dest, const void *src, size_t size);
|
||||||
|
|||||||
@@ -65,6 +65,15 @@ size_t strlen(const char *a) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t strnlen(const char *a, size_t max) {
|
||||||
|
size_t s = 0;
|
||||||
|
|
||||||
|
while (s < max && a[s] != '\0')
|
||||||
|
++s;
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
int strncmp(const char *a, const char *b, size_t c) {
|
int strncmp(const char *a, const char *b, size_t c) {
|
||||||
int diff = 0;
|
int diff = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user