Skip to content

Commit

Permalink
fix fileErrno on node
Browse files Browse the repository at this point in the history
- adds missing cases and fixes fallback values
- fix sign of getErrno
  • Loading branch information
dunhamsteve committed Feb 24, 2025
1 parent 0cfcd5d commit e2d1e45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion support/js/support_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ function support_system_unsetEnv(name) {
}

function support_system_getErrno() {
return process.__lasterr===undefined?0:process.__lasterr.errno || 0
return process.__lasterr === undefined ? 0 : -process.__lasterr.errno || 0
}
10 changes: 7 additions & 3 deletions support/js/support_system_file.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const support_system_file_fs = require('fs')
const support_system_file_child_process = require('child_process')

// See System/File/Error.idr for return values
function support_system_file_fileErrno(){
const n = process.__lasterr===undefined?0:process.__lasterr.errno || 0
if (process.platform == 'win32') {
// TODO: Add the error codes for the other errors
switch(n) {
// these are documented in include/uv/errno.h of libuv
case -4058: return 2
case -4092: return 3
case -4075: return 4
default: return -n
default: return -n + 5
}
} else {
switch(n){
case -2: return 2
case -13: return 3
case -17: return 4
default: return -n
default: return -n + 5
}
}
}
Expand Down

0 comments on commit e2d1e45

Please sign in to comment.