Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more

deno-cstdlib

clang stdlib wrapper.

import { malloc, free, mblen } from 'https://deno.land/x/cstdlib@v0.0.3/mod.ts';
// or import { malloc } from 'https://deno.land/x/cstdlib/@0.0.3/malloc/malloc.ts';
// or import { free } from 'https://deno.land/x/cstdlib/@0.0.3/free/free.ts';
// or import { mblen } from 'https://deno.land/x/cstdlib/@0.0.3/mblen/mblen.ts';

// 8 byte malloc
let ptr = malloc(8);

// free ptr;
free(ptr);
import { mbtowc, free, calloc } from 'https://deno.land/x/cstdlib@v0.0.3/mod.ts';

const mbbuf = new TextEncoder().encode("ใ‚ใ„ใ†ใˆใŠ");
        const buf = new Uint8Array(buforig.length + 1);
        buf.set(buforig);
        buf[buf.length] = 0; // \0 terminator
        let result = puts(buf);

// ๅคงใ็›ฎใซใจใ‚‹ใ€‚ๆ–‡็ซ ใชใ‚‰1024่ฆ‹ใŸใ„ใชๅ–ใ‚Šๆ–นใ‚’ใ—ใฆใ‚‚ใ‚ˆใ„ใ€‚
// 
let wchar_size = 2
let wchar_p = calloc(7, wchar_size);
// ใ“ใ‚Œใ‚‚ๅคงใ็›ฎใงใ‚ˆใ„ใ€‚
let size = 1024;

mbtowc(wchar_p, mbbuf, size);

// ใƒฏใ‚คใƒ‰ๆ–‡ๅญ—ใŒๅฟ…้ ˆใชๅฅดใซๆธกใ™ใ€‚

// const wchar_view = new Deno.UnsafePointerView(wchar_p);

// const f_bsize = statvfs_view.getBigUint64(0) as bigint;