pwrite function

int pwrite(
  1. int fd,
  2. List<int> buf,
  3. int offset
)

Write N bytes of BUF to FD at the given position OFFSET without changing the file pointer. Return the number of bytes written

Throws a PosixException if an error occurs.

Implementation

int pwrite(
  int fd,
  List<int> buf, // ffi.Pointer<ffi.Void> buf,
  int offset,
) {
  final cBuf = copyDartListToCBuff(buf);

  _pwrite ??= Libc().dylib.lookupFunction<
      ffi.Int64 Function(
          ffi.Int32, ffi.Pointer<ffi.Int8>, ffi.Uint64, ffi.Int64),
      _dart_pwrite>('pwrite');
  final written = _pwrite!(
    fd,
    cBuf,
    buf.length,
    offset,
  );

  _throwIfErrno('pwrite', written, cBuf);

  malloc.free(cBuf);

  return written;
}