confstr function

String confstr(
  1. int name
)

Get the value of the string-valued system variable NAME.

Implementation

String confstr(
  int name,
) {
  _confstr ??= Libc().dylib.lookupFunction<
      ffi.Uint64 Function(ffi.Int32, ffi.Pointer<ffi.Void>, ffi.Uint64),
      _dart_confstr>('confstr');
  final len = _confstr!(
    name,
    ffi.nullptr,
    0,
  );

  if (len == 0) {
    throw PosixException(strerror(errno()), errno());
  }

  final cBuf = malloc.allocate<ffi.Void>(len);

  final result = _confstr!(
    name,
    cBuf,
    len,
  );

  if (result == 0) {
    throw PosixException(strerror(errno()), errno());
  }

  return copyCBuffToDartString(cBuf);
}