/** * This is all the nasty ffi setup for the bun runtime */ import { dlopen, ptr, suffix } from "bun:ffi"; const getLib = (name: string) => { return dlopen( name, { tcgetattr: { args: ['i32', 'pointer'], returns: 'i32', }, tcsetattr: { args: ['i32', 'i32', 'pointer'], returns: 'i32', }, cfmakeraw: { args: ['pointer'], returns: 'void', }, }, ); } let cStdLib = {symbols: {}}; try { cStdLib = getLib(`libc.${suffix}`); } catch { try { cStdLib = getLib(`libc.${suffix}.6`); } catch { throw new Error('Could not find c standard library'); } } export const { tcgetattr, tcsetattr, cfmakeraw } = cStdLib.symbols; export const getPointer = ptr;