Files
bun.sh/test/mkfifo.ts
Colin McDonnell a5f92224b5 Fix types (#2453)
* WIP

* WIP

* WIP

* WIP

* Improve typechecking in type files

* Fix typechecking

* Update

* Update submodule

* CI for typechecking

* Add ci

* Update commands

* Format after build

* Dont use bunx

* Rename job

* Use nodemodules prettier

* Update workflow

* Use symlink

* Debug

* Debug

* Clean up and rename jobs
2023-03-22 15:01:01 -07:00

23 lines
587 B
TypeScript

import { dlopen, ptr } from "bun:ffi";
var lazyMkfifo: any;
export function mkfifo(path: string, permissions: number = 0o666): void {
if (!lazyMkfifo) {
const suffix = process.platform === "darwin" ? "dylib" : "so.6";
lazyMkfifo = dlopen(`libc.${suffix}`, {
mkfifo: {
args: ["ptr", "i32"],
returns: "i32",
},
}).symbols.mkfifo;
}
const buf = new Uint8Array(Buffer.byteLength(path) + 1);
new TextEncoder().encodeInto(path, buf);
const rc = lazyMkfifo(ptr(buf), permissions);
if (rc < 0) {
throw new Error(`mkfifo failed`);
}
}