2013-12-06 12:04:52 +01:00
|
|
|
/* $NetBSD: wcsncasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $ */
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Aleksey Cheusov
|
|
|
|
*
|
|
|
|
* This material is provided "as is", with absolutely no warranty expressed
|
|
|
|
* or implied. Any use is at your own risk.
|
|
|
|
*
|
|
|
|
* Permission to use or copy this software for any purpose is hereby granted
|
|
|
|
* without fee. Permission to modify the code and to distribute modified
|
|
|
|
* code is also granted without any restrictions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2013-12-06 12:04:52 +01:00
|
|
|
__RCSID("$NetBSD: wcsncasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $");
|
2011-02-14 20:36:03 +01:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <wctype.h>
|
2013-12-06 12:04:52 +01:00
|
|
|
#include <locale.h>
|
|
|
|
#include "setlocale_local.h"
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
__weak_alias(wcsncasecmp,_wcsncasecmp)
|
2013-12-06 12:04:52 +01:00
|
|
|
__weak_alias(wcsncasecmp_l,_wcsncasecmp_l)
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
int
|
2013-12-06 12:04:52 +01:00
|
|
|
wcsncasecmp_l(const wchar_t *s1, const wchar_t *s2, size_t n, locale_t loc)
|
2011-02-14 20:36:03 +01:00
|
|
|
{
|
|
|
|
int lc1 = 0;
|
|
|
|
int lc2 = 0;
|
|
|
|
int diff = 0;
|
|
|
|
|
|
|
|
_DIAGASSERT(s1);
|
|
|
|
_DIAGASSERT(s2);
|
|
|
|
|
|
|
|
while (n--) {
|
2013-12-06 12:04:52 +01:00
|
|
|
lc1 = towlower_l(*s1, loc);
|
|
|
|
lc2 = towlower_l(*s2, loc);
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
diff = lc1 - lc2;
|
|
|
|
if (diff)
|
|
|
|
return diff;
|
|
|
|
|
|
|
|
if (!lc1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
++s1;
|
|
|
|
++s2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-06 12:04:52 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
|
|
|
|
{
|
|
|
|
return wcsncasecmp_l(s1, s2, n, _current_locale());
|
|
|
|
}
|