]>
Commit | Line | Data |
---|---|---|
ab93e183 GKB |
1 | /* |
2 | * nls.h - Header for encoding support functions | |
3 | * | |
4 | * Copyright (C) 2017 Collabora Ltd. | |
5 | * | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 3 of the License, or (at | |
10 | * your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | #ifndef EXT2FS_NLS_H | |
22 | #define EXT2FS_NLS_H | |
23 | ||
24 | #include <unistd.h> | |
25 | #include <string.h> | |
26 | #include <stdio.h> | |
27 | ||
28 | #include "ext2_fs.h" | |
29 | ||
30 | struct nls_table; | |
31 | ||
32 | #define ARRAY_SIZE(array) \ | |
33 | (sizeof(array) / sizeof(array[0])) | |
34 | ||
35 | struct nls_ops { | |
ab93e183 GKB |
36 | int (*casefold)(const struct nls_table *charset, |
37 | const unsigned char *str, size_t len, | |
38 | unsigned char *dest, size_t dlen); | |
39 | }; | |
40 | ||
41 | struct nls_table { | |
42 | int version; | |
43 | const struct nls_ops *ops; | |
44 | }; | |
45 | ||
a7fba47e | 46 | extern const struct nls_table nls_utf8_12_1; |
ab93e183 GKB |
47 | |
48 | static const struct { | |
49 | int encoding_magic; | |
50 | const struct nls_table *tbl; | |
51 | } nls_map[] = { | |
a7fba47e | 52 | { EXT4_ENC_UTF8_12_1, &nls_utf8_12_1 }, |
ab93e183 GKB |
53 | }; |
54 | ||
55 | static const struct nls_table *nls_load_table(int encoding) | |
56 | { | |
57 | int i; | |
58 | ||
59 | for (i = 0; i < ARRAY_SIZE(nls_map); i++) { | |
60 | if (encoding == nls_map[i].encoding_magic) | |
61 | return nls_map[i].tbl; | |
62 | } | |
63 | return NULL; | |
64 | } | |
65 | ||
66 | #endif |