aboutsummaryrefslogtreecommitdiff
path: root/stdlib/c89/stdlib.lh
blob: 329cac851982ee5f4cee1190130ba406c9f22a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

/*
  LRL version of ANSI C header <stdio.h>
  http://flash-gordon.me.uk/ansi.c.txt
*/

linkname "";

// 4.10 GENERAL UTILITIES <stdlib.h>
typedef size_t = count;
typedef wchar_t = uint32; // UCS-4
typedef div_t = (var int quot, var int rem);
typedef ldiv_t = (var long quot, var long rem);

// Use none instead of NULL, which is a typed NULL

alias int EXIT_FAILURE = 1;
alias int EXIT_SUCCESS = 0;

// Value from GNU libc
alias int RAND_MAX = 2147483647;

// TODO MB_CUR_MAX ?


// 4.10.1 String conversion functions
cdouble atof(byte+> nptr);
int atoi(byte+> nptr);
long atol(byte+> nptr);
cdouble strtod(byte+> nptr, byte+>? var^ endptr);
long strtol(byte+> nptr, byte+>? var^ endptr, int base);
ulong strtoul(byte+> nptr, byte+>? var^ endptr, int base);


// 4.10.2 Pseudo-random sequence generation functions
int rand();
() srand(uint seed);


// 4.10.3 Memory management functions
// TODO size constraints (size == sizeof(T))
T own^? calloc[T](count nmemb, count size);
() free[T](T own^? ptr);
T own^? malloc[T](count size);
U own^? realloc[T,U](T own^? ptr, count size); // kind of unsafe. type mismatches can not be detected with e.g. Valgrind


// 4.10.4 Communication with the environment
() abort();
int atexit(()()^ func);
() exit(int status);
shared byte+>? getenv(byte+> name);
int system(byte ^string);


// 4.10.5 Searching and sorting utilities
// TODO size constraints (size == sizeof(T))
T^? bsearch[T](T^ key, T#[nmemb]^ base, count nmemb, count size,
               int(T^, T^)^ compar);
() qsort[T](var T#[nmemb]^, count nmemb, count size, int(T^, T^)^ compar);


// 4.10.6 Integer arithmetic functions
int abs(int j);
div_t div(int number, int denom);
long labs(long j);
ldiv_t ldiv(long number, long denom);


// 4.10.7 Multibyte character functions
int mblen(byte+> s, count n);
int mbtowc(var wchar_t^? pwc,  byte+>? s, count n);
int wctomb(var byte+>? s, wchar_t wchar);


// 4.10.8 Multibyte string functions
count mbstowcs(var wchar_t^? pwcs, byte+> s, count n);
count wcstombs(var byte+>? s, wchar_t^ pwcs, count n);