1 /** 2 * D header file for POSIX. 3 * 4 * Copyright: Public Domain 5 * License: Public Domain 6 * Authors: Sean Kelly 7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition 8 */ 9 module tango.stdc.posix.stdlib; 10 11 private import tango.stdc.posix.config; 12 public import tango.stdc.stdlib; 13 public import tango.stdc.posix.sys.wait; 14 15 extern (C): 16 17 // 18 // Required (defined in tango.stdc.stdlib) 19 // 20 /* 21 EXIT_FAILURE 22 EXIT_SUCCESS 23 NULL 24 RAND_MAX 25 MB_CUR_MAX 26 div_t 27 ldiv_t 28 lldiv_t 29 size_t 30 wchar_t 31 32 void _Exit(int); 33 void abort(); 34 int abs(int); 35 int atexit(void function()); 36 double atof(in char*); 37 int atoi(in char*); 38 c_long atol(in char*); 39 long atoll(in char*); 40 void* bsearch(in void*, in void*, size_t, size_t, int function(in void*, in void*)); 41 void* calloc(size_t, size_t); 42 div_t div(int, int); 43 void exit(int); 44 void free(void*); 45 char* getenv(in char*); 46 c_long labs(c_long); 47 ldiv_t ldiv(c_long, c_long); 48 long llabs(long); 49 lldiv_t lldiv(long, long); 50 void* malloc(size_t); 51 int mblen(in char*, size_t); 52 size_t mbstowcs(wchar_t*, in char*, size_t); 53 int mbtowc(wchar_t*, in char*, size_t); 54 void qsort(void*, size_t, size_t, int function(in void*, in void*)); 55 int rand(); 56 void* realloc(void*, size_t); 57 void srand(uint); 58 double strtod(in char*, char**); 59 float strtof(in char*, char**); 60 c_long strtol(in char*, char**, int); 61 real strtold(in char*, char**); 62 long strtoll(in char*, char**, int); 63 c_ulong strtoul(in char*, char**, int); 64 ulong strtoull(in char*, char**, int); 65 int system(in char*); 66 size_t wcstombs(char*, in wchar_t*, size_t); 67 int wctomb(char*, wchar_t); 68 */ 69 70 // 71 // Advisory Information (ADV) 72 // 73 /* 74 int posix_memalign(void**, size_t, size_t); 75 */ 76 77 version( linux ) 78 { 79 int posix_memalign(void**, size_t, size_t); 80 } 81 82 // 83 // C Extension (CX) 84 // 85 /* 86 int setenv(in char*, in char*, int); 87 int unsetenv(in char*); 88 */ 89 90 version( linux ) 91 { 92 int setenv(in char*, in char*, int); 93 int unsetenv(in char*); 94 95 void* valloc(size_t); // LEGACY non-standard 96 } 97 else version( darwin ) 98 { 99 int setenv(in char*, in char*, int); 100 int unsetenv(in char*); 101 102 void* valloc(size_t); // LEGACY non-standard 103 } 104 else version( FreeBSD ) 105 { 106 int setenv(in char*, in char*, int); 107 int unsetenv(in char*); 108 109 void* valloc(size_t); // LEGACY non-standard 110 } 111 else version( solaris ) 112 { 113 int setenv(in char*, in char*, int); 114 int unsetenv(in char*); 115 116 void* valloc(size_t); // LEGACY non-standard 117 } 118 119 // 120 // Thread-Safe Functions (TSF) 121 // 122 /* 123 int rand_r(uint*); 124 */ 125 126 version( linux ) 127 { 128 int rand_r(uint*); 129 } 130 else version( darwin ) 131 { 132 int rand_r(uint*); 133 } 134 else version( FreeBSD ) 135 { 136 int rand_r(uint*); 137 } 138 else version( solaris ) 139 { 140 int rand_r(uint*); 141 } 142 143 // 144 // XOpen (XSI) 145 // 146 /* 147 WNOHANG (defined in tango.stdc.posix.sys.wait) 148 WUNTRACED (defined in tango.stdc.posix.sys.wait) 149 WEXITSTATUS (defined in tango.stdc.posix.sys.wait) 150 WIFEXITED (defined in tango.stdc.posix.sys.wait) 151 WIFSIGNALED (defined in tango.stdc.posix.sys.wait) 152 WIFSTOPPED (defined in tango.stdc.posix.sys.wait) 153 WSTOPSIG (defined in tango.stdc.posix.sys.wait) 154 WTERMSIG (defined in tango.stdc.posix.sys.wait) 155 156 c_long a64l(in char*); 157 double drand48(); 158 char* ecvt(double, int, int *, int *); // LEGACY 159 double erand48(ushort[3]); 160 char* fcvt(double, int, int *, int *); // LEGACY 161 char* gcvt(double, int, char*); // LEGACY 162 // per spec: int getsubopt(char** char* const*, char**); 163 int getsubopt(char**, in char**, char**); 164 int grantpt(int); 165 char* initstate(uint, char*, size_t); 166 c_long jrand48(ushort[3]); 167 char* l64a(c_long); 168 void lcong48(ushort[7]); 169 c_long lrand48(); 170 char* mktemp(char*); // LEGACY 171 int mkstemp(char*); 172 c_long mrand48(); 173 c_long nrand48(ushort[3]); 174 int posix_openpt(int); 175 char* ptsname(int); 176 int putenv(char*); 177 c_long random(); 178 char* realpath(in char*, char*); 179 ushort seed48(ushort[3]); 180 void setkey(in char*); 181 char* setstate(in char*); 182 void srand48(c_long); 183 void srandom(uint); 184 int unlockpt(int); 185 */ 186 187 version( linux ) 188 { 189 //WNOHANG (defined in tango.stdc.posix.sys.wait) 190 //WUNTRACED (defined in tango.stdc.posix.sys.wait) 191 //WEXITSTATUS (defined in tango.stdc.posix.sys.wait) 192 //WIFEXITED (defined in tango.stdc.posix.sys.wait) 193 //WIFSIGNALED (defined in tango.stdc.posix.sys.wait) 194 //WIFSTOPPED (defined in tango.stdc.posix.sys.wait) 195 //WSTOPSIG (defined in tango.stdc.posix.sys.wait) 196 //WTERMSIG (defined in tango.stdc.posix.sys.wait) 197 198 c_long a64l(in char*); 199 double drand48(); 200 char* ecvt(double, int, int *, int *); // LEGACY 201 double erand48(ushort[3]); 202 char* fcvt(double, int, int *, int *); // LEGACY 203 char* gcvt(double, int, char*); // LEGACY 204 int getsubopt(char**, in char**, char**); 205 int grantpt(int); 206 char* initstate(uint, char*, size_t); 207 c_long jrand48(ushort[3]); 208 char* l64a(c_long); 209 void lcong48(ushort[7]); 210 c_long lrand48(); 211 char* mktemp(char*); // LEGACY 212 //int mkstemp(char*); 213 c_long mrand48(); 214 c_long nrand48(ushort[3]); 215 int posix_openpt(int); 216 char* ptsname(int); 217 int putenv(char*); 218 c_long random(); 219 char* realpath(in char*, char*); 220 ushort seed48(ushort[3]); 221 void setkey(in char*); 222 char* setstate(in char*); 223 void srand48(c_long); 224 void srandom(uint); 225 int unlockpt(int); 226 227 static if( __USE_LARGEFILE64 ) 228 { 229 int mkstemp64(char*); 230 alias mkstemp64 mkstemp; 231 } 232 else 233 { 234 int mkstemp(char*); 235 } 236 } 237 else version( darwin ) 238 { 239 //WNOHANG (defined in tango.stdc.posix.sys.wait) 240 //WUNTRACED (defined in tango.stdc.posix.sys.wait) 241 //WEXITSTATUS (defined in tango.stdc.posix.sys.wait) 242 //WIFEXITED (defined in tango.stdc.posix.sys.wait) 243 //WIFSIGNALED (defined in tango.stdc.posix.sys.wait) 244 //WIFSTOPPED (defined in tango.stdc.posix.sys.wait) 245 //WSTOPSIG (defined in tango.stdc.posix.sys.wait) 246 //WTERMSIG (defined in tango.stdc.posix.sys.wait) 247 248 c_long a64l(in char*); 249 double drand48(); 250 char* ecvt(double, int, int *, int *); // LEGACY 251 double erand48(ushort[3]); 252 char* fcvt(double, int, int *, int *); // LEGACY 253 char* gcvt(double, int, char*); // LEGACY 254 int getsubopt(char**, in char**, char**); 255 int grantpt(int); 256 char* initstate(uint, char*, size_t); 257 c_long jrand48(ushort[3]); 258 char* l64a(c_long); 259 void lcong48(ushort[7]); 260 c_long lrand48(); 261 char* mktemp(char*); // LEGACY 262 int mkstemp(char*); 263 c_long mrand48(); 264 c_long nrand48(ushort[3]); 265 int posix_openpt(int); 266 char* ptsname(int); 267 int putenv(char*); 268 c_long random(); 269 char* realpath(in char*, char*); 270 ushort seed48(ushort[3]); 271 void setkey(in char*); 272 char* setstate(in char*); 273 void srand48(c_long); 274 void srandom(uint); 275 int unlockpt(int); 276 } 277 else version( FreeBSD ) 278 { 279 //WNOHANG (defined in tango.stdc.posix.sys.wait) 280 //WUNTRACED (defined in tango.stdc.posix.sys.wait) 281 //WEXITSTATUS (defined in tango.stdc.posix.sys.wait) 282 //WIFEXITED (defined in tango.stdc.posix.sys.wait) 283 //WIFSIGNALED (defined in tango.stdc.posix.sys.wait) 284 //WIFSTOPPED (defined in tango.stdc.posix.sys.wait) 285 //WSTOPSIG (defined in tango.stdc.posix.sys.wait) 286 //WTERMSIG (defined in tango.stdc.posix.sys.wait) 287 288 c_long a64l(in char*); 289 double drand48(); 290 291 // Unimplemented on FreeBSD, but required by tango 292 import tango.stdc.math : modf; 293 char* ecvt(double arg, int ndigits, int* decpt, int* sign) 294 { 295 return(cvt(arg, ndigits, decpt, sign, true)); 296 } 297 char* fcvt(double arg, int ndigits, int* decpt, int* sign) 298 { 299 return(cvt(arg, ndigits, decpt, sign, false)); 300 } 301 private char* cvt(double arg, int ndigits, int* decpt, int* sign, bool eflag) 302 { 303 int r2; 304 double fi, fj; 305 char* p, p1; 306 char[] buf; 307 308 if (ndigits<0) 309 ndigits = 0; 310 buf = new char[ndigits]; 311 312 r2 = 0; 313 *sign = 0; 314 p = &buf[0]; 315 if (arg<0) { 316 *sign = 1; 317 arg = -arg; 318 } 319 arg = modf(arg, &fi); 320 p1 = &buf[$-1]; 321 /* 322 * Do integer part 323 */ 324 if (fi != 0) { 325 p1 = &buf[$-1]; 326 while (fi != 0) { 327 fj = modf(fi/10, &fi); 328 *--p1 = cast(char)((cast(char) (fj+.03)*10) + '0'); 329 r2++; 330 } 331 while (p1 < &buf[$-1]) 332 *p++ = *p1++; 333 } else if (arg > 0) { 334 while ((fj = arg*10) < 1) { 335 arg = fj; 336 r2--; 337 } 338 } 339 p1 = &buf[ndigits]; 340 if (!eflag) 341 p1 += r2; 342 *decpt = r2; 343 if (p1 < &buf[0]) { 344 buf[0] = '\0'; 345 return(buf.ptr); 346 } 347 while (p<=p1 && p<&buf[$-1]) { 348 arg *= 10; 349 arg = modf(arg, &fj); 350 *p++ = cast(char) (cast(char)(fj) + '0'); 351 } 352 if (p1 >= &buf[$-1]) { 353 buf[$-2] = '\0'; 354 return(buf.ptr); 355 } 356 p = p1; 357 *p1 += 5; 358 while (*p1 > '9') { 359 *p1 = '0'; 360 if (p1>buf.ptr) 361 ++*--p1; 362 else { 363 *p1 = '1'; 364 (*decpt)++; 365 if (!eflag) { 366 if (p>buf.ptr) 367 *p = '0'; 368 p++; 369 } 370 } 371 } 372 *p = '\0'; 373 return(buf.ptr); 374 } 375 376 double erand48(ushort[3]); 377 int getsubopt(char**, in char**, char**); 378 int grantpt(int); 379 char* initstate(uint, char*, size_t); 380 c_long jrand48(ushort[3]); 381 char* l64a(c_long); 382 void lcong48(ushort[7]); 383 c_long lrand48(); 384 char* mktemp(char*); // LEGACY 385 int mkstemp(char*); 386 c_long mrand48(); 387 c_long nrand48(ushort[3]); 388 int posix_openpt(int); 389 char* ptsname(int); 390 int putenv(char*); 391 c_long random(); 392 char* realpath(in char*, char*); 393 ushort seed48(ushort[3]); 394 void setkey(in char*); 395 char* setstate(in char*); 396 void srand48(c_long); 397 void srandom(uint); 398 int unlockpt(int); 399 } 400 else version( solaris ) 401 { 402 //WNOHANG (defined in tango.stdc.posix.sys.wait) 403 //WUNTRACED (defined in tango.stdc.posix.sys.wait) 404 //WEXITSTATUS (defined in tango.stdc.posix.sys.wait) 405 //WIFEXITED (defined in tango.stdc.posix.sys.wait) 406 //WIFSIGNALED (defined in tango.stdc.posix.sys.wait) 407 //WIFSTOPPED (defined in tango.stdc.posix.sys.wait) 408 //WSTOPSIG (defined in tango.stdc.posix.sys.wait) 409 //WTERMSIG (defined in tango.stdc.posix.sys.wait) 410 411 c_long a64l(in char*); 412 double drand48(); 413 //char* ecvt(double, int, int *, int *); // LEGACY 414 double erand48(ushort[3]); 415 //char* fcvt(double, int, int *, int *); // LEGACY 416 //char* gcvt(double, int, char*); // LEGACY 417 int getsubopt(char**, in char**, char**); 418 int grantpt(int); 419 char* initstate(uint, char*, size_t); 420 c_long jrand48(ushort[3]); 421 char* l64a(c_long); 422 void lcong48(ushort[7]); 423 c_long lrand48(); 424 char* mktemp(char*); // LEGACY 425 int mkstemp(char*); 426 c_long mrand48(); 427 c_long nrand48(ushort[3]); 428 int posix_openpt(int); 429 char* ptsname(int); 430 int putenv(char*); 431 c_long random(); 432 char* realpath(in char*, char*); 433 ushort seed48(ushort[3]); 434 void setkey(in char*); 435 char* setstate(in char*); 436 void srand48(c_long); 437 void srandom(uint); 438 int unlockpt(int); 439 }