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