1 | module builtin |
2 | |
3 | // struct C.FILE {} |
4 | |
5 | // <string.h> |
6 | fn C.memcpy(dest voidptr, const_src voidptr, n usize) voidptr |
7 | |
8 | fn C.memcmp(const_s1 voidptr, const_s2 voidptr, n usize) int |
9 | |
10 | fn C.memmove(dest voidptr, const_src voidptr, n usize) voidptr |
11 | |
12 | fn C.memset(str voidptr, c int, n usize) voidptr |
13 | |
14 | [trusted] |
15 | fn C.calloc(int, int) &u8 |
16 | |
17 | fn C.atoi(&char) int |
18 | |
19 | fn C.malloc(int) &u8 |
20 | |
21 | fn C.realloc(a &u8, b int) &u8 |
22 | |
23 | fn C.free(ptr voidptr) |
24 | |
25 | [noreturn; trusted] |
26 | fn C.exit(code int) |
27 | |
28 | fn C.qsort(base voidptr, items usize, item_size usize, cb C.qsort_callback_func) |
29 | |
30 | fn C.sprintf(a ...voidptr) int |
31 | |
32 | fn C.strlen(s &char) int |
33 | |
34 | fn C.sscanf(&u8, &u8, ...&u8) int |
35 | |
36 | [trusted] |
37 | fn C.isdigit(c int) bool |
38 | |
39 | // stdio.h |
40 | fn C.popen(c &char, t &char) voidptr |
41 | |
42 | // <libproc.h> |
43 | pub fn proc_pidpath(int, voidptr, int) int |
44 | |
45 | fn C.realpath(&char, &char) &char |
46 | |
47 | // fn C.chmod(byteptr, mode_t) int |
48 | fn C.chmod(&char, u32) int |
49 | |
50 | fn C.printf(&char, ...voidptr) int |
51 | |
52 | fn C.scanf(&char, ...voidptr) int |
53 | |
54 | fn C.puts(&char) int |
55 | fn C.abs(f64) f64 |
56 | |
57 | fn C.fputs(str &char, stream &C.FILE) int |
58 | |
59 | fn C.fflush(&C.FILE) int |
60 | |
61 | // TODO define args in these functions |
62 | fn C.fseek(stream &C.FILE, offset int, whence int) int |
63 | |
64 | fn C.fopen(filename &char, mode &char) &C.FILE |
65 | |
66 | fn C.fileno(&C.FILE) int |
67 | |
68 | fn C.fread(ptr voidptr, item_size usize, items usize, stream &C.FILE) usize |
69 | |
70 | fn C.fwrite(ptr voidptr, item_size usize, items usize, stream &C.FILE) usize |
71 | |
72 | fn C.fclose(stream &C.FILE) int |
73 | |
74 | fn C.pclose(stream &C.FILE) int |
75 | |
76 | fn C.strrchr(s &char, c int) &char |
77 | fn C.strchr(s &char, c int) &char |
78 | |
79 | // process execution, os.process: |
80 | [trusted] |
81 | fn C.getpid() int |
82 | |
83 | fn C.getuid() int |
84 | |
85 | fn C.geteuid() int |
86 | |
87 | fn C.system(cmd &char) int |
88 | |
89 | fn C.posix_spawn(child_pid &int, path &char, file_actions voidptr, attrp voidptr, argv &&char, envp &&char) int |
90 | |
91 | fn C.posix_spawnp(child_pid &int, exefile &char, file_actions voidptr, attrp voidptr, argv &&char, envp &&char) int |
92 | |
93 | fn C.execve(cmd_path &char, args voidptr, envs voidptr) int |
94 | |
95 | fn C.execvp(cmd_path &char, args &&char) int |
96 | |
97 | fn C._execve(cmd_path &char, args voidptr, envs voidptr) int |
98 | |
99 | fn C._execvp(cmd_path &char, args &&char) int |
100 | |
101 | fn C.strcmp(s1 &char, s2 &char) int |
102 | |
103 | [trusted] |
104 | fn C.fork() int |
105 | |
106 | fn C.wait(status &int) int |
107 | |
108 | fn C.waitpid(pid int, status &int, options int) int |
109 | |
110 | [trusted] |
111 | fn C.kill(pid int, sig int) int |
112 | |
113 | fn C.setenv(&char, &char, int) int |
114 | |
115 | fn C.unsetenv(&char) int |
116 | |
117 | fn C.access(path &char, amode int) int |
118 | |
119 | fn C.remove(filename &char) int |
120 | |
121 | fn C.rmdir(path &char) int |
122 | |
123 | fn C.chdir(path &char) int |
124 | |
125 | fn C.rewind(stream &C.FILE) int |
126 | |
127 | fn C.ftell(&C.FILE) isize |
128 | |
129 | fn C.stat(&char, voidptr) int |
130 | |
131 | fn C.lstat(path &char, buf &C.stat) int |
132 | |
133 | fn C.rename(old_filename &char, new_filename &char) int |
134 | |
135 | fn C.fgets(str &char, n int, stream &C.FILE) int |
136 | |
137 | [trusted] |
138 | fn C.sigemptyset() int |
139 | |
140 | fn C.getcwd(buf &char, size usize) &char |
141 | |
142 | [trusted] |
143 | fn C.mktime() int |
144 | |
145 | fn C.gettimeofday(tv &C.timeval, tz &C.timezone) int |
146 | |
147 | [trusted] |
148 | fn C.sleep(seconds u32) u32 |
149 | |
150 | // fn C.usleep(usec useconds_t) int |
151 | [trusted] |
152 | fn C.usleep(usec u32) int |
153 | |
154 | [typedef] |
155 | struct C.DIR { |
156 | } |
157 | |
158 | fn C.opendir(&char) &C.DIR |
159 | |
160 | fn C.closedir(dirp &C.DIR) int |
161 | |
162 | // fn C.mkdir(path &char, mode mode_t) int |
163 | fn C.mkdir(path &char, mode u32) int |
164 | |
165 | // C.rand returns a pseudorandom integer from 0 (inclusive) to C.RAND_MAX (exclusive) |
166 | [trusted] |
167 | fn C.rand() int |
168 | |
169 | // C.srand seeds the internal PRNG with the given value. |
170 | [trusted] |
171 | fn C.srand(seed u32) |
172 | |
173 | fn C.atof(str &char) f64 |
174 | |
175 | [trusted] |
176 | fn C.tolower(c int) int |
177 | |
178 | [trusted] |
179 | fn C.toupper(c int) int |
180 | |
181 | [trusted] |
182 | fn C.isspace(c int) int |
183 | |
184 | fn C.strchr(s &char, c int) &char |
185 | |
186 | [trusted] |
187 | fn C.getchar() int |
188 | |
189 | [trusted] |
190 | fn C.putchar(int) int |
191 | |
192 | fn C.strdup(s &char) &char |
193 | |
194 | fn C.strncasecmp(s &char, s2 &char, n int) int |
195 | |
196 | fn C.strcasecmp(s &char, s2 &char) int |
197 | |
198 | fn C.strncmp(s &char, s2 &char, n int) int |
199 | |
200 | [trusted] |
201 | fn C.strerror(int) &char |
202 | |
203 | fn C.snprintf(str &char, size usize, format &char, opt ...voidptr) int |
204 | |
205 | fn C.fprintf(voidptr, &char, ...voidptr) |
206 | |
207 | [trusted] |
208 | fn C.WIFEXITED(status int) bool |
209 | |
210 | [trusted] |
211 | fn C.WEXITSTATUS(status int) int |
212 | |
213 | [trusted] |
214 | fn C.WIFSIGNALED(status int) bool |
215 | |
216 | [trusted] |
217 | fn C.WTERMSIG(status int) int |
218 | |
219 | [trusted] |
220 | fn C.isatty(fd int) int |
221 | |
222 | fn C.syscall(number int, va ...voidptr) int |
223 | |
224 | fn C.sysctl(name &int, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen usize) int |
225 | |
226 | [trusted] |
227 | fn C._fileno(int) int |
228 | |
229 | fn C._get_osfhandle(fd int) C.intptr_t |
230 | |
231 | fn C.GetModuleFileName(hModule voidptr, lpFilename &u16, nSize u32) u32 |
232 | |
233 | fn C.GetModuleFileNameW(hModule voidptr, lpFilename &u16, nSize u32) u32 |
234 | |
235 | fn C.CreateFile(lpFilename &u16, dwDesiredAccess u32, dwShareMode u32, lpSecurityAttributes &u16, dwCreationDisposition u32, dwFlagsAndAttributes u32, hTemplateFile voidptr) voidptr |
236 | |
237 | fn C.CreateFileW(lpFilename &u16, dwDesiredAccess u32, dwShareMode u32, lpSecurityAttributes &u16, dwCreationDisposition u32, dwFlagsAndAttributes u32, hTemplateFile voidptr) voidptr |
238 | |
239 | fn C.GetFinalPathNameByHandleW(hFile voidptr, lpFilePath &u16, nSize u32, dwFlags u32) u32 |
240 | |
241 | fn C.CreatePipe(hReadPipe &voidptr, hWritePipe &voidptr, lpPipeAttributes voidptr, nSize u32) bool |
242 | |
243 | fn C.SetHandleInformation(hObject voidptr, dwMask u32, dw_flags u32) bool |
244 | |
245 | fn C.ExpandEnvironmentStringsW(lpSrc &u16, lpDst &u16, nSize u32) u32 |
246 | |
247 | fn C.GetComputerNameW(&u16, &u32) bool |
248 | |
249 | fn C.GetUserNameW(&u16, &u32) bool |
250 | |
251 | [trusted] |
252 | fn C.SendMessageTimeout() isize |
253 | |
254 | fn C.SendMessageTimeoutW(hWnd voidptr, msg u32, wParam &u16, lParam &u32, fuFlags u32, uTimeout u32, lpdwResult &u64) isize |
255 | |
256 | fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttributes voidptr, lpThreadAttributes voidptr, bInheritHandles bool, dwCreationFlags u32, lpEnvironment voidptr, lpCurrentDirectory &u16, lpStartupInfo voidptr, lpProcessInformation voidptr) bool |
257 | |
258 | fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead &u32, lpOverlapped voidptr) bool |
259 | |
260 | fn C.GetFileAttributesW(lpFileName &u8) u32 |
261 | |
262 | fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &u8, lpcbData &u32) int |
263 | |
264 | fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &u8, lpcbData &u32) int |
265 | |
266 | fn C.RegOpenKeyEx(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) int |
267 | |
268 | fn C.RegOpenKeyExW(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) int |
269 | |
270 | fn C.RegSetValueEx(hKey voidptr, lpValueName &u16, dwType u32, lpData &u16, cbData u32) int |
271 | |
272 | fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, reserved u32, dwType u32, const_lpData &u8, cbData u32) int |
273 | |
274 | fn C.RegCloseKey(hKey voidptr) int |
275 | |
276 | fn C.RemoveDirectory(lpPathName &u16) bool |
277 | |
278 | fn C.RemoveDirectoryW(lpPathName &u16) bool |
279 | |
280 | fn C.GetStdHandle(u32) voidptr |
281 | |
282 | fn C.SetConsoleMode(voidptr, u32) bool |
283 | |
284 | fn C.GetConsoleMode(voidptr, &u32) bool |
285 | |
286 | [trusted] |
287 | fn C.GetCurrentProcessId() u32 |
288 | |
289 | fn C.wprintf() |
290 | |
291 | // fn C.setbuf() |
292 | fn C.setbuf(voidptr, &char) |
293 | |
294 | fn C.SymCleanup(hProcess voidptr) |
295 | |
296 | fn C.MultiByteToWideChar(codePage u32, dwFlags u32, lpMultiMyteStr &char, cbMultiByte int, lpWideCharStr &u16, cchWideChar int) int |
297 | |
298 | fn C.wcslen(str voidptr) usize |
299 | |
300 | fn C.WideCharToMultiByte(codePage u32, dwFlags u32, lpWideCharStr &u16, cchWideChar int, lpMultiByteStr &char, cbMultiByte int, lpDefaultChar &char, lpUsedDefaultChar &int) int |
301 | |
302 | fn C._wstat(path &u16, buffer &C._stat) int |
303 | |
304 | fn C._wrename(oldname &u16, newname &u16) int |
305 | |
306 | fn C._wfopen(filename &u16, mode &u16) voidptr |
307 | |
308 | fn C._wpopen(command &u16, mode &u16) voidptr |
309 | |
310 | fn C._pclose(stream &C.FILE) int |
311 | |
312 | fn C._wsystem(command &u16) int |
313 | |
314 | fn C._wgetenv(varname &u16) voidptr |
315 | |
316 | fn C._putenv(envstring &char) int |
317 | |
318 | fn C._waccess(path &u16, mode int) int |
319 | |
320 | fn C._wremove(path &u16) int |
321 | |
322 | fn C.ReadConsole(in_input_handle voidptr, out_buffer voidptr, in_chars_to_read u32, out_read_chars &u32, in_input_control voidptr) bool |
323 | |
324 | fn C.WriteConsole() voidptr |
325 | |
326 | fn C.WriteFile() voidptr |
327 | |
328 | fn C._wchdir(dirname &u16) int |
329 | |
330 | fn C._wgetcwd(buffer &u16, maxlen int) int |
331 | |
332 | fn C._fullpath() int |
333 | |
334 | fn C.GetFullPathName(voidptr, u32, voidptr, voidptr) u32 |
335 | |
336 | [trusted] |
337 | fn C.GetCommandLine() voidptr |
338 | |
339 | fn C.LocalFree() |
340 | |
341 | fn C.FindFirstFileW(lpFileName &u16, lpFindFileData voidptr) voidptr |
342 | |
343 | fn C.FindFirstFile(lpFileName &u8, lpFindFileData voidptr) voidptr |
344 | |
345 | fn C.FindNextFile(hFindFile voidptr, lpFindFileData voidptr) int |
346 | |
347 | fn C.FindClose(hFindFile voidptr) |
348 | |
349 | // macro |
350 | fn C.MAKELANGID(lgid voidptr, srtid voidptr) int |
351 | |
352 | fn C.FormatMessage(dwFlags u32, lpSource voidptr, dwMessageId u32, dwLanguageId u32, lpBuffer voidptr, nSize u32, arguments ...voidptr) u32 |
353 | |
354 | fn C.CloseHandle(voidptr) int |
355 | |
356 | fn C.GetExitCodeProcess(hProcess voidptr, lpExitCode &u32) |
357 | |
358 | [trusted] |
359 | fn C.GetTickCount() i64 |
360 | |
361 | [trusted] |
362 | fn C.Sleep(dwMilliseconds u32) |
363 | |
364 | fn C.WSAStartup(u16, &voidptr) int |
365 | |
366 | [trusted] |
367 | fn C.WSAGetLastError() int |
368 | |
369 | fn C.closesocket(int) int |
370 | |
371 | fn C.vschannel_init(&C.TlsContext) |
372 | |
373 | fn C.request(&C.TlsContext, int, &u16, &u8, u32, &&u8) int |
374 | |
375 | fn C.vschannel_cleanup(&C.TlsContext) |
376 | |
377 | fn C.URLDownloadToFile(int, &u16, &u16, int, int) |
378 | |
379 | [trusted] |
380 | fn C.GetLastError() u32 |
381 | |
382 | fn C.CreateDirectory(&u8, int) bool |
383 | |
384 | // win crypto |
385 | fn C.BCryptGenRandom(int, voidptr, int, int) int |
386 | |
387 | // win synchronization |
388 | fn C.CreateMutex(int, bool, &u8) voidptr |
389 | |
390 | fn C.WaitForSingleObject(voidptr, int) int |
391 | |
392 | fn C.ReleaseMutex(voidptr) bool |
393 | |
394 | fn C.CreateEvent(int, bool, bool, &u8) voidptr |
395 | |
396 | fn C.SetEvent(voidptr) int |
397 | |
398 | fn C.CreateSemaphore(voidptr, int, int, voidptr) voidptr |
399 | |
400 | fn C.ReleaseSemaphore(voidptr, int, voidptr) voidptr |
401 | |
402 | fn C.InitializeSRWLock(voidptr) |
403 | |
404 | fn C.AcquireSRWLockShared(voidptr) |
405 | |
406 | fn C.AcquireSRWLockExclusive(voidptr) |
407 | |
408 | fn C.ReleaseSRWLockShared(voidptr) |
409 | |
410 | fn C.ReleaseSRWLockExclusive(voidptr) |
411 | |
412 | // pthread.h |
413 | fn C.pthread_mutex_init(voidptr, voidptr) int |
414 | |
415 | fn C.pthread_mutex_lock(voidptr) int |
416 | |
417 | fn C.pthread_mutex_unlock(voidptr) int |
418 | |
419 | fn C.pthread_mutex_destroy(voidptr) int |
420 | |
421 | fn C.pthread_rwlockattr_init(voidptr) int |
422 | |
423 | fn C.pthread_rwlockattr_setkind_np(voidptr, int) int |
424 | |
425 | fn C.pthread_rwlockattr_setpshared(voidptr, int) int |
426 | |
427 | fn C.pthread_rwlock_init(voidptr, voidptr) int |
428 | |
429 | fn C.pthread_rwlock_rdlock(voidptr) int |
430 | |
431 | fn C.pthread_rwlock_wrlock(voidptr) int |
432 | |
433 | fn C.pthread_rwlock_unlock(voidptr) int |
434 | |
435 | fn C.pthread_condattr_init(voidptr) int |
436 | |
437 | fn C.pthread_condattr_setpshared(voidptr, int) int |
438 | |
439 | fn C.pthread_condattr_destroy(voidptr) int |
440 | |
441 | fn C.pthread_cond_init(voidptr, voidptr) int |
442 | |
443 | fn C.pthread_cond_signal(voidptr) int |
444 | |
445 | fn C.pthread_cond_wait(voidptr, voidptr) int |
446 | |
447 | fn C.pthread_cond_timedwait(voidptr, voidptr, voidptr) int |
448 | |
449 | fn C.pthread_cond_destroy(voidptr) int |
450 | |
451 | fn C.sem_init(voidptr, int, u32) int |
452 | |
453 | fn C.sem_post(voidptr) int |
454 | |
455 | fn C.sem_wait(voidptr) int |
456 | |
457 | fn C.sem_trywait(voidptr) int |
458 | |
459 | fn C.sem_timedwait(voidptr, voidptr) int |
460 | |
461 | fn C.sem_destroy(voidptr) int |
462 | |
463 | // MacOS semaphore functions |
464 | [trusted] |
465 | fn C.dispatch_semaphore_create(i64) voidptr |
466 | |
467 | fn C.dispatch_semaphore_signal(voidptr) i64 |
468 | |
469 | fn C.dispatch_semaphore_wait(voidptr, u64) i64 |
470 | |
471 | [trusted] |
472 | fn C.dispatch_time(u64, i64) u64 |
473 | |
474 | fn C.dispatch_release(voidptr) |
475 | |
476 | // file descriptor based reading/writing |
477 | fn C.read(fd int, buf voidptr, count usize) int |
478 | |
479 | fn C.write(fd int, buf voidptr, count usize) int |
480 | |
481 | fn C.close(fd int) int |
482 | |
483 | // pipes |
484 | fn C.pipe(pipefds &int) int |
485 | |
486 | fn C.dup2(oldfd int, newfd int) int |
487 | |
488 | // used by gl, stbi, freetype |
489 | fn C.glTexImage2D() |
490 | |
491 | // used by ios for println |
492 | fn C.WrappedNSLog(str &u8) |
493 | |
494 | // used by Android for (e)println to output to the Android log system / logcat |
495 | pub fn C.android_print(voidptr, &char, ...voidptr) |
496 | |
497 | // absolute value |
498 | fn C.abs(number int) int |