Line | Count | Source (jump to first uncovered line) |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * |
3 | | * Copyright 2020 Evan Miller |
4 | | * |
5 | | * This file is part of libxls -- A multiplatform, C/C++ library for parsing |
6 | | * Excel(TM) files. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions are met: |
10 | | * |
11 | | * 1. Redistributions of source code must retain the above copyright notice, |
12 | | * this list of conditions and the following disclaimer. |
13 | | * |
14 | | * 2. Redistributions in binary form must reproduce the above copyright |
15 | | * notice, this list of conditions and the following disclaimer in the |
16 | | * documentation and/or other materials provided with the distribution. |
17 | | * |
18 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS |
19 | | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
20 | | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR |
22 | | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
23 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
24 | | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
25 | | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
26 | | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
27 | | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
28 | | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | | * |
30 | | */ |
31 | | #include "config.h" |
32 | | #include <stdlib.h> |
33 | | #include "../include/libxls/locale.h" |
34 | | |
35 | 11.5k | xls_locale_t xls_createlocale() { |
36 | | #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || defined(WINDOWS) |
37 | | return _create_locale(LC_CTYPE, ".65001"); |
38 | | #else |
39 | 11.5k | return newlocale(LC_CTYPE_MASK, "C.UTF-8", NULL); |
40 | 11.5k | #endif |
41 | 11.5k | } |
42 | | |
43 | 11.5k | void xls_freelocale(xls_locale_t locale) { |
44 | 11.5k | if (!locale) |
45 | 0 | return; |
46 | | #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || defined(WINDOWS) |
47 | | _free_locale(locale); |
48 | | #else |
49 | 11.5k | freelocale(locale); |
50 | 11.5k | #endif |
51 | 11.5k | } |
52 | | |
53 | 15.9k | size_t xls_wcstombs_l(char *restrict s, const wchar_t *restrict pwcs, size_t n, xls_locale_t loc) { |
54 | | #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || defined(WINDOWS) |
55 | | return _wcstombs_l(s, pwcs, n, loc); |
56 | | #elif defined(HAVE_WCSTOMBS_L) |
57 | | return wcstombs_l(s, pwcs, n, loc); |
58 | | #else |
59 | 15.9k | locale_t oldlocale = uselocale(loc); |
60 | 15.9k | size_t result = wcstombs(s, pwcs, n); |
61 | 15.9k | uselocale(oldlocale); |
62 | 15.9k | return result; |
63 | 15.9k | #endif |
64 | 15.9k | } |