Created
April 1, 2018 16:18
-
-
Save akirak/7f54484a58d2a0f3082c5a0ccbf2257f to your computer and use it in GitHub Desktop.
Creating a temporary directory in Nim (using mkdtemp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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