getlogin_r function

String getlogin_r()

Returns the login name.

Throws a PosixException if the name cannot be retrieved.

Implementation

String getlogin_r() {
  const maxLength = 32 + 1;
  final cName = malloc.allocate<Utf8>(maxLength);
  _getlogin_r ??= Libc().dylib.lookupFunction<
      ffi.Int32 Function(ffi.Pointer<Utf8>, ffi.Uint64),
      _dart_getlogin_r>('getlogin_r');
  final result = _getlogin_r!(
    cName,
    maxLength,
  );

  _throwIfErrno('getlogin_r', result, cName);

  final name = cName.toDartString();
  malloc.free(cName);

  return name;
}