1 1.4 joerg /* $NetBSD: wcscasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $ */ 2 1.2 christos 3 1.2 christos /* 4 1.2 christos * Copyright (C) 2006 Aleksey Cheusov 5 1.2 christos * 6 1.2 christos * This material is provided "as is", with absolutely no warranty expressed 7 1.2 christos * or implied. Any use is at your own risk. 8 1.2 christos * 9 1.2 christos * Permission to use or copy this software for any purpose is hereby granted 10 1.2 christos * without fee. Permission to modify the code and to distribute modified 11 1.2 christos * code is also granted without any restrictions. 12 1.2 christos */ 13 1.1 christos 14 1.1 christos #include <sys/cdefs.h> 15 1.1 christos #if defined(LIBC_SCCS) && !defined(lint) 16 1.4 joerg __RCSID("$NetBSD: wcscasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $"); 17 1.1 christos #endif /* LIBC_SCCS and not lint */ 18 1.1 christos 19 1.1 christos #include "namespace.h" 20 1.1 christos #include <assert.h> 21 1.1 christos #include <wchar.h> 22 1.1 christos #include <wctype.h> 23 1.3 joerg #include <locale.h> 24 1.3 joerg #include "setlocale_local.h" 25 1.1 christos 26 1.1 christos __weak_alias(wcscasecmp,_wcscasecmp) 27 1.3 joerg __weak_alias(wcscasecmp_l,_wcscasecmp_l) 28 1.1 christos 29 1.1 christos int 30 1.3 joerg wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t loc) 31 1.1 christos { 32 1.1 christos int lc1 = 0; 33 1.1 christos int lc2 = 0; 34 1.1 christos int diff = 0; 35 1.1 christos 36 1.1 christos _DIAGASSERT(s1); 37 1.1 christos _DIAGASSERT(s2); 38 1.1 christos 39 1.1 christos for (;;) { 40 1.3 joerg lc1 = towlower_l(*s1, loc); 41 1.3 joerg lc2 = towlower_l(*s2, loc); 42 1.1 christos 43 1.1 christos diff = lc1 - lc2; 44 1.1 christos if (diff) 45 1.1 christos return diff; 46 1.1 christos 47 1.1 christos if (!lc1) 48 1.1 christos return 0; 49 1.1 christos 50 1.1 christos ++s1; 51 1.1 christos ++s2; 52 1.1 christos } 53 1.1 christos } 54 1.3 joerg 55 1.3 joerg int 56 1.3 joerg wcscasecmp(const wchar_t *s1, const wchar_t *s2) 57 1.3 joerg { 58 1.4 joerg return wcscasecmp_l(s1, s2, _current_locale()); 59 1.3 joerg } 60