read function
Read NBYTES from FD. Returning the bytes read.
The returned array will be empty if EOF was reached.
Throws a PosixException if an error occurs.
This function is a cancellation point and therefore not marked with __THROW.
Implementation
List<int> read(
int fd,
int nbytes,
) {
final cBuf = malloc.allocate<ffi.Int8>(nbytes);
_read ??= Libc().dylib.lookupFunction<
ffi.Int64 Function(ffi.Int32, ffi.Pointer<ffi.Int8>, ffi.Uint64),
_dart_read>('read');
final result = _read!(
fd,
cBuf,
nbytes,
);
_throwIfErrno('read', result, cBuf);
final buf = cBuf.asTypedList(result);
malloc.free(cBuf);
return buf;
}