mirror of
https://github.com/ipxe/ipxe
synced 2025-12-10 21:41:09 +03:00
@@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
@@ -205,11 +206,24 @@ int strncmp ( const char *first, const char *second, size_t max ) {
|
|||||||
* @ret diff Difference
|
* @ret diff Difference
|
||||||
*/
|
*/
|
||||||
int strcasecmp ( const char *first, const char *second ) {
|
int strcasecmp ( const char *first, const char *second ) {
|
||||||
|
|
||||||
|
return strncasecmp ( first, second, ~( ( size_t ) 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare case-insensitive strings
|
||||||
|
*
|
||||||
|
* @v first First string
|
||||||
|
* @v second Second string
|
||||||
|
* @v max Maximum length to compare
|
||||||
|
* @ret diff Difference
|
||||||
|
*/
|
||||||
|
int strncasecmp ( const char *first, const char *second, size_t max ) {
|
||||||
const uint8_t *first_bytes = ( ( const uint8_t * ) first );
|
const uint8_t *first_bytes = ( ( const uint8_t * ) first );
|
||||||
const uint8_t *second_bytes = ( ( const uint8_t * ) second );
|
const uint8_t *second_bytes = ( ( const uint8_t * ) second );
|
||||||
int diff;
|
int diff;
|
||||||
|
|
||||||
for ( ; ; first_bytes++, second_bytes++ ) {
|
for ( ; max-- ; first_bytes++, second_bytes++ ) {
|
||||||
diff = ( toupper ( *first_bytes ) -
|
diff = ( toupper ( *first_bytes ) -
|
||||||
toupper ( *second_bytes ) );
|
toupper ( *second_bytes ) );
|
||||||
if ( diff )
|
if ( diff )
|
||||||
@@ -217,6 +231,7 @@ int strcasecmp ( const char *first, const char *second ) {
|
|||||||
if ( ! *first_bytes )
|
if ( ! *first_bytes )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -189,5 +189,7 @@ bzero ( void *dest, size_t len ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int __pure strcasecmp ( const char *first, const char *second ) __nonnull;
|
int __pure strcasecmp ( const char *first, const char *second ) __nonnull;
|
||||||
|
int __pure strncasecmp ( const char *first, const char *second,
|
||||||
|
size_t max ) __nonnull;
|
||||||
|
|
||||||
#endif /* _STRINGS_H */
|
#endif /* _STRINGS_H */
|
||||||
|
|||||||
@@ -105,6 +105,14 @@ static void string_test_exec ( void ) {
|
|||||||
ok ( strcasecmp ( "Uncle", "Uncle Jack" ) != 0 );
|
ok ( strcasecmp ( "Uncle", "Uncle Jack" ) != 0 );
|
||||||
ok ( strcasecmp ( "not", "equal" ) != 0 );
|
ok ( strcasecmp ( "not", "equal" ) != 0 );
|
||||||
|
|
||||||
|
/* Test strncasecmp() */
|
||||||
|
ok ( strncasecmp ( "", "", 0 ) == 0 );
|
||||||
|
ok ( strncasecmp ( "", "", 73 ) == 0 );
|
||||||
|
ok ( strncasecmp ( "Uncle Jack", "Uncle jack", 47 ) == 0 );
|
||||||
|
ok ( strncasecmp ( "Uncle Jack", "Uncle jake", 47 ) != 0 );
|
||||||
|
ok ( strncasecmp ( "Uncle Jack", "Uncle jake", 9 ) != 0 );
|
||||||
|
ok ( strncasecmp ( "Uncle Jack", "Uncle jake", 8 ) == 0 );
|
||||||
|
|
||||||
/* Test memcmp() */
|
/* Test memcmp() */
|
||||||
ok ( memcmp ( "", "", 0 ) == 0 );
|
ok ( memcmp ( "", "", 0 ) == 0 );
|
||||||
ok ( memcmp ( "Foo", "Foo", 3 ) == 0 );
|
ok ( memcmp ( "Foo", "Foo", 3 ) == 0 );
|
||||||
|
|||||||
Reference in New Issue
Block a user