aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2021-05-18 11:45:24 +0100
committerMichael Brown <mcb30@ipxe.org>2021-05-18 11:45:24 +0100
commit661093054bcfae16d79404304d6f8318baf1231e (patch)
treebecc12c5729556998fe5c2b19515b58d5f7e6710 /src/core
parent059c4dc688cea6d9398d63ca10f5c00e94ae2159 (diff)
downloadipxe-661093054bcfae16d79404304d6f8318baf1231e.zip
ipxe-661093054bcfae16d79404304d6f8318baf1231e.tar.gz
ipxe-661093054bcfae16d79404304d6f8318baf1231e.tar.bz2
[libc] Add strncasecmp()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/string.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/core/string.c b/src/core/string.c
index 188fe08..9a1b9b7 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <ctype.h>
/** @file
@@ -205,11 +206,24 @@ int strncmp ( const char *first, const char *second, size_t max ) {
* @ret diff Difference
*/
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 *second_bytes = ( ( const uint8_t * ) second );
int diff;
- for ( ; ; first_bytes++, second_bytes++ ) {
+ for ( ; max-- ; first_bytes++, second_bytes++ ) {
diff = ( toupper ( *first_bytes ) -
toupper ( *second_bytes ) );
if ( diff )
@@ -217,6 +231,7 @@ int strcasecmp ( const char *first, const char *second ) {
if ( ! *first_bytes )
return 0;
}
+ return 0;
}
/**