diff options
author | Josh Meredith <joshmeredith2008@gmail.com> | 2023-04-13 16:12:38 +0000 |
---|---|---|
committer | Josh Meredith <joshmeredith2008@gmail.com> | 2023-04-21 17:17:01 +0000 |
commit | 8b9132c39a150dae18d93822a6b419543e5bc4a8 (patch) | |
tree | eeefb698fe4dce470bb7449f2ef32ae567162ce3 /libraries/base/jsbits/base.js | |
parent | df1a581188694479a583270548896245fc23b525 (diff) | |
download | haskell-wip/js-mkdir.tar.gz |
JS/base: provide implementation for mkdir (issue 22374)wip/js-mkdir
Diffstat (limited to 'libraries/base/jsbits/base.js')
-rw-r--r-- | libraries/base/jsbits/base.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libraries/base/jsbits/base.js b/libraries/base/jsbits/base.js index b9e0b84ce1..1f0123943b 100644 --- a/libraries/base/jsbits/base.js +++ b/libraries/base/jsbits/base.js @@ -889,3 +889,21 @@ function h$__hscore_free_dirent(a,o) { function h$__hscore_d_name(a,o) { RETURN_UBX_TUP2(h$encodeModifiedUtf8(a.name),0); } + +function h$mkdir(path, path_offset, mode) { + if (!h$isNode()) { + throw "h$mkdir unsupported"; + } + const d = h$decodeUtf8z(path, path_offset); + try { + h$fs.mkdirSync(d, {mode: mode}); + } catch(e) { + // we can't directly set errno code, because numbers may not match + // e.g. e.errno is -17 for EEXIST while we would expect -20 + // this is probably an inconsistency between nodejs using the native + // environment and everything else using Emscripten-provided headers. + h$setErrno(e); + return -1; + } + return 0; +} |