chown function

void chown(
  1. String filename,
  2. int owner,
  3. int group
)

Change the owner and group of FILE.

If the owner or group is specified as -1, then that ID is not changed.

If the call fails a PosixException is thrown with the value of errno.

Implementation

void chown(
  String filename,
  int owner,
  int group,
) {
  final cFilename = filename.toNativeUtf8();

  clearErrno();

  _chown ??= Libc().dylib.lookupFunction<
      ffi.Int32 Function(ffi.Pointer<Utf8>, ffi.Uint32, ffi.Uint32),
      _dart_chown>('chown');
  final results = _chown!(
    cFilename,
    owner,
    group,
  );
  malloc.free(cFilename);

  if (results != 0) {
    final error = errno();
    throw PosixException('chown failed error: ${strerror(error)}', error);
  }
}