a simple posix API FFI library (WIP).
Provide posix standard in unistd.h most of the functions, the same category of functions only at
series of functions and functions to support file descriptor
operations, as far as possible to avoid the use of CString
to operate the file, such as only fchownat
and fchown
no chown
, first open the file to obtain the file descriptor
and then operate the file.
Currently waiting for official build system and FFI toolchain support. FFI Tools like rust bindgen
In /src/example directory provides a number of useful examples.
Currently supported interfaces can be viewed at posix.mbti
Install the module with the following bash command.
Static libraries are installed in /your_project/lib
.
moon add illusory0x0/native
bash .mooncakes/illusory0x0/native/install.sh
moon add illusory0x0/posix
bash .mooncakes/illusory0x0/posix/install.sh
Modify moon.pkg.json
to the following code snippet
{
"is-main": true,
"import": [
"illusory0x0/native",
"illusory0x0/posix"
],
"link": {
"native": {
"cc-flags": "-fwrapv -fsanitize=address -fsanitize=undefined",
"cc-link-flags": "-l native.mbt -l posix.mbt -L ./lib"
}
}
}
Under ./src/example
there are some examples, some of them won't compile on Mac, more details are in .github/workflows/rm_incompatible_in_apple.sh
.
Reduce the overhead of static library function calls by enable lto when release.
FFI namespace moonbit_posix_
https://stackoverflow.com/questions/36708171/how-can-openat-avoid-tocttou-errors
https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use
https://www.gnu.org/software/libc/manual/html_node/POSIX-Safety-Concepts.html
https://www.gnu.org/software/libc/manual/html_node/POSIX.html
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/README
https://man7.org/linux/man-pages/man2/syscalls.2.html
https://man7.org/linux/man-pages/man7/pthreads.7.html
https://hackage.haskell.org/package/unix
https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#index-L