PageRenderTime 26ms CodeModel.GetById 9ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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