https://github.com/streamich/libjs
libc implemented in JavaScript
https://github.com/streamich/libjs
Last synced: 11 months ago
JSON representation
libc implemented in JavaScript
- Host: GitHub
- URL: https://github.com/streamich/libjs
- Owner: streamich
- License: unlicense
- Created: 2016-07-23T20:12:00.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-12T08:41:58.000Z (almost 6 years ago)
- Last Synced: 2025-08-01T21:53:51.073Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 459 KB
- Stars: 55
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# libjs
[![][npm-badge]][npm-url] [![][travis-badge]][travis-url]
System programming library; **libjs** — [libc](https://en.wikipedia.org/wiki/C_standard_library) in JavaScript.
## Usage
```shell
npm install libjs libsys
```
This library uses [`libsys`](https://github.com/streamich/libsys) to execute system calls from JavaScript.
It expects your environment has `libsys` global object, in Node.js you can shim `libsys` as follows:
```js
require('libsys/shim');
```
## Examples
- [Write to console](./docs/examples/write-to-console.md)
- [Read from a file](./docs/examples/read-file.md)
- [Run `stat()` on a file](./docs/examples/stat.md)
- [TCP *echo* server](./docs/examples/server.md)
## Reference
- [Synchronous system calls](./docs/synchronous-system-calls.md)
- __Files__ — Standard file operations, which operate on most of the Linux/Unix file descriptors.
- [`read`](./docs/syscalls/read.md) — read from a file descriptor.
- [`write`](./docs/syscalls/write.md) — write to a file descriptor.
- [`open`](./docs/syscalls/open.md) — open a file.
- [`close`](./docs/syscalls/close.md) — close a file descriptor.
- [`access`](./docs/syscalls/ADD.md) — check user can access a file.
- [`chmod`](./docs/syscalls/ADD.md) — change file attributes.
- [`fchmod`](./docs/syscalls/ADD.md) — change file attributes.
- [`chown`](./docs/syscalls/ADD.md) — change file owner.
- [`fchown`](./docs/syscalls/ADD.md) — change file owner.
- [`lchown`](./docs/syscalls/ADD.md) — change file owner.
- [`truncate`](./docs/syscalls/ADD.md) — erase file contents.
- [`ftruncate`](./docs/syscalls/ADD.md) — erase file contents.
- [`lseek`](./docs/syscalls/ADD.md) — change cursor position.
- [`rename`](./docs/syscalls/ADD.md) — rename a file.
- [`fsync`](./docs/syscalls/ADD.md) — flush file to disk.
- [`fdatasync`](./docs/syscalls/ADD.md) — flush file to disk.
- __Stats__ — Fetches and returns statistics about a file.
- [`stat`](./docs/syscalls/ADD.md) — fetch statistics about a file.
- [`lstat`](./docs/syscalls/ADD.md) — fetch statistics about a file.
- [`fstat`](./docs/syscalls/ADD.md) — fetch statistics about a file.
- __Directories__
- [`mkdir`](./docs/syscalls/ADD.md) — creat a directory.
- [`mkdirat`](./docs/syscalls/ADD.md) — create a directory relative to another directory.
- [`rmdir`](./docs/syscalls/ADD.md) — remove a directory.
- [`getcwd`](./docs/syscalls/ADD.md) — fetch current working directory.
- [`getdents64`](./docs/syscalls/ADD.md) — scan through directory entries.
- [`readdir`](./docs/syscalls/ADD.md) — fetch all folder entries.
- [`readdirList`](./docs/syscalls/ADD.md) — fetch all folder entries.
- __Links__
- [`symlink`](./docs/syscalls/ADD.md) — create a symbolic link.
- [`unlink`](./docs/syscalls/ADD.md) — remove a link.
- [`readlink`](./docs/syscalls/ADD.md) — read value of a symbolic link.
- [`link`](./docs/syscalls/ADD.md) — create a link.
- __Time__
- [`utime`](./docs/syscalls/ADD.md) — change file last access and modification times.
- [`utimes`](./docs/syscalls/ADD.md) — change file last access and modification times.
- __Networking__
- [`socket`](./docs/syscalls/ADD.md) — create a socket file descriptor.
- [`connect`](./docs/syscalls/ADD.md) — initiate a connection on a socket.
- [`bind`](./docs/syscalls/ADD.md) — assign an address to a socket.
- [`listen`](./docs/syscalls/ADD.md) — listen for new connections on a socket.
- [`accept`](./docs/syscalls/ADD.md) — accept a connection on a socket.
- [`accept4`](./docs/syscalls/ADD.md) — accept a connection on a socket.
- [`shutdown`](./docs/syscalls/ADD.md) — shut down all or part of a full-duplex connection.
- [`send`](./docs/syscalls/ADD.md) — write data to a socket file descriptor.
- [`sendto`](./docs/syscalls/ADD.md) — write data to a socket file descriptor.
- [`recv`](./docs/syscalls/ADD.md) — read data from socket file descriptor.
- [`recvfrom`](./docs/syscalls/ADD.md) — read data from socket file descriptor.
- [`setsockopt`](./docs/syscalls/ADD.md) — get and set options on a socket.
- __Process__
- [`getpid`](./docs/syscalls/ADD.md) — fetch process *id*.
- [`getppid`](./docs/syscalls/ADD.md) — fetch process *id*.
- [`getuid`](./docs/syscalls/ADD.md) — fetch user *id*.
- [`geteuid`](./docs/syscalls/ADD.md) — fetch user *id*.
- [`getgid`](./docs/syscalls/ADD.md) — fetch group *id*.
- [`getegid`](./docs/syscalls/ADD.md) — fetch group *id*.
- [`sched_yield`](./docs/syscalls/ADD.md) — yield execution to another thread.
- [`nanosleep`](./docs/syscalls/ADD.md) — put thread to sleep.
- __Events__
- [`fcntl`](./docs/syscalls/ADD.md) — manipulate file descriptor.
- [`epoll_create`](./docs/syscalls/ADD.md) — create an *epoll* file descriptor.
- [`epoll_create1`](./docs/syscalls/ADD.md) — create an *epoll* file descriptor.
- [`epoll_wait`](./docs/syscalls/ADD.md) — fetch *epoll* events.
- [`epoll_ctl`](./docs/syscalls/ADD.md) — control interface for an epoll file descriptor.
- [`inotify_init`](./docs/syscalls/ADD.md)
- [`inotify_init1`](./docs/syscalls/ADD.md)
- [`inotify_add_watch`](./docs/syscalls/ADD.md)
- [`inotify_rm_watch`](./docs/syscalls/ADD.md)
- [`kqueue`](./docs/syscalls/ADD.md)
- [`kevent`](./docs/syscalls/ADD.md)
- [`EV_SET`](./docs/syscalls/ADD.md)
- __Memory__
- [`mmap`](./docs/syscalls/ADD.md)
- [`munmap`](./docs/syscalls/ADD.md)
- [`mprotect`](./docs/syscalls/ADD.md)
- [`shmget`](./docs/syscalls/ADD.md)
- [`shmat`](./docs/syscalls/ADD.md)
- [`shmdt`](./docs/syscalls/ADD.md)
- [`shmctl`](./docs/syscalls/ADD.md)
- Asynchronous system calls
- __Files__: [`readAsync`](./docs/syscalls/readAsync.md),
[`writeAsync`](./docs/syscalls/writeAsync.md),
[`openAsync`](./docs/syscalls/openAsync.md),
[`closeAsync`](./docs/syscalls/closeAsync.md),
[`accessAsync`](./docs/syscalls/ADD.md),
[`chmodAsync`](./docs/syscalls/ADD.md),
[`fchmodAsync`](./docs/syscalls/ADD.md),
[`chownAsync`](./docs/syscalls/ADD.md),
[`fchownAsync`](./docs/syscalls/ADD.md),
[`lchownAsync`](./docs/syscalls/ADD.md),
[`truncateAsync`](./docs/syscalls/ADD.md),
[`ftruncateAsync`](./docs/syscalls/ADD.md),
[`lseekAsync`](./docs/syscalls/ADD.md),
[`renameAsync`](./docs/syscalls/ADD.md),
[`fsyncAsync`](./docs/syscalls/ADD.md),
[`fdatasyncAsync`](./docs/syscalls/ADD.md)
- __Stats__: [`statAsync`](./docs/syscalls/ADD.md),
[`lstatAsync`](./docs/syscalls/ADD.md),
and [`fstatAsync`](./docs/syscalls/ADD.md)
- __Directories__: [`mkdirAsync`](./docs/syscalls/ADD.md),
[`mkdiratAsync`](./docs/syscalls/ADD.md),
[`rmdirAsync`](./docs/syscalls/ADD.md),
[`getcwdAsync`](./docs/syscalls/ADD.md),
[`getdents64Async`](./docs/syscalls/ADD.md),
and [`readdirListAsync`](./docs/syscalls/ADD.md)
- __Links__: [`symlinkAsync`](./docs/syscalls/ADD.md),
[`unlinkAsync`](./docs/syscalls/ADD.md),
[`readlinkAsync`](./docs/syscalls/ADD.md),
and [`linkAsync`](./docs/syscalls/ADD.md)
- __Time__: [`utimeAsync`](./docs/syscalls/ADD.md) and [`utimesAsync`](./docs/syscalls/ADD.md)
- __Networking__: [`socketAsync`](./docs/syscalls/ADD.md),
[`connectAsync`](./docs/syscalls/ADD.md),
[`bindAsync`](./docs/syscalls/ADD.md),
[`listenAsync`](./docs/syscalls/ADD.md),
[`acceptAsync`](./docs/syscalls/ADD.md),
[`accept4Async`](./docs/syscalls/ADD.md),
[`shutdownAsync`](./docs/syscalls/ADD.md),
[`sendAsync`](./docs/syscalls/ADD.md)
and [`sendtoAsync`](./docs/syscalls/ADD.md),
- __Process__: [`getpidAsync`](./docs/syscalls/ADD.md),
[`getppidAsync`](./docs/syscalls/ADD.md),
[`getuidAsync`](./docs/syscalls/ADD.md),
[`geteuidAsync`](./docs/syscalls/ADD.md),
[`getgidAsync`](./docs/syscalls/ADD.md),
and [`getegidAsync`](./docs/syscalls/ADD.md),
- Structs
- `epoll_event` and `Iepoll_event`
- `in_addr` and `Iin_addr`
- `inotify_event` and `Iinotify_event`
- `ipc_perm` and `Iipc_perm`
- `ipv4` and `Iipv4`
- `linux_dirent64` and `Ilinux_dirent64`
- `shmid_ds` and `Ishmid_ds`
- `sigaction` and `Isigaction`
- `sockaddr` and `Isockaddr`
- `sockaddr_in` and `Isockaddr_in`
- `statStruct` and `IstatStruct`
- `timespec` and `Itimespec`
- `timeval` and `Itimeval`
- `timevalarr` and `Itimevalarr`
- `utimbuf` and `Iutimbuf`
- [`keventStruct`](./src/structs/kevent.ts) and [`IkeventStruct`](./src/structs/kevent.ts)
- [`kevent64_sStruct`](./src/structs/kevent64_s.ts) and [`Ikevent64_sStruct`](./src/structs/kevent64_s.ts)
- Sockets
- `flip`,
`htons32`,
`hton16`,
`htons`,
`Ip`,
`Ipv4`,
and `Ipv6`,
- Constants
- [`AF`](./src/consts/AF.ts),
[`AMODE`](./src/consts/AMODE.ts),
[`BUS`](./src/consts/BUS.ts),
[`CLD`](./src/consts/CLD.ts),
[`DT`](./src/consts/DT.ts),
[`EPOLL`](./src/consts/EPOLL.ts),
[`EPOLL_CTL`](./src/consts/EPOLL_CTL.ts),
[`EPOLL_EVENTS`](./src/consts/EPOLL_EVENTS.ts),
[`ERROR`](./src/consts/ERROR.ts),
[`EV`](./src/consts/EV.ts),
[`EVFILT`](./src/consts/EVFILT.ts),
[`FCNTL`](./src/consts/FCNTL.ts),
[`FD`](./src/consts/FD.ts),
[`FLAG`](./src/consts/FLAG.ts),
[`FPE`](./src/consts/FPE.ts),
[`ILL`](./src/consts/ILL.ts),
[`IN`](./src/consts/IN.ts),
[`IP`](./src/consts/IP.ts),
[`IPC`](./src/consts/IPC.ts),
[`IPPROT`](./src/consts/IPPROT.ts),
[`IPPROTO`](./src/consts/IPPROTO.ts),
[`IPV6`](./src/consts/IPV6.ts),
[`KEVENT`](./src/consts/KEVENT.ts),
[`MAP`](./src/consts/MAP.ts),
[`MCAST`](./src/consts/MCAST.ts),
[`MSG`](./src/consts/MSG.ts),
[`NOTE`](./src/consts/NOTE.ts),
[`PF`](./src/consts/PF.ts),
[`POLL`](./src/consts/POLL.ts),
[`PROT`](./src/consts/PROT.ts),
[`S`](./src/consts/S.ts),
[`SA`](./src/consts/SA.ts),
[`SEEK`](./src/consts/SEEK.ts),
[`SEGV`](./src/consts/SEGV.ts),
[`SHM`](./src/consts/SHM.ts),
[`SHUT`](./src/consts/SHUT.ts),
[`SI`](./src/consts/SI.ts),
[`SIG`](./src/consts/SIG.ts),
[`SIGEV`](./src/consts/SIGEV.ts),
[`SO`](./src/consts/SO.ts),
[`SOCK`](./src/consts/SOCK.ts),
[`SOL`](./src/consts/SOL.ts),
[`TRAP`](./src/consts/TRAP.ts)
## License
[Unlicense](./LICENSE) — public domain.
[npm-url]: https://www.npmjs.com/package/libjs
[npm-badge]: https://img.shields.io/npm/v/libjs.svg
[travis-url]: https://travis-ci.org/streamich/libjs
[travis-badge]: https://travis-ci.org/streamich/libjs.svg?branch=master