2023-11-01 15:05:31 -04:00
|
|
|
// 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,
|
|
|
|
);
|
|
|
|
|
2023-11-01 15:27:31 -04:00
|
|
|
export const { tcgetattr, tcsetattr, cfmakeraw } = cStdLib.symbols;
|
2023-11-01 15:05:31 -04:00
|
|
|
|
|
|
|
export const getPointer = Deno.UnsafePointer.of;
|