sdlRenamePath function filesystem

bool sdlRenamePath(
  1. String? oldpath,
  2. String? newpath
)

Rename a file or directory.

If the file at newpath already exists, it will be replaced.

Note that this will not copy files across filesystems/drives/volumes, as that is a much more complicated (and possibly time-consuming) operation.

Which is to say, if this function fails, SDL_CopyFile() to a temporary file in the same directory as newpath, then SDL_RenamePath() from the temporary file to newpath and SDL_RemovePath() on oldpath might work for files. Renaming a non-empty directory across filesystems is dramatically more complex, however.

\param oldpath the old path. \param newpath the new path. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.2.0.

extern SDL_DECLSPEC bool SDLCALL SDL_RenamePath(const char *oldpath, const char *newpath)

Implementation

bool sdlRenamePath(String? oldpath, String? newpath) {
  final sdlRenamePathLookupFunction = _libSdl
      .lookupFunction<
        Uint8 Function(Pointer<Utf8> oldpath, Pointer<Utf8> newpath),
        int Function(Pointer<Utf8> oldpath, Pointer<Utf8> newpath)
      >('SDL_RenamePath');
  final oldpathPointer = oldpath != null ? oldpath.toNativeUtf8() : nullptr;
  final newpathPointer = newpath != null ? newpath.toNativeUtf8() : nullptr;
  final result =
      sdlRenamePathLookupFunction(oldpathPointer, newpathPointer) == 1;
  calloc
    ..free(oldpathPointer)
    ..free(newpathPointer);
  return result;
}