53 ok (
strlen (
"Hello world!" ) == 12 );
54 ok (
strlen (
"Hello\0world!" ) == 5 );
63 ok (
strnlen (
"Hello world!", 5 ) == 5 );
64 ok (
strnlen (
"Hello world!", 11 ) == 11 );
65 ok (
strnlen (
"Hello world!", 16 ) == 12 );
69 ok ( *(
strchr (
"Testing",
'e' )) ==
'e' );
70 ok ( *(
strchr (
"Testing",
'g' )) ==
'g' );
75 ok ( *(
strrchr (
"Haystack",
'a' )) ==
'a' );
76 ok ( *(
strrchr (
"Haystack",
'k' )) ==
'k' );
87 ok (
strcmp (
"Hello",
"Hello" ) == 0 );
88 ok (
strcmp (
"Hello",
"hello" ) != 0 );
89 ok (
strcmp (
"Hello",
"Hello world!" ) != 0 );
90 ok (
strcmp (
"Hello world!",
"Hello" ) != 0 );
96 ok (
strncmp (
"Goodbye",
"Goodbye", 16 ) == 0 );
97 ok (
strncmp (
"Goodbye",
"Hello", 16 ) != 0 );
98 ok (
strncmp (
"Goodbye",
"Goodbye world", 32 ) != 0 );
99 ok (
strncmp (
"Goodbye",
"Goodbye world", 7 ) == 0 );
118 ok (
memcmp (
"Foo",
"Foo", 3 ) == 0 );
119 ok (
memcmp (
"Foo",
"Bar", 3 ) != 0 );
120 ok (
memcmp (
"abc",
"def", 3 ) < 0 );
124 const char haystack[] =
"find me!";
127 found =
strstr ( haystack,
"find" );
128 ok ( found == &haystack[0] );
129 found =
strstr ( haystack,
"me" );
130 ok ( found == &haystack[5] );
131 found =
strstr ( haystack,
"me." );
137 static uint8_t test[7] = {
'>', 1, 1, 1, 1, 1,
'<' };
138 static const uint8_t expected[7] = {
'>', 0, 0, 0, 0, 0,
'<' };
144 static const uint8_t expected[4] = {
'>', 0xeb, 0xeb,
'<' };
152 {
'>', 1, 2, 3, 4, 5, 6, 7, 8, 9,
'<' };
153 static const uint8_t expected[11] =
154 {
'>', 3, 4, 5, 6, 7, 8, 7, 8, 9,
'<' };
160 {
'>', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
'<' };
161 static const uint8_t expected[12] =
162 {
'>', 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
'<' };
170 {
'>', 1, 2, 3, 7, 8, 9,
'<' };
171 static const uint8_t expected[8] =
172 {
'>', 7, 8, 9, 1, 2, 3,
'<' };
179 const char *orig =
"testing testing";
180 char *dup =
strdup ( orig );
189 const char *
normal =
"testing testing";
190 const char unterminated[6] = {
'h',
'e',
'l',
'l',
'o',
'!' };
201 dup =
strndup ( unterminated, 5 );
203 ok (
strcmp ( dup,
"hello" ) == 0 );
209 const char longer[12] =
"duplicateme";
210 const char shorter[6] =
"hello";
215 ok ( *dnul ==
'\0' );
219 ok ( *dnul ==
'\0' );
227 const char longer[7] =
"copyme";
228 const char shorter[3] =
"hi";
243 const char src[5] =
"copy";
244 const char orig[8] = {
'x',
'x',
'x',
'x',
'x',
'x',
'x',
'x' };
245 const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
272 char buf[16] =
"append";
277 ok (
strcmp ( buf,
"append this" ) == 0 );
284 for ( i = 0 ; i < 16 ; i++ ) {
285 snprintf ( buf,
sizeof ( buf ),
"%x", i );
287 snprintf ( buf,
sizeof ( buf ),
"%X", i );
314 static const char string[] =
"123aHa.world";
316 ok (
strtoul (
string, &endp, 0 ) == 123UL );
317 ok ( endp == &
string[3] );
318 ok (
strtoul (
string, &endp, 16 ) == 0x123aUL );
319 ok ( endp == &
string[4] );
321 ( ( ( ( ( 1 * 26 + 2 ) * 26 + 3 ) * 26 + 10 ) * 26
322 + 17 ) * 26 + 10 ) );
323 ok ( endp == &
string[6] );
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.
char * strrchr(const char *src, int character)
Find rightmost character within a string.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Self-test infrastructure.
const char * name
Test set name.
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.
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.
struct self_test string_test __self_test
String self-test.
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
static void string_test_exec(void)
Perform string self-tests.
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