42 lines
760 B
JavaScript
42 lines
760 B
JavaScript
|
// Deno-specific ffi code
|
||
|
|
||
|
// Determine library extension based on
|
||
|
// your OS.
|
||
|
// import { termiosStruct } from "../common/termios.ts";
|
||
|
|
||
|
let libSuffix = '';
|
||
|
switch (Deno.build.os) {
|
||
|
case 'windows':
|
||
|
libSuffix = 'dll';
|
||
|
break;
|
||
|
case 'darwin':
|
||
|
libSuffix = 'dylib';
|
||
|
break;
|
||
|
default:
|
||
|
libSuffix = 'so.6';
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
const cSharedLib = `libc.${libSuffix}`;
|
||
|
const cStdLib = Deno.dlopen(
|
||
|
cSharedLib,
|
||
|
{
|
||
|
tcgetattr: {
|
||
|
parameters: ['i32', 'pointer'],
|
||
|
result: 'i32',
|
||
|
},
|
||
|
tcsetattr: {
|
||
|
parameters: ['i32', 'i32', 'pointer'],
|
||
|
result: 'i32',
|
||
|
},
|
||
|
cfmakeraw: {
|
||
|
parameters: ['pointer'],
|
||
|
result: 'void',
|
||
|
},
|
||
|
} as const,
|
||
|
);
|
||
|
|
||
|
export const { tcgetattr, tcsetattr, cfmakeraw} = cStdLib.symbols;
|
||
|
|
||
|
export const getPointer = Deno.UnsafePointer.of;
|