1 /*
2  * Support functions
3  *
4  * Copyright (C) 2009-2020, Joachim Metz <joachim.metz@gmail.com>
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 #include "libbfio_definitions.h"
26 #include "libbfio_libcerror.h"
27 #include "libbfio_libclocale.h"
28 #include "libbfio_support.h"
29 
30 #if !defined( HAVE_LOCAL_LIBBFIO )
31 
32 /* Returns the library version as a string
33  */
libbfio_get_version(void)34 const char *libbfio_get_version(
35              void )
36 {
37 	return( (const char *) LIBBFIO_VERSION_STRING );
38 }
39 
40 /* Retrieves the narrow system string codepage
41  * A value of 0 represents no codepage, UTF-8 encoding is used instead
42  * Returns 1 if successful or -1 on error
43  */
libbfio_get_codepage(int * codepage,libcerror_error_t ** error)44 int libbfio_get_codepage(
45      int *codepage,
46      libcerror_error_t **error )
47 {
48 	static char *function = "libbfio_get_codepage";
49 
50 	if( libclocale_codepage_get(
51 	     codepage,
52 	     error ) != 1 )
53 	{
54 		libcerror_error_set(
55 		 error,
56 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
57 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
58 		 "%s: unable to retrieve codepage.",
59 		 function );
60 
61 		return( -1 );
62 	}
63 	return( 1 );
64 }
65 
66 /* Sets the narrow system string codepage
67  * A value of 0 represents no codepage, UTF-8 encoding is used instead
68  * Returns 1 if successful or -1 on error
69  */
libbfio_set_codepage(int codepage,libcerror_error_t ** error)70 int libbfio_set_codepage(
71      int codepage,
72      libcerror_error_t **error )
73 {
74 	static char *function = "libbfio_set_codepage";
75 
76 	if( libclocale_codepage_set(
77 	     codepage,
78 	     error ) != 1 )
79 	{
80 		libcerror_error_set(
81 		 error,
82 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
83 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
84 		 "%s: unable to set codepage.",
85 		 function );
86 
87 		return( -1 );
88 	}
89 	return( 1 );
90 }
91 
92 #endif /* !defined( HAVE_LOCAL_LIBBFIO ) */
93 
94