@weintek/libc/errno

When an error occurs while using FILE-related functions, use @weintek/libc/errno module to retrieve error codes indicating the cause.

Note:

  • The modules under @weintek/libc (e.g., errno, stdio, string, unistd) are heavily influenced by the design of C standard library.
  • The module is availabe when JS object/action is run on Local HMI)
Properties:
Name Type Description
EACCES Number

Permission denied. (13)

EAGAIN Number

Resource temporarily unavailable. Try again. (11)

EBADF Number

Bad file descriptor. (9)

EBUSY Number

Device or resource busy. (16)

EEXIST Number

File exists. (17)

EFAULT Number

Bad address. (14)

EINTR Number

Invalid argument. (4)

EINVAL Number

Input/output error. (22)

EIO Number

Interrupted function call. (5)

EISDIR Number

Is a directory. (21)

ELOOP Number

Too many levels of symbolic links. (114)

ENAMETOOLONG Number

File name too long. (38)

ENOENT Number

No such file or directory. (2)

ENOMEM Number

Cannot allocate memory. (12)

ENOSPC Number

No space left on device. (28)

ENOSYS Number

Function not implemented. (40)

ENOTDIR Number

Not a directory. (20)

EPERM Number

Operation not permitted. (1)

EPIPE Number

Broken pipe. (32)

EROFS Number

Read-only file system. (30)

ESPIPE Number

Invalid seek. (29)

Examples

Get error code and handle if it's an EINVAL error

const cerrno = await import('@weintek/libc/errno');
const cstdio = await import('@weintek/libc/stdio');
const file = cstdio.fopen('USB1', '/some/example/file', 'r+');
if (cstdio.fseek(file, -1, cstdio.SEEK_SET) !== 0) {
  const errCode = cerrno.getErrno();
  if (errCode === cerrno.EINVAL) {
    // do something...
  }
}

Return the last error

const cerrno = await import('@weintek/libc/errno');
const cstdio = await import('@weintek/libc/stdio');
const cstring = await import('@weintek/libc/string');
const disk = 'USB1';
const path = 'test';

try {
    cstdio.fopen(disk, path, "r");
} catch (error) {
    console.log('errno:', cerrno.getErrno())
    // errno: 2 (== cerrno.ENOENT)
    console.log('strerror returned:', cstring.strerror(cerrno.getErrno()))
    // strerror returned: No such file or directory 
    console.log('caught:', error);
    // caught: Error: No such file or directory at <anonymous> (<JS Object>:8)
}

Methods

(static) getErrno() → {Number}

Since:
  • EasyBuilder Pro V6.09.01
See:

This method returns the error code of the last occurred error. If no error has occurred, it returns zero.

Returns:
Type
Number