/src/core/stdc/stdlib.d

http://github.com/AlexeyProkhin/druntime · D · 144 lines · 103 code · 23 blank · 18 comment · 6 complexity · d38d9eea9b112248420d36312865a1d6 MD5 · raw file

  1. /**
  2. * D header file for C99.
  3. *
  4. * Copyright: Copyright Sean Kelly 2005 - 2012.
  5. * License: Distributed under the
  6. * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
  7. * (See accompanying file LICENSE)
  8. * Authors: Sean Kelly
  9. * Standards: ISO/IEC 9899:1999 (E)
  10. * Source: $(DRUNTIMESRC src/core/stdc/_stdlib.d)
  11. */
  12. module core.stdc.stdlib;
  13. private import core.stdc.config;
  14. public import core.stdc.stddef; // for size_t, wchar_t
  15. extern (C):
  16. @system:
  17. nothrow:
  18. struct div_t
  19. {
  20. int quot,
  21. rem;
  22. }
  23. struct ldiv_t
  24. {
  25. int quot,
  26. rem;
  27. }
  28. struct lldiv_t
  29. {
  30. long quot,
  31. rem;
  32. }
  33. enum EXIT_SUCCESS = 0;
  34. enum EXIT_FAILURE = 1;
  35. enum MB_CUR_MAX = 1;
  36. version(Windows) enum RAND_MAX = 0x7fff;
  37. else version(linux) enum RAND_MAX = 0x7fffffff;
  38. else version(OSX) enum RAND_MAX = 0x7fffffff;
  39. else version(FreeBSD) enum RAND_MAX = 0x7fffffff;
  40. else version(Solaris) enum RAND_MAX = 0x7fff;
  41. else static assert( false, "Unsupported platform" );
  42. double atof(in char* nptr);
  43. int atoi(in char* nptr);
  44. c_long atol(in char* nptr);
  45. long atoll(in char* nptr);
  46. double strtod(in char* nptr, char** endptr);
  47. float strtof(in char* nptr, char** endptr);
  48. c_long strtol(in char* nptr, char** endptr, int base);
  49. long strtoll(in char* nptr, char** endptr, int base);
  50. c_ulong strtoul(in char* nptr, char** endptr, int base);
  51. ulong strtoull(in char* nptr, char** endptr, int base);
  52. version (Win64)
  53. {
  54. real strtold(in char* nptr, char** endptr)
  55. { // Fake it 'till we make it
  56. return strtod(nptr, endptr);
  57. }
  58. }
  59. else version (MinGW)
  60. {
  61. real __mingw_strtold(in char* nptr, char** endptr);
  62. alias __mingw_strtold strtold;
  63. }
  64. else
  65. {
  66. real strtold(in char* nptr, char** endptr);
  67. }
  68. // No unsafe pointer manipulation.
  69. @trusted
  70. {
  71. int rand();
  72. void srand(uint seed);
  73. }
  74. // We don't mark these @trusted. Given that they return a void*, one has
  75. // to do a pointer cast to do anything sensible with the result. Thus,
  76. // functions using these already have to be @trusted, allowing them to
  77. // call @system stuff anyway.
  78. void* malloc(size_t size);
  79. void* calloc(size_t nmemb, size_t size);
  80. void* realloc(void* ptr, size_t size);
  81. void free(void* ptr);
  82. void abort();
  83. void exit(int status);
  84. int atexit(void function() func);
  85. void _Exit(int status);
  86. char* getenv(in char* name);
  87. int system(in char* string);
  88. void* bsearch(in void* key, in void* base, size_t nmemb, size_t size, int function(in void*, in void*) compar);
  89. void qsort(void* base, size_t nmemb, size_t size, int function(in void*, in void*) compar);
  90. // These only operate on integer values.
  91. @trusted
  92. {
  93. pure int abs(int j);
  94. pure c_long labs(c_long j);
  95. pure long llabs(long j);
  96. div_t div(int numer, int denom);
  97. ldiv_t ldiv(c_long numer, c_long denom);
  98. lldiv_t lldiv(long numer, long denom);
  99. }
  100. int mblen(in char* s, size_t n);
  101. int mbtowc(wchar_t* pwc, in char* s, size_t n);
  102. int wctomb(char*s, wchar_t wc);
  103. size_t mbstowcs(wchar_t* pwcs, in char* s, size_t n);
  104. size_t wcstombs(char* s, in wchar_t* pwcs, size_t n);
  105. version( DigitalMars )
  106. {
  107. // See malloc comment about @trusted.
  108. void* alloca(size_t size); // non-standard
  109. }
  110. version (Win64)
  111. {
  112. ulong _strtoui64(in char *,char **,int);
  113. ulong _wcstoui64(in wchar *,wchar **,int);
  114. long _strtoi64(in char *,char **,int);
  115. long _wcstoi64(in wchar *,wchar **,int);
  116. }
  117. version( LDC )
  118. {
  119. pragma(LDC_alloca)
  120. void* alloca(size_t size);
  121. }