blob: 1fd04572399c099e7af82d8af4c8cb2b3f1e39b1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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`);
}
}
|