X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/6d2010ae8f7a6078e10b361c6962983bab233e0f..743345f9a4b36f7e2f9ba37691e70c50baecb56e:/osfmk/device/subrs.c diff --git a/osfmk/device/subrs.c b/osfmk/device/subrs.c index 105edff0f..e36267988 100644 --- a/osfmk/device/subrs.c +++ b/osfmk/device/subrs.c @@ -187,6 +187,8 @@ strcmp( * comparison runs for at most "n" characters. */ +// ARM implementation in ../arm/strncmp.s +// ARM64 implementation in ../arm64/strncmp.s int strncmp( const char *s1, @@ -261,7 +263,6 @@ strncasecmp(const char *s1, const char *s2, size_t n) * Deprecation Warning: * strcpy() is being deprecated. Please use strlcpy() instead. */ -#if !CONFIG_EMBEDDED char * strcpy( char *to, @@ -274,7 +275,6 @@ strcpy( return ret; } -#endif /* * Abstract: @@ -285,6 +285,7 @@ strcpy( * to the "to" string. */ +// ARM and ARM64 implementation in ../arm/strncpy.c char * strncpy( char *s1, @@ -378,7 +379,10 @@ atoi_term( * outputs: * length of s or max; whichever is smaller */ -size_t + +// ARM implementation in ../arm/strnlen.s +// ARM64 implementation in ../arm64/strnlen.s +size_t strnlen(const char *s, size_t max) { const char *es = s + max, *p = s; while(*p && p != es) @@ -428,7 +432,6 @@ itoa( * Deprecation Warning: * strcat() is being deprecated. Please use strlcat() instead. */ -#if !CONFIG_EMBEDDED char * strcat( char *dest, @@ -442,7 +445,6 @@ strcat( ; return (old); } -#endif /* * Appends src to string dst of size siz (unlike strncat, siz is the @@ -484,6 +486,8 @@ strlcat(char *dst, const char *src, size_t siz) * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ + +// ARM and ARM64 implementation in ../arm/strlcpy.c size_t strlcpy(char *dst, const char *src, size_t siz) { @@ -553,16 +557,37 @@ STRDUP(const char *string, int type) /* * Return TRUE(1) if string 2 is a prefix of string 1. - */ -int -strprefix(register const char *s1, register const char *s2) -{ - register int c; - - while ((c = *s2++) != '\0') { - if (c != *s1++) - return (0); - } - return (1); + */ +int +strprefix(const char *s1, const char *s2) +{ + int c; + + while ((c = *s2++) != '\0') { + if (c != *s1++) + return (0); + } + return (1); +} + +char * +strnstr(char *s, const char *find, size_t slen) +{ + char c, sc; + size_t len; + + if ((c = *find++) != '\0') { + len = strlen(find); + do { + do { + if ((sc = *s++) == '\0' || slen-- < 1) + return (NULL); + } while (sc != c); + if (len > slen) + return (NULL); + } while (strncmp(s, find, len) != 0); + s--; + } + return (s); }