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