Debian Codegraph @

libclocale/libclocale_support.c

raw symbols SCIP
1 /*
2 * Support functions
3 *
4 * Copyright (C) 2010-2024, Joachim Metz <[email protected]>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <common.h>
23 #include <types.h>
24
25 #if defined( HAVE_LIBINTL_H ) && defined( ENABLE_NLS )
26 #include <libintl.h>
27 #endif
28
29 #include "libclocale_codepage.h"
30 #include "libclocale_definitions.h"
31 #include "libclocale_libcerror.h"
32 #include "libclocale_locale.h"
33 #include "libclocale_support.h"
34
35 #if !defined( HAVE_LOCAL_LIBCLOCALE )
36
37 /* Returns the library version as a string
38 */
39 const char *libclocale_get_version(
40 void )
41 {
42 return( (const char *) LIBCLOCALE_VERSION_STRING );
43 }
44
45 #endif /* !defined( HAVE_LOCAL_LIBCLOCALE ) */
46
47 /* Initializes the locale values
48 * Returns 1 if successful or -1 on error
49 */
50 int libclocale_initialize(
51 const char *domain_name,
52 libcerror_error_t **error )
53 {
54 static char *function = "libclocale_initialize";
55
56 #if !defined( HAVE_WIDE_SYSTEM_CHARACTER )
57 int codepage = 0;
58 #endif
59
60 if( domain_name == NULL )
61 {
62 libcerror_error_set(
63 error,
64 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
65 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
66 "%s: invalid domain name.",
67 function );
68
69 return( -1 );
70 }
71 #if defined( HAVE_BINDTEXTDOMAIN ) && defined( HAVE_TEXTDOMAIN ) && defined( LOCALEDIR )
72 if( bindtextdomain(
73 domain_name,
74 LOCALEDIR ) == NULL )
75 {
76 libcerror_error_set(
77 error,
78 LIBCERROR_ERROR_DOMAIN_RUNTIME,
79 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
80 "%s: unable to bind text domain.",
81 function );
82
83 return( -1 );
84 }
85 if( textdomain(
86 domain_name ) == NULL )
87 {
88 libcerror_error_set(
89 error,
90 LIBCERROR_ERROR_DOMAIN_RUNTIME,
91 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
92 "%s: unable to set text domain.",
93 function );
94
95 return( -1 );
96 }
97 #endif /* defined( HAVE_BINDTEXTDOMAIN ) && defined( HAVE_TEXTDOMAIN ) && defined( LOCALEDIR ) */
98
99 #if !defined( HAVE_WIDE_SYSTEM_CHARACTER )
100 if( libclocale_locale_get_codepage(
101 &codepage,
102 error ) != 1 )
103 {
104 libcerror_error_set(
105 error,
106 LIBCERROR_ERROR_DOMAIN_RUNTIME,
107 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
108 "%s: unable to retrieve codepage.",
109 function );
110
111 return( -1 );
112 }
113 if( libclocale_codepage_set(
114 codepage,
115 error ) != 1 )
116 {
117 libcerror_error_set(
118 error,
119 LIBCERROR_ERROR_DOMAIN_RUNTIME,
120 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
121 "%s: unable to set codepage.",
122 function );
123
124 return( -1 );
125 }
126 #endif /* !defined( HAVE_WIDE_SYSTEM_CHARACTER ) */
127
128 return( 1 );
129 }
130