mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
filesystem: POSIX SDL_SYS_CopyFile shouldn't use a temp file.
Fixes #10957.
This commit is contained in:
@@ -83,23 +83,18 @@ bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath)
|
|||||||
bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath)
|
bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath)
|
||||||
{
|
{
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
char *tmppath = NULL;
|
|
||||||
SDL_IOStream *input = NULL;
|
SDL_IOStream *input = NULL;
|
||||||
SDL_IOStream *output = NULL;
|
SDL_IOStream *output = NULL;
|
||||||
const size_t maxlen = 4096;
|
const size_t maxlen = 4096;
|
||||||
size_t len;
|
size_t len;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (SDL_asprintf(&tmppath, "%s.tmp", newpath) < 0) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
input = SDL_IOFromFile(oldpath, "rb");
|
input = SDL_IOFromFile(oldpath, "rb");
|
||||||
if (!input) {
|
if (!input) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = SDL_IOFromFile(tmppath, "wb");
|
output = SDL_IOFromFile(newpath, "wb");
|
||||||
if (!output) {
|
if (!output) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@@ -125,28 +120,16 @@ bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SDL_CloseIO(output)) {
|
result = SDL_CloseIO(output);
|
||||||
output = NULL; // it's gone, even if it failed.
|
output = NULL; // it's gone, even if it failed.
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
output = NULL;
|
|
||||||
|
|
||||||
if (!SDL_RenamePath(tmppath, newpath)) {
|
|
||||||
SDL_RemovePath(tmppath);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (output) {
|
if (output) {
|
||||||
SDL_CloseIO(output);
|
SDL_CloseIO(output);
|
||||||
SDL_RemovePath(tmppath);
|
|
||||||
}
|
}
|
||||||
if (input) {
|
if (input) {
|
||||||
SDL_CloseIO(input);
|
SDL_CloseIO(input);
|
||||||
}
|
}
|
||||||
SDL_free(tmppath);
|
|
||||||
SDL_free(buffer);
|
SDL_free(buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user