1a3f66598SOliver Tappe /*
2a3f66598SOliver Tappe * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
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" size_t
strxfrm(char * out,const char * in,size_t size)20a3f66598SOliver Tappe strxfrm(char *out, const char *in, size_t size)
21a3f66598SOliver Tappe {
22*d338200eSTrung Nguyen LocaleBackend* backend = GetCurrentLocaleBackend();
23*d338200eSTrung Nguyen
24*d338200eSTrung Nguyen if (backend != NULL) {
25a3f66598SOliver Tappe size_t outSize = 0;
26*d338200eSTrung Nguyen status_t status = backend->Strxfrm(out, in, size, outSize);
27*d338200eSTrung Nguyen
28*d338200eSTrung Nguyen if (status != B_OK)
29*d338200eSTrung Nguyen __set_errno(EINVAL);
30*d338200eSTrung Nguyen
31*d338200eSTrung Nguyen return outSize;
32*d338200eSTrung Nguyen }
33*d338200eSTrung Nguyen
34*d338200eSTrung Nguyen return strlcpy(out, in, size);
35*d338200eSTrung Nguyen }
36*d338200eSTrung Nguyen
37*d338200eSTrung Nguyen
38*d338200eSTrung Nguyen extern "C" size_t
strxfrm_l(char * out,const char * in,size_t size,locale_t l)39*d338200eSTrung Nguyen strxfrm_l(char *out, const char *in, size_t size, 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 size_t outSize = 0;
46*d338200eSTrung Nguyen status_t status = backend->Strxfrm(out, in, size, outSize);
47a3f66598SOliver Tappe
48a3f66598SOliver Tappe if (status != B_OK)
49ae901935SOliver Tappe __set_errno(EINVAL);
50a3f66598SOliver Tappe
51a3f66598SOliver Tappe return outSize;
52a3f66598SOliver Tappe }
53a3f66598SOliver Tappe
54a3f66598SOliver Tappe return strlcpy(out, in, size);
55a3f66598SOliver Tappe }
56