diff options
author | 2023-03-07 12:22:34 -0800 | |
---|---|---|
committer | 2023-03-07 12:22:34 -0800 | |
commit | f7e4eb83694aa007a492ef66c28ffbe6a2dae791 (patch) | |
tree | 7af25aa5c42a2e1b2b47ba1df35f8caa9054cbeb /test/mkfifo.ts | |
parent | 36275a44ce7a33587bd26aad120042ab95470ff3 (diff) | |
download | bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.tar.gz bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.tar.zst bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.zip |
Reorganize tests (#2332)
Diffstat (limited to 'test/mkfifo.ts')
-rw-r--r-- | test/mkfifo.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/mkfifo.ts b/test/mkfifo.ts new file mode 100644 index 000000000..48471cbf5 --- /dev/null +++ b/test/mkfifo.ts @@ -0,0 +1,22 @@ +import { dlopen, ptr } from "bun:ffi"; + +var lazyMkfifo; +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`); + } +} |