Here's how I implemented [fwrite](https://github.com/khaledh/axiom/blob/e8c96c564c476a1d67ae372f8dfbab2dfdc74c5d/src/lib/libc.nim#L75-L83) in my [kernel](https://github.com/khaledh/axiom): type constCstringImpl {.importc: "const char *".} = cstring constCstring = distinct constCstringImpl constPointerImpl {.importc: "const void *".} = pointer constPointer = distinct constPointerImpl type CFile {.importc: "FILE", header: "<stdio.h>", incompleteStruct.} = object CFilePtr* = ptr CFile ## The type representing a file handle. proc fwrite*(buf {.noalias.}: constPointer, size, n: csize_t, f {.noalias.}: CFilePtr): csize_t {.exportc.} = let p = cast[ptr UncheckedArray[char]](buf) for i in 0..(n*size): print(&"{p[i]}") Run
In my case `print` uses the UEFI [Simple Text Output protocol](https://uefi.org/specs/UEFI/2.9_A/12_Protocols_Console_Support.html#efi-simple-text-output-protocol) instead of writing directly to the framebuffer, but that's beside the point.