How to use the bindings/wasi.path_open function in bindings

To help you get started, we’ve selected a few bindings examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jedisct1 / as-wasi / assembly / wasa.ts View on Github external
static openForWrite(path: string, dirfd: Descriptor = 3): Descriptor {
    let fd_lookup_flags = lookupflags.SYMLINK_FOLLOW;
    let fd_oflags: oflags = oflags.CREAT;
    let fd_rights =
      rights.FD_WRITE |
      rights.FD_SEEK |
      rights.FD_TELL |
      rights.FD_FILESTAT_GET |
      rights.PATH_CREATE_FILE;
    let fd_rights_inherited = fd_rights;
    let fd_flags: fdflags = 0;
    let path_utf8_len: usize = path.lengthUTF8 - 1;
    let path_utf8 = path.toUTF8();
    let fd_buf = changetype(new ArrayBuffer(sizeof()));
    let res = path_open(
      dirfd as fd,
      fd_lookup_flags,
      path_utf8,
      path_utf8_len,
      fd_oflags,
      fd_rights,
      fd_rights_inherited,
      fd_flags,
      fd_buf
    );
    if (res != errno.SUCCESS) {
      return InvalidDescriptor;
    }
    let fd = load(fd_buf);

    return fd as Descriptor;
github jedisct1 / as-wasi / assembly / wasa.ts View on Github external
static openForRead(path: string, dirfd: Descriptor = 3): Descriptor {
    let fd_lookup_flags = lookupflags.SYMLINK_FOLLOW;
    let fd_oflags: oflags = 0;
    let fd_rights =
      rights.FD_READ | rights.FD_SEEK | rights.FD_TELL | rights.FD_FILESTAT_GET;
    let fd_rights_inherited = fd_rights;
    let fd_flags: fdflags = 0;
    let path_utf8_len: usize = path.lengthUTF8 - 1;
    let path_utf8 = path.toUTF8();
    let fd_buf = changetype(new ArrayBuffer(sizeof()));
    let res = path_open(
      dirfd as fd,
      fd_lookup_flags,
      path_utf8,
      path_utf8_len,
      fd_oflags,
      fd_rights,
      fd_rights_inherited,
      fd_flags,
      fd_buf
    );
    if (res != errno.SUCCESS) {
      return InvalidDescriptor;
    }
    let fd = load(fd_buf);

    return fd as Descriptor;