forked from maplelang/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibc.m
151 lines (132 loc) · 5.29 KB
/
libc.m
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2022-2023, Mate Kukri
* SPDX-License-Identifier: GPL-2.0-only
*
* Description: C standard library bindings
*/
// C primitive types (can differ between platform/ABIs)
struct Void()
type Char = Int8
type Uchar = Uint8
type Short = Int16
type Ushort = Uint16
type Int = Int32
type Uint = Uint32
type Long = Int64
type Ulong = Uint64
type Llong = Int64
type Ullong = Uint64
// stdio.h
struct FILE()
const SEEK_SET: Int = 0
const SEEK_CUR: Int = 1
const SEEK_END: Int = 2
const EOF: Int = -1
extern {
function remove(filename: *Char) -> Int
function rename(old: *Char, new: *Char) -> Int
function tmpfile() -> *mut FILE
function tmpnam(s: *mut Char) -> *mut Char
function fclose(stream: *mut FILE) -> Int
function fflush(stream: *mut FILE) -> Int
function fopen(filename: *Char, mode: *Char) -> *mut FILE
function freopen(filename: *Char, mode: *Char) -> *mut FILE
function setbuf(stream: *mut FILE, buf: *Char)
function setvbuf(stream: *mut FILE, buf: *Char, mode: Int, size: Uintn) -> Int
function fprintf(stream: *mut FILE, fmt: *Char, ...) -> Int
function fscanf(stream: *mut FILE, fmt: *Char, ...) -> Int
function printf(fmt: *Char, ...) -> Int
function scanf(fmt: *Char, ...) -> Int
function snprintf(s: *mut Char, n: Uintn, fmt: *Char, ...) -> Int
function sprintf(s: *mut Char, fmt: *Char, ...) -> Int
function sscanf(s: *mut Char, fmt: *Char, ...) -> Int
// TODO(va_list support): vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, vsscanf
function fgetc(stream: *mut FILE) -> Int
function fgets(s: *mut Char, n: Int, stream: *mut FILE) -> *mut Char
function fputc(c: Int, stream: *mut FILE) -> Int
function fputs(s: *Char, stream: *mut FILE) -> Int
function getc(stream: *mut FILE) -> Int
function getchar() -> Int
function gets(s: *mut Char) -> *mut Char
function putc(c: Int, stream: *mut FILE) -> Int
function putchar(c: Int) -> Int
function puts(s: *Char) -> Int
function ungetc(c: Int, stream: *mut FILE) -> Int
function fread(ptr: *mut Void, size: Uintn, nmemb: Uintn, stream: *mut FILE) -> Uintn
function fwrite(ptr: *mut Void, size: Uintn, nmemb: Uintn, stream: *mut FILE) -> Uintn
// TODO(platform dependent): fgetpos
function fseek(stream: *mut FILE, offset: Long, whence: Int) -> Int
// TODO(platform dependent): fsetpos
function ftell(stream: *mut FILE) -> Long
function rewind(stream: *mut FILE)
function clearerr(stream: *mut FILE)
function feof(stream: *mut FILE) -> Int
function ferror(stream: *mut FILE) -> Int
function perror(s: *Char)
data stdin: *mut FILE
data stdout: *mut FILE
data stderr: *mut FILE
}
// stdlib.h
extern {
function atof(nptr: *Char) -> Double
function atoi(nptr: *Char) -> Int
function atol(nptr: *Char) -> Long
function atoll(nptr: *Char) -> Llong
function strtod(nptr: *Char, endptr: *mut *mut Char) -> Double
function strtof(nptr: *Char, endptr: *mut *mut Char) -> Float
function strtol(nptr: *Char, endptr: *mut *mut Char, base: Int) -> Long
function strtoll(nptr: *Char, endptr: *mut *mut Char, base: Int) -> Llong
function strtoul(nptr: *Char, endptr: *mut *mut Char, base: Int) -> Ulong
function strtoull(nptr: *Char, endptr: *mut *mut Char, base: Int) -> Ullong
function rand() -> Int
function srand(seed: Uint)
function calloc(nmemb: Uintn, size: Uintn) -> *mut Void
function free(ptr: *mut Void)
function malloc(size: Uintn) -> *mut Void
function realloc(old: *mut Void, size: Uintn) -> *mut Void
function abort()
function atexit(func: Function()) -> Int
function exit(status: Int)
function _Exit(status: Int)
function getenv(name: *Char) -> *mut Char
function system(string: *Char) -> Int
function bsearch(key: *Void, base: *Void,
nmemb: Uintn, size: Uintn,
compar: Function(a: *Void, b: *Void)) -> *mut Void
function qsort(base: *mut Void,
nmemb: Uintn, size: Uintn,
compar: Function(a: *Void, b: *Void))
function abs(j: Int) -> Int
function labs(j: Long) -> Long
function llabs(j: Llong) -> Llong
}
// string.h
extern {
function memcpy(dest: *mut Void, src: *Void, len: Uintn) -> *mut Void
function memmove(dest: *mut Void, src: *Void, len: Uintn) -> *mut Void
function strcpy(s1: *mut Char, s2: *Char) -> *mut Char
function strncpy(s1: *mut Char, s2: *Char, n: Uintn) -> *mut Char
function strcat(s1: *mut Char, s2: *Char) -> *mut Char
function strncat(s1: *mut Char, s2: *Char, n: Uintn) -> *mut Char
function memcmp(s1: *Void, s2: *Void, n: Uintn) -> Int
function strcmp(s1: *Char, s2: *Char) -> Int
function strcoll(s1: *Char, s2: *Char) -> Int
function strncmp(s1: *Char, s2: *Char, n: Uintn) -> Int
function strxfrm(s1: *Char, s2: *Char, n: Uintn) -> Uintn
function memchr(s: *Void, c: Int, n: Uintn) -> *mut Void
function strchr(s: *Char, c: Int) -> *mut Char
function strcspn(s1: *Char, s2: *Char) -> Uintn
function strpbrk(s1: *Char, s2: *Char) -> *mut Char
function strrchr(s: *Char, c: Int) -> *mut Char
function strspn(s1: *Char, s2: *Char) -> Uintn
function strstr(s1: *Char, s2: *Char) -> *mut Char
function strtok(s1: *mut Char, s2: *Char) -> *mut Char
function memset(s: *mut Void, c: Int, n: Uintn) -> *mut Void
function strerror(errnum: Int) -> *mut Char
function strlen(s: *Char) -> Uintn
}
// errno.h
extern {
data errno: Int32
}