Skip to content

Instantly share code, notes, and snippets.

@akirak
Created April 1, 2018 16:18
Show Gist options
  • Save akirak/7f54484a58d2a0f3082c5a0ccbf2257f to your computer and use it in GitHub Desktop.
Save akirak/7f54484a58d2a0f3082c5a0ccbf2257f to your computer and use it in GitHub Desktop.
Creating a temporary directory in Nim (using mkdtemp)
import posix
from system import `$`
proc mkdtemp*(tmpl: cstring): cstring {.importc, header: "<stdlib.h>".}
proc createTempDirectory*(tmpl: string): string =
var s = newString(tmpl.len)
s = tmpl
if mkdtemp(s.cstring()) == nil:
raise newException(IOError, "mkdtemp returns null")
else:
result = $s
echo createTempDirectory("/tmp/nim.XXXXXX")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment