Merge pull request #4526 from doofin/master

add `get current directory name`
This commit is contained in:
Niklas Larsson 2018-07-25 23:59:41 +02:00 committed by GitHub
commit 86126a72fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -375,3 +375,9 @@ changeDir : String -> IO Bool
changeDir dir
= do ok <- foreign FFI_C "idris_chdir" (String -> IO Int) dir
pure (ok == 0)
export
currentDir : IO String
currentDir = do
MkRaw s <- foreign FFI_C "idris_currentDir" (IO (Raw String))
pure s

View File

@ -259,3 +259,11 @@ VAL idris_getString(VM* vm, void* buffer) {
free(sb);
return str;
}
VAL idris_currentDir() {
char cwd[1024];
if (getcwd(cwd, sizeof(cwd)) != NULL)
return MKSTR(get_vm(),cwd);
else
return MKSTR(get_vm(),"");
}

View File

@ -55,4 +55,6 @@ VAL idris_time();
void idris_forceGC();
VAL idris_currentDir();
#endif