linkat function

void linkat(
  1. int __fromfd,
  2. String from,
  3. int __tofd,
  4. String to,
  5. int flags,
)

Like link but relative paths in TO and FROM are interpreted relative to FROMFD and TOFD respectively.

Throws a PosixException if an error occurs.

Implementation

void linkat(
  int __fromfd,
  String from,
  int __tofd,
  String to,
  int flags,
) {
  final cFrom = from.toNativeUtf8();
  final cTo = to.toNativeUtf8();

  _linkat ??= Libc().dylib.lookupFunction<
      ffi.Int32 Function(ffi.Int32, ffi.Pointer<Utf8>, ffi.Int32,
          ffi.Pointer<Utf8>, ffi.Int32),
      _dart_linkat>('linkat');
  final result = _linkat!(
    __fromfd,
    cFrom,
    __tofd,
    cTo,
    flags,
  );

  _throwIfErrno('symlink', result, cFrom, cTo);

  malloc
    ..free(cFrom)
    ..free(cTo);
}