pread function

List<int> pread(
  1. int fd,
  2. int nbytes,
  3. int offset
)

Read NBYTES and returns 'nbytes' from FD at the given position OFFSET without changing the file pointer.

Returns a List

Throws: PosixException if an error occurs reading the data.

Implementation

List<int> pread(
  int fd,
  int nbytes,
  int offset,
) {
  final cBuf = malloc.allocate<ffi.Int8>(nbytes);
  _pread ??= Libc().dylib.lookupFunction<
      ffi.Int64 Function(
          ffi.Int32, ffi.Pointer<ffi.Int8>, ffi.Uint64, ffi.Int64),
      _dart_pread>('pread');
  final read = _pread!(
    fd,
    cBuf,
    nbytes,
    offset,
  );

  _throwIfErrno('pread', read, cBuf);

  final buf = cBuf.asTypedList(read);
  malloc.free(cBuf);

  return buf;
}