| 1 |
/** |
| 2 |
* D header file for C99. |
| 3 |
* |
| 4 |
* $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_wchar.h.html, _wchar.h) |
| 5 |
* |
| 6 |
* Copyright: Copyright Sean Kelly 2005 - 2009. |
| 7 |
* License: Distributed under the |
| 8 |
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). |
| 9 |
* (See accompanying file LICENSE) |
| 10 |
* Authors: Sean Kelly |
| 11 |
* Source: $(DRUNTIMESRC core/stdc/_wchar_.d) |
| 12 |
* Standards: ISO/IEC 9899:1999 (E) |
| 13 |
*/ |
| 14 |
|
| 15 |
module core.stdc.wchar_; |
| 16 |
|
| 17 |
import core.stdc.config; |
| 18 |
import core.stdc.stdarg; // for va_list |
| 19 |
import core.stdc.stdio; // for FILE, not exposed per spec |
| 20 |
import core.atomic : atomicLoad; |
| 21 |
public import core.stdc.stddef; // for wchar_t |
| 22 |
public import core.stdc.time; // for tm |
| 23 |
public import core.stdc.stdint; // for WCHAR_MIN, WCHAR_MAX |
| 24 |
|
| 25 |
extern (C): |
| 26 |
nothrow: |
| 27 |
@nogc: |
| 28 |
|
| 29 |
version (CRuntime_Glibc) |
| 30 |
{ |
| 31 |
/// |
| 32 |
struct mbstate_t |
| 33 |
{ |
| 34 |
int __count; |
| 35 |
union ___value |
| 36 |
{ |
| 37 |
wint_t __wch = 0; |
| 38 |
char[4] __wchb; |
| 39 |
} |
| 40 |
___value __value; |
| 41 |
} |
| 42 |
} |
| 43 |
else version (FreeBSD) |
| 44 |
{ |
| 45 |
/// |
| 46 |
union __mbstate_t // <sys/_types.h> |
| 47 |
{ |
| 48 |
char[128] _mbstate8 = 0; |
| 49 |
long _mbstateL; |
| 50 |
} |
| 51 |
|
| 52 |
/// |
| 53 |
alias mbstate_t = __mbstate_t; |
| 54 |
} |
| 55 |
else version (NetBSD) |
| 56 |
{ |
| 57 |
/// |
| 58 |
union __mbstate_t |
| 59 |
{ |
| 60 |
int64_t __mbstateL; |
| 61 |
char[128] __mbstate8; |
| 62 |
} |
| 63 |
|
| 64 |
/// |
| 65 |
alias mbstate_t = __mbstate_t; |
| 66 |
} |
| 67 |
else version (OpenBSD) |
| 68 |
{ |
| 69 |
/// |
| 70 |
union __mbstate_t |
| 71 |
{ |
| 72 |
char[128] __mbstate8 = 0; |
| 73 |
int64_t __mbstateL; |
| 74 |
} |
| 75 |
|
| 76 |
/// |
| 77 |
alias mbstate_t = __mbstate_t; |
| 78 |
} |
| 79 |
else version (DragonFlyBSD) |
| 80 |
{ |
| 81 |
/// |
| 82 |
union __mbstate_t // <sys/stdint.h> |
| 83 |
{ |
| 84 |
char[128] _mbstate8 = 0; |
| 85 |
long _mbstateL; |
| 86 |
} |
| 87 |
|
| 88 |
/// |
| 89 |
alias mbstate_t = __mbstate_t; |
| 90 |
} |
| 91 |
else version (Solaris) |
| 92 |
{ |
| 93 |
/// |
| 94 |
struct __mbstate_t |
| 95 |
{ |
| 96 |
version (D_LP64) |
| 97 |
{ |
| 98 |
long[4] __filler; |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
int[6] __filler; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
/// |
| 107 |
alias mbstate_t = __mbstate_t; |
| 108 |
} |
| 109 |
else version (CRuntime_Newlib) |
| 110 |
{ |
| 111 |
/// |
| 112 |
struct mbstate_t |
| 113 |
{ |
| 114 |
int __count; |
| 115 |
union ___value |
| 116 |
{ |
| 117 |
wint_t __wch = 0; |
| 118 |
char[4] __wchb; |
| 119 |
} |
| 120 |
___value __value; |
| 121 |
} |
| 122 |
} |
| 123 |
else version (CRuntime_UClibc) |
| 124 |
{ |
| 125 |
/// |
| 126 |
struct mbstate_t |
| 127 |
{ |
| 128 |
wchar_t __mask = 0; |
| 129 |
wchar_t __wc = 0; |
| 130 |
} |
| 131 |
} |
| 132 |
else |
| 133 |
{ |
| 134 |
/// |
| 135 |
alias int mbstate_t; |
| 136 |
} |
| 137 |
|
| 138 |
/// |
| 139 |
alias wchar_t wint_t; |
| 140 |
|
| 141 |
/// |
| 142 |
enum wchar_t WEOF = 0xFFFF; |
| 143 |
|
| 144 |
version (CRuntime_Glibc) |
| 145 |
{ |
| 146 |
/// |
| 147 |
int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...); |
| 148 |
/// |
| 149 |
int __isoc99_fwscanf(FILE* stream, const scope wchar_t* format, scope ...); |
| 150 |
/// |
| 151 |
alias fwscanf = __isoc99_fwscanf; |
| 152 |
/// |
| 153 |
int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...); |
| 154 |
/// |
| 155 |
int __isoc99_swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...); |
| 156 |
/// |
| 157 |
alias swscanf = __isoc99_swscanf; |
| 158 |
/// |
| 159 |
int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg); |
| 160 |
/// |
| 161 |
int __isoc99_vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg); |
| 162 |
/// |
| 163 |
alias vfwscanf = __isoc99_vfwscanf; |
| 164 |
/// |
| 165 |
int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg); |
| 166 |
/// |
| 167 |
int __isoc99_vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg); |
| 168 |
/// |
| 169 |
alias vswscanf = __isoc99_vswscanf; |
| 170 |
/// |
| 171 |
int vwprintf(const scope wchar_t* format, va_list arg); |
| 172 |
/// |
| 173 |
int __isoc99_vwscanf(const scope wchar_t* format, va_list arg); |
| 174 |
/// |
| 175 |
alias vwscanf = __isoc99_vwscanf; |
| 176 |
/// |
| 177 |
int wprintf(const scope wchar_t* format, scope const ...); |
| 178 |
/// |
| 179 |
int __isoc99_wscanf(const scope wchar_t* format, scope ...); |
| 180 |
/// |
| 181 |
alias wscanf = __isoc99_wscanf; |
| 182 |
} |
| 183 |
else |
| 184 |
{ |
| 185 |
/// |
| 186 |
int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...); |
| 187 |
/// |
| 188 |
int fwscanf(FILE* stream, const scope wchar_t* format, scope ...); |
| 189 |
/// |
| 190 |
int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...); |
| 191 |
/// |
| 192 |
int swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...); |
| 193 |
/// |
| 194 |
int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg); |
| 195 |
/// |
| 196 |
int vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg); |
| 197 |
/// |
| 198 |
int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg); |
| 199 |
/// |
| 200 |
int vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg); |
| 201 |
/// |
| 202 |
int vwprintf(const scope wchar_t* format, va_list arg); |
| 203 |
/// |
| 204 |
int vwscanf(const scope wchar_t* format, va_list arg); |
| 205 |
/// |
| 206 |
int wprintf(const scope wchar_t* format, scope const ...); |
| 207 |
/// |
| 208 |
int wscanf(const scope wchar_t* format, scope ...); |
| 209 |
} |
| 210 |
|
| 211 |
// No unsafe pointer manipulation. |
| 212 |
@trusted |
| 213 |
{ |
| 214 |
/// |
| 215 |
wint_t fgetwc(FILE* stream); |
| 216 |
/// |
| 217 |
wint_t fputwc(wchar_t c, FILE* stream); |
| 218 |
} |
| 219 |
|
| 220 |
/// |
| 221 |
wchar_t* fgetws(wchar_t* s, int n, FILE* stream); |
| 222 |
/// |
| 223 |
int fputws(const scope wchar_t* s, FILE* stream); |
| 224 |
|
| 225 |
// No unsafe pointer manipulation. |
| 226 |
extern (D) @trusted |
| 227 |
{ |
| 228 |
/// |
| 229 |
wint_t getwchar() { return fgetwc(atomicLoad(stdin)); } |
| 230 |
/// |
| 231 |
wint_t putwchar(wchar_t c) { return fputwc(c,atomicLoad(stdout)); } |
| 232 |
} |
| 233 |
|
| 234 |
/// |
| 235 |
alias getwc = fgetwc; |
| 236 |
/// |
| 237 |
alias putwc = fputwc; |
| 238 |
|
| 239 |
// No unsafe pointer manipulation. |
| 240 |
@trusted |
| 241 |
{ |
| 242 |
/// |
| 243 |
wint_t ungetwc(wint_t c, FILE* stream); |
| 244 |
/// |
| 245 |
version (CRuntime_Microsoft) |
| 246 |
{ |
| 247 |
// MSVC defines this as an inline function. |
| 248 |
int fwide(FILE* stream, int mode) { return mode; } |
| 249 |
} |
| 250 |
else |
| 251 |
{ |
| 252 |
int fwide(FILE* stream, int mode); |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
/// |
| 257 |
double wcstod(const scope wchar_t* nptr, wchar_t** endptr); |
| 258 |
/// |
| 259 |
float wcstof(const scope wchar_t* nptr, wchar_t** endptr); |
| 260 |
/// |
| 261 |
real wcstold(const scope wchar_t* nptr, wchar_t** endptr); |
| 262 |
/// |
| 263 |
c_long wcstol(const scope wchar_t* nptr, wchar_t** endptr, int base); |
| 264 |
/// |
| 265 |
long wcstoll(const scope wchar_t* nptr, wchar_t** endptr, int base); |
| 266 |
/// |
| 267 |
c_ulong wcstoul(const scope wchar_t* nptr, wchar_t** endptr, int base); |
| 268 |
/// |
| 269 |
ulong wcstoull(const scope wchar_t* nptr, wchar_t** endptr, int base); |
| 270 |
|
| 271 |
/// |
| 272 |
pure wchar_t* wcscpy(return scope wchar_t* s1, scope const wchar_t* s2); |
| 273 |
/// |
| 274 |
pure wchar_t* wcsncpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 275 |
/// |
| 276 |
pure wchar_t* wcscat(return scope wchar_t* s1, scope const wchar_t* s2); |
| 277 |
/// |
| 278 |
pure wchar_t* wcsncat(return scope wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 279 |
/// |
| 280 |
pure int wcscmp(scope const wchar_t* s1, scope const wchar_t* s2); |
| 281 |
/// |
| 282 |
int wcscoll(scope const wchar_t* s1, scope const wchar_t* s2); |
| 283 |
/// |
| 284 |
pure int wcsncmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 285 |
/// |
| 286 |
size_t wcsxfrm(scope wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 287 |
/// |
| 288 |
pure inout(wchar_t)* wcschr(return scope inout(wchar_t)* s, wchar_t c); |
| 289 |
/// |
| 290 |
pure size_t wcscspn(scope const wchar_t* s1, scope const wchar_t* s2); |
| 291 |
/// |
| 292 |
pure inout(wchar_t)* wcspbrk(return scope inout(wchar_t)* s1, scope const wchar_t* s2); |
| 293 |
/// |
| 294 |
pure inout(wchar_t)* wcsrchr(return scope inout(wchar_t)* s, wchar_t c); |
| 295 |
/// |
| 296 |
pure size_t wcsspn(scope const wchar_t* s1, scope const wchar_t* s2); |
| 297 |
/// |
| 298 |
pure inout(wchar_t)* wcsstr(return scope inout(wchar_t)* s1, scope const wchar_t* s2); |
| 299 |
/// |
| 300 |
wchar_t* wcstok(return scope wchar_t* s1, scope const wchar_t* s2, wchar_t** ptr); |
| 301 |
/// |
| 302 |
pure size_t wcslen(scope const wchar_t* s); |
| 303 |
|
| 304 |
/// |
| 305 |
pure inout(wchar_t)* wmemchr(return scope inout wchar_t* s, wchar_t c, size_t n); |
| 306 |
/// |
| 307 |
pure int wmemcmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 308 |
/// |
| 309 |
pure wchar_t* wmemcpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 310 |
/// |
| 311 |
pure wchar_t* wmemmove(return scope wchar_t* s1, scope const wchar_t* s2, size_t n); |
| 312 |
/// |
| 313 |
pure wchar_t* wmemset(return scope wchar_t* s, wchar_t c, size_t n); |
| 314 |
|
| 315 |
/// |
| 316 |
size_t wcsftime(wchar_t* s, size_t maxsize, const scope wchar_t* format, const scope tm* timeptr); |
| 317 |
|
| 318 |
version (Windows) |
| 319 |
{ |
| 320 |
/// |
| 321 |
wchar_t* _wasctime(tm*); // non-standard |
| 322 |
/// |
| 323 |
wchar_t* _wctime(time_t*); // non-standard |
| 324 |
/// |
| 325 |
wchar_t* _wstrdate(wchar_t*); // non-standard |
| 326 |
/// |
| 327 |
wchar_t* _wstrtime(wchar_t*); // non-standard |
| 328 |
} |
| 329 |
|
| 330 |
// No unsafe pointer manipulation. |
| 331 |
@trusted |
| 332 |
{ |
| 333 |
/// |
| 334 |
wint_t btowc(int c); |
| 335 |
/// |
| 336 |
int wctob(wint_t c); |
| 337 |
} |
| 338 |
|
| 339 |
/// |
| 340 |
int mbsinit(const scope mbstate_t* ps); |
| 341 |
/// |
| 342 |
size_t mbrlen(const scope char* s, size_t n, mbstate_t* ps); |
| 343 |
/// |
| 344 |
size_t mbrtowc(wchar_t* pwc, const scope char* s, size_t n, mbstate_t* ps); |
| 345 |
/// |
| 346 |
size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps); |
| 347 |
/// |
| 348 |
size_t mbsrtowcs(wchar_t* dst, const scope char** src, size_t len, mbstate_t* ps); |
| 349 |
/// |
| 350 |
size_t wcsrtombs(char* dst, const scope wchar_t** src, size_t len, mbstate_t* ps); |