xref: /haiku/src/system/libroot/posix/string/strcoll.cpp (revision 97f11716bfaa0f385eb0e28a52bf56a5023b9e99)
1a3f66598SOliver Tappe /*
2a3f66598SOliver Tappe  * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3a3f66598SOliver Tappe  * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
4a3f66598SOliver Tappe  * All rights reserved. Distributed under the terms of the MIT License.
5a3f66598SOliver Tappe  */
6a3f66598SOliver Tappe 
7a3f66598SOliver Tappe #include <errno.h>
8a3f66598SOliver Tappe #include <string.h>
9a3f66598SOliver Tappe 
10ae901935SOliver Tappe #include <errno_private.h>
11a3f66598SOliver Tappe #include "LocaleBackend.h"
12a3f66598SOliver Tappe 
13a3f66598SOliver Tappe 
14*d338200eSTrung Nguyen using BPrivate::Libroot::GetCurrentLocaleBackend;
15*d338200eSTrung Nguyen using BPrivate::Libroot::LocaleBackend;
16*d338200eSTrung Nguyen using BPrivate::Libroot::LocaleBackendData;
17a3f66598SOliver Tappe 
18a3f66598SOliver Tappe 
19a3f66598SOliver Tappe extern "C" int
strcoll(const char * a,const char * b)20a3f66598SOliver Tappe strcoll(const char *a, const char *b)
21a3f66598SOliver Tappe {
22*d338200eSTrung Nguyen 	LocaleBackend* backend = GetCurrentLocaleBackend();
23*d338200eSTrung Nguyen 
24*d338200eSTrung Nguyen 	if (backend != NULL) {
25a3f66598SOliver Tappe 		int result = 0;
26*d338200eSTrung Nguyen 		status_t status = backend->Strcoll(a, b, result);
27*d338200eSTrung Nguyen 
28*d338200eSTrung Nguyen 		if (status != B_OK)
29*d338200eSTrung Nguyen 			__set_errno(EINVAL);
30*d338200eSTrung Nguyen 
31*d338200eSTrung Nguyen 		return result;
32*d338200eSTrung Nguyen 	}
33*d338200eSTrung Nguyen 
34*d338200eSTrung Nguyen 	return strcmp(a, b);
35*d338200eSTrung Nguyen }
36*d338200eSTrung Nguyen 
37*d338200eSTrung Nguyen 
38*d338200eSTrung Nguyen extern "C" int
strcoll_l(const char * a,const char * b,locale_t l)39*d338200eSTrung Nguyen strcoll_l(const char *a, const char *b, locale_t l)
40*d338200eSTrung Nguyen {
41*d338200eSTrung Nguyen 	LocaleBackendData* locale = (LocaleBackendData*)l;
42*d338200eSTrung Nguyen 	LocaleBackend* backend = locale->backend;
43*d338200eSTrung Nguyen 
44*d338200eSTrung Nguyen 	if (backend != NULL) {
45*d338200eSTrung Nguyen 		int result = 0;
46*d338200eSTrung Nguyen 		status_t status = backend->Strcoll(a, b, result);
47a3f66598SOliver Tappe 
48a3f66598SOliver Tappe 		if (status != B_OK)
49ae901935SOliver Tappe 			__set_errno(EINVAL);
50a3f66598SOliver Tappe 
51a3f66598SOliver Tappe 		return result;
52a3f66598SOliver Tappe 	}
53a3f66598SOliver Tappe 
54a3f66598SOliver Tappe 	return strcmp(a, b);
55a3f66598SOliver Tappe }
56