Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 4af1eed

Browse files
authored
Merge pull request #2789 from Geod24/ocean
POSIX: Add core.sys.posix.{string,strings,locale} merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 891eaf7 + a2a88cf commit 4af1eed

File tree

7 files changed

+307
-66
lines changed

7 files changed

+307
-66
lines changed

mak/COPY

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ COPY=\
205205
$(IMPDIR)\core\sys\posix\iconv.d \
206206
$(IMPDIR)\core\sys\posix\inttypes.d \
207207
$(IMPDIR)\core\sys\posix\libgen.d \
208+
$(IMPDIR)\core\sys\posix\locale.d \
208209
$(IMPDIR)\core\sys\posix\netdb.d \
209210
$(IMPDIR)\core\sys\posix\poll.d \
210211
$(IMPDIR)\core\sys\posix\pthread.d \
@@ -216,6 +217,8 @@ COPY=\
216217
$(IMPDIR)\core\sys\posix\spawn.d \
217218
$(IMPDIR)\core\sys\posix\stdio.d \
218219
$(IMPDIR)\core\sys\posix\stdlib.d \
220+
$(IMPDIR)\core\sys\posix\string.d \
221+
$(IMPDIR)\core\sys\posix\strings.d \
219222
$(IMPDIR)\core\sys\posix\syslog.d \
220223
$(IMPDIR)\core\sys\posix\termios.d \
221224
$(IMPDIR)\core\sys\posix\time.d \

mak/SRCS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ SRCS=\
203203
src\core\sys\posix\iconv.d \
204204
src\core\sys\posix\inttypes.d \
205205
src\core\sys\posix\libgen.d \
206+
src\core\sys\posix\locale.d \
206207
src\core\sys\posix\netdb.d \
207208
src\core\sys\posix\poll.d \
208209
src\core\sys\posix\pthread.d \
@@ -214,6 +215,8 @@ SRCS=\
214215
src\core\sys\posix\spawn.d \
215216
src\core\sys\posix\stdio.d \
216217
src\core\sys\posix\stdlib.d \
218+
src\core\sys\posix\string.d \
219+
src\core\sys\posix\strings.d \
217220
src\core\sys\posix\syslog.d \
218221
src\core\sys\posix\termios.d \
219222
src\core\sys\posix\time.d \

mak/WINDOWS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ $(IMPDIR)\core\sys\posix\inttypes.d : src\core\sys\posix\inttypes.d
603603
$(IMPDIR)\core\sys\posix\libgen.d : src\core\sys\posix\libgen.d
604604
copy $** $@
605605

606+
$(IMPDIR)\core\sys\posix\locale.d : src\core\sys\posix\locale.d
607+
copy $** $@
608+
606609
$(IMPDIR)\core\sys\posix\netdb.d : src\core\sys\posix\netdb.d
607610
copy $** $@
608611

@@ -645,6 +648,12 @@ $(IMPDIR)\core\sys\posix\stdio.d : src\core\sys\posix\stdio.d
645648
$(IMPDIR)\core\sys\posix\stdlib.d : src\core\sys\posix\stdlib.d
646649
copy $** $@
647650

651+
$(IMPDIR)\core\sys\posix\string.d : src\core\sys\posix\string.d
652+
copy $** $@
653+
654+
$(IMPDIR)\core\sys\posix\strings.d : src\core\sys\posix\strings.d
655+
copy $** $@
656+
648657
$(IMPDIR)\core\sys\posix\syslog.d : src\core\sys\posix\syslog.d
649658
copy $** $@
650659

src/core/stdc/string.d

Lines changed: 39 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,104 +23,77 @@ else version (TVOS)
2323
else version (WatchOS)
2424
version = Darwin;
2525

26+
// Those libs don't expose the mandated C interface
27+
version (CRuntime_Glibc)
28+
version = ReturnStrerrorR;
29+
else version (CRuntime_UClibc)
30+
version = ReturnStrerrorR;
31+
2632
extern (C):
2733
@system:
2834
nothrow:
2935
@nogc:
3036

3137
///
32-
pure void* memchr(return const void* s, int c, size_t n);
38+
void* memchr(return const void* s, int c, size_t n) pure;
3339
///
34-
pure int memcmp(scope const void* s1, scope const void* s2, size_t n);
40+
int memcmp(scope const void* s1, scope const void* s2, size_t n) pure;
3541
///
36-
pure void* memcpy(return void* s1, scope const void* s2, size_t n);
42+
void* memcpy(return void* s1, scope const void* s2, size_t n) pure;
3743
version (Windows)
3844
{
3945
///
4046
int memicmp(scope const char* s1, scope const char* s2, size_t n);
4147
}
4248
///
43-
pure void* memmove(return void* s1, scope const void* s2, size_t n);
49+
void* memmove(return void* s1, scope const void* s2, size_t n) pure;
4450
///
45-
pure void* memset(return void* s, int c, size_t n);
51+
void* memset(return void* s, int c, size_t n) pure;
4652

4753
///
48-
pure char* strcpy(return char* s1, scope const char* s2);
49-
///
50-
pure char* strncpy(return char* s1, scope const char* s2, size_t n);
54+
char* strcat(return char* s1, scope const char* s2) pure;
5155
///
52-
pure char* strcat(return char* s1, scope const char* s2);
56+
inout(char)* strchr(return inout(char)* s, int c) pure;
5357
///
54-
pure char* strncat(return char* s1, scope const char* s2, size_t n);
55-
///
56-
pure int strcmp(scope const char* s1, scope const char* s2);
58+
int strcmp(scope const char* s1, scope const char* s2) pure;
5759
///
5860
int strcoll(scope const char* s1, scope const char* s2);
5961
///
60-
pure int strncmp(scope const char* s1, scope const char* s2, size_t n);
61-
///
62-
size_t strxfrm(scope char* s1, scope const char* s2, size_t n);
62+
char* strcpy(return char* s1, scope const char* s2) pure;
6363
///
64-
pure inout(char)* strchr(return inout(char)* s, int c);
64+
size_t strcspn(scope const char* s1, scope const char* s2) pure;
6565
///
66-
pure size_t strcspn(scope const char* s1, scope const char* s2);
67-
///
68-
pure inout(char)* strpbrk(return inout(char)* s1, scope const char* s2);
69-
///
70-
pure inout(char)* strrchr(return inout(char)* s, int c);
71-
///
72-
pure size_t strspn(scope const char* s1, scope const char* s2);
73-
///
74-
pure inout(char)* strstr(return inout(char)* s1, scope const char* s2);
75-
///
76-
char* strtok(return char* s1, scope const char* s2);
66+
char* strdup(scope const char *s);
7767
///
7868
char* strerror(int errnum);
79-
version (CRuntime_Glibc)
69+
// This `strerror_r` definition is not following the POSIX standard
70+
version (ReturnStrerrorR)
8071
{
8172
///
8273
const(char)* strerror_r(int errnum, return char* buf, size_t buflen);
8374
}
84-
else version (Darwin)
85-
{
86-
int strerror_r(int errnum, scope char* buf, size_t buflen);
87-
}
88-
else version (FreeBSD)
89-
{
90-
int strerror_r(int errnum, scope char* buf, size_t buflen);
91-
}
92-
else version (NetBSD)
93-
{
94-
int strerror_r(int errnum, char* buf, size_t buflen);
95-
}
96-
else version (OpenBSD)
97-
{
98-
int strerror_r(int errnum, scope char* buf, size_t buflen);
99-
}
100-
else version (DragonFlyBSD)
75+
// This one is
76+
else
10177
{
10278
int strerror_r(int errnum, scope char* buf, size_t buflen);
10379
}
104-
else version (Solaris)
105-
{
106-
int strerror_r(int errnum, scope char* buf, size_t buflen);
107-
}
108-
else version (CRuntime_Bionic)
109-
{
110-
///
111-
int strerror_r(int errnum, scope char* buf, size_t buflen);
112-
}
113-
else version (CRuntime_Musl)
114-
{
115-
///
116-
int strerror_r(int errnum, scope char *buf, size_t buflen);
117-
}
118-
else version (CRuntime_UClibc)
119-
{
120-
///
121-
const(char)* strerror_r(int errnum, return char* buf, size_t buflen);
122-
}
12380
///
124-
pure size_t strlen(scope const char* s);
81+
size_t strlen(scope const char* s) pure;
12582
///
126-
char* strdup(scope const char *s);
83+
char* strncat(return char* s1, scope const char* s2, size_t n) pure;
84+
///
85+
int strncmp(scope const char* s1, scope const char* s2, size_t n) pure;
86+
///
87+
char* strncpy(return char* s1, scope const char* s2, size_t n) pure;
88+
///
89+
inout(char)* strpbrk(return inout(char)* s1, scope const char* s2) pure;
90+
///
91+
inout(char)* strrchr(return inout(char)* s, int c) pure;
92+
///
93+
size_t strspn(scope const char* s1, scope const char* s2) pure;
94+
///
95+
inout(char)* strstr(return inout(char)* s1, scope const char* s2) pure;
96+
///
97+
char* strtok(return char* s1, scope const char* s2);
98+
///
99+
size_t strxfrm(scope char* s1, scope const char* s2, size_t n);

src/core/sys/posix/locale.d

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/**
2+
* D header file for POSIX's <locale.h>.
3+
*
4+
* See_Also: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/locale.h.html
5+
* Copyright: D Language Foundation, 2019
6+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7+
* Authors: Mathias 'Geod24' Lang
8+
* Standards: The Open Group Base Specifications Issue 7, 2018 edition
9+
* Source: $(DRUNTIMESRC core/sys/posix/_locale.d)
10+
*/
11+
module core.sys.posix.locale;
12+
13+
version (Posix):
14+
extern(C):
15+
@system:
16+
nothrow:
17+
@nogc:
18+
19+
version (OSX)
20+
version = OSXBSDLocale;
21+
version (FreeBSD)
22+
version = OSXBSDLocale;
23+
version (NetBSD)
24+
version = OSXBSDLocale;
25+
version (DragonflyBSD)
26+
version = OSXBSDLocale;
27+
28+
29+
///
30+
struct lconv
31+
{
32+
char* currency_symbol;
33+
char* decimal_point;
34+
char frac_digits;
35+
char* grouping;
36+
char* int_curr_symbol;
37+
char int_frac_digits;
38+
char int_n_cs_precedes;
39+
char int_n_sep_by_space;
40+
char int_n_sign_posn;
41+
char int_p_cs_precedes;
42+
char int_p_sep_by_space;
43+
char int_p_sign_posn;
44+
char* mon_decimal_point;
45+
char* mon_grouping;
46+
char* mon_thousands_sep;
47+
char* negative_sign;
48+
char n_cs_precedes;
49+
char n_sep_by_space;
50+
char n_sign_posn;
51+
char* positive_sign;
52+
char p_cs_precedes;
53+
char p_sep_by_space;
54+
char p_sign_posn;
55+
char* thousands_sep;
56+
}
57+
58+
/// Duplicate existing locale
59+
locale_t duplocale(locale_t locale);
60+
/// Free an allocated locale
61+
void freelocale(locale_t locale);
62+
/// Natural language formatting for C
63+
lconv* localeconv();
64+
/// Create a new locale
65+
locale_t newlocale(int mask, const char* locale, locale_t base);
66+
/// Set the C library's notion of natural language formatting style
67+
char* setlocale(int category, const char* locale);
68+
/// Set the per-thread locale
69+
locale_t uselocale (locale_t locale);
70+
71+
version (OSXBSDLocale)
72+
{
73+
///
74+
enum
75+
{
76+
LC_ALL = 0,
77+
LC_COLLATE = 1,
78+
LC_CTYPE = 2,
79+
LC_MESSAGES = 6,
80+
LC_MONETARY = 3,
81+
LC_NUMERIC = 4,
82+
LC_TIME = 5,
83+
}
84+
85+
private struct _xlocale;
86+
87+
///
88+
alias locale_t = _xlocale*;
89+
90+
version (NetBSD)
91+
enum LC_ALL_MASK = (cast(int)~0);
92+
else
93+
enum LC_ALL_MASK = (
94+
LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK |
95+
LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK);
96+
97+
98+
///
99+
enum
100+
{
101+
LC_COLLATE_MASK = (1 << 0),
102+
LC_CTYPE_MASK = (1 << 1),
103+
LC_MESSAGES_MASK = (1 << 2),
104+
LC_MONETARY_MASK = (1 << 3),
105+
LC_NUMERIC_MASK = (1 << 4),
106+
LC_TIME_MASK = (1 << 5),
107+
}
108+
109+
///
110+
enum LC_GLOBAL_LOCALE = (cast(locale_t)-1);
111+
}
112+
113+
version (linux)
114+
{
115+
///
116+
enum
117+
{
118+
LC_ALL = 6,
119+
LC_COLLATE = 3,
120+
LC_CTYPE = 0,
121+
LC_MESSAGES = 5,
122+
LC_MONETARY = 4,
123+
LC_NUMERIC = 1,
124+
LC_TIME = 2,
125+
126+
// Linux-specific
127+
LC_PAPER = 7,
128+
LC_NAME = 8,
129+
LC_ADDRESS = 9,
130+
LC_TELEPHONE = 10,
131+
LC_MEASUREMENT = 11,
132+
LC_IDENTIFICATION = 12,
133+
}
134+
135+
///
136+
enum
137+
{
138+
LC_ALL_MASK = (LC_CTYPE_MASK | LC_NUMERIC_MASK | LC_TIME_MASK |
139+
LC_COLLATE_MASK | LC_MONETARY_MASK | LC_MESSAGES_MASK |
140+
LC_PAPER_MASK | LC_NAME_MASK | LC_ADDRESS_MASK |
141+
LC_TELEPHONE_MASK | LC_MEASUREMENT_MASK |
142+
LC_IDENTIFICATION_MASK),
143+
144+
LC_COLLATE_MASK = (1 << LC_COLLATE),
145+
LC_CTYPE_MASK = (1 << LC_CTYPE),
146+
LC_MESSAGES_MASK = (1 << LC_MESSAGES),
147+
LC_MONETARY_MASK = (1 << LC_MONETARY),
148+
LC_NUMERIC_MASK = (1 << LC_NUMERIC),
149+
LC_TIME_MASK = (1 << LC_TIME),
150+
151+
// Linux specific
152+
LC_PAPER_MASK = (1 << LC_PAPER),
153+
LC_NAME_MASK = (1 << LC_NAME),
154+
LC_ADDRESS_MASK = (1 << LC_ADDRESS),
155+
LC_TELEPHONE_MASK = (1 << LC_TELEPHONE),
156+
LC_MEASUREMENT_MASK = (1 << LC_MEASUREMENT),
157+
LC_IDENTIFICATION_MASK = (1 << LC_IDENTIFICATION),
158+
}
159+
160+
private struct __locale_struct;
161+
162+
///
163+
alias locale_t = __locale_struct*;
164+
165+
///
166+
enum LC_GLOBAL_LOCALE = (cast(locale_t)-1);
167+
}

0 commit comments

Comments
 (0)