@weintek/libc/errno
The @weintek/libc/errno module provides error codes for FILE-related operations and a method to retrieve the last error.
Influenced by the C standard library.
Note: Available when a Custom Model script runs on a local HMI.
Import
js
const cerrno = await import('@weintek/libc/errno');Example: Catch a file error and inspect it
js
const cerrno = await import('@weintek/libc/errno');
const cstdio = await import('@weintek/libc/stdio');
const cstring = await import('@weintek/libc/string');
try {
cstdio.fopen('USB1', 'test', "r");
} catch (error) {
console.log('errno:', cerrno.getErrno());
// errno: 2 (== cerrno.ENOENT)
console.log('strerror:', cstring.strerror(cerrno.getErrno()));
// strerror: No such file or directory
}Functions
getErrno()
Returns the last error number.
Returns: Number — The corresponding error code.
Error Constants
| Constant | Value | Description |
|---|---|---|
EPERM | 1 | Operation not permitted |
ENOENT | 2 | No such file or directory |
EIO | 5 | Interrupted function call |
EBADF | 9 | Bad file descriptor |
EAGAIN | 11 | Resource temporarily unavailable |
ENOMEM | 12 | Cannot allocate memory |
EACCES | 13 | Permission denied |
EFAULT | 14 | Bad address |
EBUSY | 16 | Device or resource busy |
EEXIST | 17 | File exists |
ENOTDIR | 20 | Not a directory |
EISDIR | 21 | Is a directory |
EINVAL | 22 | Input/output error |
ENOSPC | 28 | No space left on device |
ESPIPE | 29 | Invalid seek |
EROFS | 30 | Read-only file system |
EPIPE | 32 | Broken pipe |
ENAMETOOLONG | 38 | File name too long |
ENOSYS | 40 | Function not implemented |
ELOOP | 114 | Too many levels of symbolic links |