Skip to content

Commit 2ab0d35

Browse files
committed
nl_langinfo(): minimal implementation
1 parent 77bdf31 commit 2ab0d35

File tree

6 files changed

+298
-0
lines changed

6 files changed

+298
-0
lines changed

include/MISCFILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ MISCFILES = 00README COPYMINT COPYING COPYING.LIB MISCFILES \
3636
ifaddrs.h \
3737
inttypes.h \
3838
iovec.h \
39+
langinfo.h \
3940
lastlog.h \
4041
libgen.h \
4142
limits.h \
@@ -48,6 +49,7 @@ MISCFILES = 00README COPYMINT COPYING COPYING.LIB MISCFILES \
4849
mintbind.h \
4950
mntent.h \
5051
netdb.h \
52+
nl_types.h \
5153
obstack.h \
5254
osbind.h \
5355
paths.h \

include/langinfo.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
* SUCH DAMAGE.
27+
*/
28+
#ifndef _LANGINFO_H_
29+
#define _LANGINFO_H_
30+
#include <sys/cdefs.h>
31+
#include <nl_types.h>
32+
struct __locale_t;
33+
typedef struct __locale_t* locale_t;
34+
__BEGIN_DECLS
35+
#define CODESET 1
36+
#define D_T_FMT 2
37+
#define D_FMT 3
38+
#define T_FMT 4
39+
#define T_FMT_AMPM 5
40+
#define AM_STR 6
41+
#define PM_STR 7
42+
#define DAY_1 8
43+
#define DAY_2 9
44+
#define DAY_3 10
45+
#define DAY_4 11
46+
#define DAY_5 12
47+
#define DAY_6 13
48+
#define DAY_7 14
49+
#define ABDAY_1 15
50+
#define ABDAY_2 16
51+
#define ABDAY_3 17
52+
#define ABDAY_4 18
53+
#define ABDAY_5 19
54+
#define ABDAY_6 20
55+
#define ABDAY_7 21
56+
#define MON_1 22
57+
#define MON_2 23
58+
#define MON_3 24
59+
#define MON_4 25
60+
#define MON_5 26
61+
#define MON_6 27
62+
#define MON_7 28
63+
#define MON_8 29
64+
#define MON_9 30
65+
#define MON_10 31
66+
#define MON_11 32
67+
#define MON_12 33
68+
#define ABMON_1 34
69+
#define ABMON_2 35
70+
#define ABMON_3 36
71+
#define ABMON_4 37
72+
#define ABMON_5 38
73+
#define ABMON_6 39
74+
#define ABMON_7 40
75+
#define ABMON_8 41
76+
#define ABMON_9 42
77+
#define ABMON_10 43
78+
#define ABMON_11 44
79+
#define ABMON_12 45
80+
#define ERA 46
81+
#define ERA_D_FMT 47
82+
#define ERA_D_T_FMT 48
83+
#define ERA_T_FMT 49
84+
#define ALT_DIGITS 50
85+
#define RADIXCHAR 51
86+
#define THOUSEP 52
87+
#define YESEXPR 53
88+
#define NOEXPR 54
89+
#define CRNCYSTR 55
90+
char* nl_langinfo(nl_item __item);
91+
char* nl_langinfo_l(nl_item __item, locale_t __l);
92+
__END_DECLS
93+
#endif

include/nl_types.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
* SUCH DAMAGE.
27+
*/
28+
#pragma once
29+
/**
30+
* @file nl_types.h
31+
* @brief Message catalogs.
32+
*
33+
* Android offers a no-op implementation of these functions to ease porting of historical software.
34+
*/
35+
#include <sys/cdefs.h>
36+
__BEGIN_DECLS
37+
/**
38+
* catopen() flag to use the current locale.
39+
*/
40+
#define NL_CAT_LOCALE 1
41+
/**
42+
* catgets() default set number.
43+
*/
44+
#define NL_SETD 1
45+
/** Message catalog type. */
46+
typedef void* nl_catd;
47+
/** The type of the constants in `<langinfo.h>`, used by nl_langinfo(). */
48+
typedef int nl_item;
49+
/**
50+
* [catopen(3)](https://man7.org/linux/man-pages/man3/catopen.3.html) opens a message catalog.
51+
*/
52+
nl_catd catopen(const char* __name, int __flag);
53+
/**
54+
* [catgets(3)](https://man7.org/linux/man-pages/man3/catgets.3.html) translates the given message
55+
* using the given message catalog.
56+
*/
57+
char* catgets(nl_catd __catalog, int __set_number, int __msg_number, const char* __msg);
58+
/**
59+
* [catclose(3)](https://man7.org/linux/man-pages/man3/catclose.3.html) closes a message catalog.
60+
*/
61+
int catclose(nl_catd __catalog);
62+
__END_DECLS

posix/SRCFILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ SRCFILES = \
2222
nanosleep.c \
2323
clock_gettime.c \
2424
clock_nanosleep.c \
25+
nl_types.c \
26+
langinfo.c \
2527
posix_fallocate.c \
2628
pread.c \
2729
pwrite.c \

posix/langinfo.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
* SUCH DAMAGE.
27+
*/
28+
#include <langinfo.h>
29+
#include <stdlib.h>
30+
char* nl_langinfo(nl_item item) {
31+
const char* result = "";
32+
switch (item) {
33+
case CODESET: result = (MB_CUR_MAX == 1) ? "ASCII" : "UTF-8"; break;
34+
case D_T_FMT: result = "%F %T %z"; break;
35+
case D_FMT: result = "%F"; break;
36+
case T_FMT: result = "%T"; break;
37+
case T_FMT_AMPM: result = "%I:%M:%S %p"; break;
38+
case AM_STR: result = "AM"; break;
39+
case PM_STR: result = "PM"; break;
40+
case DAY_1: result = "Sunday"; break;
41+
case DAY_2: result = "Monday"; break;
42+
case DAY_3: result = "Tuesday"; break;
43+
case DAY_4: result = "Wednesday"; break;
44+
case DAY_5: result = "Thursday"; break;
45+
case DAY_6: result = "Friday"; break;
46+
case DAY_7: result = "Saturday"; break;
47+
case ABDAY_1: result = "Sun"; break;
48+
case ABDAY_2: result = "Mon"; break;
49+
case ABDAY_3: result = "Tue"; break;
50+
case ABDAY_4: result = "Wed"; break;
51+
case ABDAY_5: result = "Thu"; break;
52+
case ABDAY_6: result = "Fri"; break;
53+
case ABDAY_7: result = "Sat"; break;
54+
case MON_1: result = "January"; break;
55+
case MON_2: result = "February"; break;
56+
case MON_3: result = "March"; break;
57+
case MON_4: result = "April"; break;
58+
case MON_5: result = "May"; break;
59+
case MON_6: result = "June"; break;
60+
case MON_7: result = "July"; break;
61+
case MON_8: result = "August"; break;
62+
case MON_9: result = "September"; break;
63+
case MON_10: result = "October"; break;
64+
case MON_11: result = "November"; break;
65+
case MON_12: result = "December"; break;
66+
case ABMON_1: result = "Jan"; break;
67+
case ABMON_2: result = "Feb"; break;
68+
case ABMON_3: result = "Mar"; break;
69+
case ABMON_4: result = "Apr"; break;
70+
case ABMON_5: result = "May"; break;
71+
case ABMON_6: result = "Jun"; break;
72+
case ABMON_7: result = "Jul"; break;
73+
case ABMON_8: result = "Aug"; break;
74+
case ABMON_9: result = "Sep"; break;
75+
case ABMON_10: result = "Oct"; break;
76+
case ABMON_11: result = "Nov"; break;
77+
case ABMON_12: result = "Dec"; break;
78+
case ERA: result = ""; break;
79+
case ERA_D_FMT: result = ""; break;
80+
case ERA_D_T_FMT: result = ""; break;
81+
case ERA_T_FMT: result = ""; break;
82+
case ALT_DIGITS: result = ""; break;
83+
case RADIXCHAR: result = "."; break;
84+
case THOUSEP: result = ""; break;
85+
case YESEXPR: result = "^[yY]"; break;
86+
case NOEXPR: result = "^[nN]"; break;
87+
case CRNCYSTR: result = ""; break;
88+
default: break;
89+
}
90+
return (char*)result;
91+
}
92+
char* nl_langinfo_l(nl_item item, locale_t l) {
93+
return nl_langinfo(item);
94+
}

posix/nl_types.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
* SUCH DAMAGE.
27+
*/
28+
29+
#include <nl_types.h>
30+
#include <errno.h>
31+
32+
nl_catd catopen(const char *name, int flag) {
33+
return (nl_catd)(-1);
34+
}
35+
36+
char *catgets(nl_catd catalog, int set_number, int message_number,
37+
const char *message ){
38+
return (char*)message;
39+
}
40+
41+
int catclose(nl_catd catalog) {
42+
// Since we didn't hand out a valid nl_catd, you can't be returning one to us.
43+
errno = EBADF;
44+
return -1;
45+
}

0 commit comments

Comments
 (0)