Perform string self-tests.
54 ok (
strlen (
"Hello world!" ) == 12 );
55 ok (
strlen (
"Hello\0world!" ) == 5 );
64 ok (
strnlen (
"Hello world!", 5 ) == 5 );
65 ok (
strnlen (
"Hello world!", 11 ) == 11 );
66 ok (
strnlen (
"Hello world!", 16 ) == 12 );
70 ok ( *(
strchr (
"Testing",
'e' )) ==
'e' );
71 ok ( *(
strchr (
"Testing",
'g' )) ==
'g' );
76 ok ( *(
strrchr (
"Haystack",
'a' )) ==
'a' );
77 ok ( *(
strrchr (
"Haystack",
'k' )) ==
'k' );
88 ok (
strcmp (
"Hello",
"Hello" ) == 0 );
89 ok (
strcmp (
"Hello",
"hello" ) != 0 );
90 ok (
strcmp (
"Hello",
"Hello world!" ) != 0 );
91 ok (
strcmp (
"Hello world!",
"Hello" ) != 0 );
97 ok (
strncmp (
"Goodbye",
"Goodbye", 16 ) == 0 );
98 ok (
strncmp (
"Goodbye",
"Hello", 16 ) != 0 );
99 ok (
strncmp (
"Goodbye",
"Goodbye world", 32 ) != 0 );
100 ok (
strncmp (
"Goodbye",
"Goodbye world", 7 ) == 0 );
119 ok (
memcmp (
"Foo",
"Foo", 3 ) == 0 );
120 ok (
memcmp (
"Foo",
"Bar", 3 ) != 0 );
121 ok (
memcmp (
"abc",
"def", 3 ) < 0 );
125 const char haystack[] =
"find me!";
128 found =
strstr ( haystack,
"find" );
129 ok ( found == &haystack[0] );
130 found =
strstr ( haystack,
"me" );
131 ok ( found == &haystack[5] );
132 found =
strstr ( haystack,
"me." );
138 static uint8_t test[7] = {
'>', 1, 1, 1, 1, 1,
'<' };
153 {
'>', 1, 2, 3, 4, 5, 6, 7, 8, 9,
'<' };
155 {
'>', 3, 4, 5, 6, 7, 8, 7, 8, 9,
'<' };
161 {
'>', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
'<' };
163 {
'>', 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
'<' };
171 {
'>', 1, 2, 3, 7, 8, 9,
'<' };
173 {
'>', 7, 8, 9, 1, 2, 3,
'<' };
180 const char *orig =
"testing testing";
181 char *dup =
strdup ( orig );
190 const char *
normal =
"testing testing";
191 const char unterminated[6] = {
'h',
'e',
'l',
'l',
'o',
'!' };
202 dup =
strndup ( unterminated, 5 );
204 ok (
strcmp ( dup,
"hello" ) == 0 );
210 const char longer[12] =
"duplicateme";
211 const char shorter[6] =
"hello";
216 ok ( *dnul ==
'\0' );
220 ok ( *dnul ==
'\0' );
228 const char longer[7] =
"copyme";
229 const char shorter[3] =
"hi";
244 const char src[5] =
"copy";
245 const char orig[8] = {
'x',
'x',
'x',
'x',
'x',
'x',
'x',
'x' };
246 const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
273 char buf[16] =
"append";
278 ok (
strcmp ( buf,
"append this" ) == 0 );
285 for ( i = 0 ; i < 16 ; i++ ) {
286 snprintf ( buf,
sizeof ( buf ),
"%x", i );
288 snprintf ( buf,
sizeof ( buf ),
"%X", i );
315 static const char string[] =
"123aHa.world";
317 ok (
strtoul (
string, &endp, 0 ) == 123UL );
318 ok ( endp == &
string[3] );
319 ok (
strtoul (
string, &endp, 16 ) == 0x123aUL );
320 ok ( endp == &
string[4] );
322 ( ( ( ( ( 1 * 26 + 2 ) * 26 + 3 ) * 26 + 10 ) * 26
323 + 17 ) * 26 + 10 ) );
324 ok ( endp == &
string[6] );
330 ok (
wcslen ( L
"Helloo woorld!" ) == 14 );
331 ok (
wcslen ( L
"Helloo\0woorld!" ) == 6 );
340 ok (
wcsnlen ( L
"Helloo woorld!", 5 ) == 5 );
341 ok (
wcsnlen ( L
"Helloo woorld!", 11 ) == 11 );
342 ok (
wcsnlen ( L
"Helloo woorld!", 16 ) == 14 );
int expected
Expected value.
void * memswap(void *first, void *second, size_t len)
Swap memory regions.
struct arbelprm_completion_queue_entry normal
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
size_t wcsnlen(const wchar_t *string, size_t max)
Calculate length of wide-character string.
char * strrchr(const char *src, int character)
Find rightmost character within a string.
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
int strncasecmp(const char *first, const char *second, size_t max)
Compare case-insensitive strings.
unsigned int digit_value(unsigned int character)
Calculate digit value.
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
size_t wcslen(const wchar_t *string)
Calculate length of wide-character string.
void * memchr(const void *src, int character, size_t len)
Find character within a memory region.
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
char * strstr(const char *haystack, const char *needle)
Find substring.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
char * stpcpy(char *dest, const char *src)
Copy string.
char * strcpy(char *dest, const char *src)
Copy string.
static void(* free)(struct refcnt *refcnt))
char * strchr(const char *src, int character)
Find character within a string.
char * strdup(const char *src)
Duplicate string.
size_t strlen(const char *src)
Get length of string.
size_t strnlen(const char *src, size_t max)
Get length of string.
void * memmove(void *dest, const void *src, size_t len) __nonnull
int strcmp(const char *first, const char *second)
Compare strings.
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
char * strndup(const char *src, size_t max)
Duplicate string.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
char * strcat(char *dest, const char *src)
Concatenate string.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define NULL
NULL pointer (VOID *)
void * memset(void *dest, int character, size_t len) __nonnull