xref: /haiku/src/system/libroot/posix/wchar/wcscoll.cpp (revision 52c4471a3024d2eb81fe88e2c3982b9f8daa5e56)
1 /*
2 ** Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
5 
6 #include <errno_private.h>
7 #include <LocaleBackend.h>
8 #include <wchar_private.h>
9 
10 
11 using BPrivate::Libroot::GetCurrentLocaleBackend;
12 using BPrivate::Libroot::LocaleBackend;
13 using BPrivate::Libroot::LocaleBackendData;
14 
15 
16 extern "C" int
17 __wcscoll(const wchar_t* wcs1, const wchar_t* wcs2)
18 {
19 	LocaleBackend* backend = GetCurrentLocaleBackend();
20 
21 	if (backend != NULL) {
22 		int result = 0;
23 		status_t status = backend->Wcscoll(wcs1, wcs2, result);
24 
25 		if (status != B_OK)
26 			__set_errno(EINVAL);
27 
28 		return result;
29 	}
30 
31 	return wcscmp(wcs1, wcs2);
32 }
33 
34 
35 B_DEFINE_WEAK_ALIAS(__wcscoll, wcscoll);
36 
37 
38 extern "C" int
39 __wcscoll_l(const wchar_t* wcs1, const wchar_t* wcs2, locale_t l)
40 {
41 	LocaleBackendData* locale = (LocaleBackendData*)l;
42 	LocaleBackend* backend = locale->backend;
43 
44 	if (backend != NULL) {
45 		int result = 0;
46 		status_t status = backend->Wcscoll(wcs1, wcs2, result);
47 
48 		if (status != B_OK)
49 			__set_errno(EINVAL);
50 
51 		return result;
52 	}
53 
54 	return wcscmp(wcs1, wcs2);
55 }
56 
57 
58 B_DEFINE_WEAK_ALIAS(__wcscoll_l, wcscoll_l);
59