Skip to content

Commit

Permalink
Merge pull request #17834 from hrydgard/cheat-db-fix
Browse files Browse the repository at this point in the history
OpenCFile: Fix Android content-uri append mode
  • Loading branch information
hrydgard authored Aug 2, 2023
2 parents 0b4fee1 + 9df91ae commit 3c0fdc1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Common/File/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,20 @@ FILE *OpenCFile(const Path &path, const char *mode) {
}

// TODO: Support append modes and stuff... For now let's go with the most common one.
int descriptor = Android_OpenContentUriFd(path.ToString(), Android_OpenContentUriMode::READ_WRITE_TRUNCATE);
Android_OpenContentUriMode openMode = Android_OpenContentUriMode::READ_WRITE_TRUNCATE;
const char *fmode = "wb";
if (!strcmp(mode, "at") || !strcmp(mode, "a")) {
openMode = Android_OpenContentUriMode::READ_WRITE;
fmode = "ab";
}
int descriptor = Android_OpenContentUriFd(path.ToString(), openMode);
if (descriptor < 0) {
INFO_LOG(COMMON, "Opening '%s' for write failed", path.ToString().c_str());
return nullptr;
}
FILE *f = fdopen(descriptor, "wb");
FILE *f = fdopen(descriptor, fmode);
if (f && (!strcmp(mode, "at") || !strcmp(mode, "a"))) {
// Append mode.
// Append mode - not sure we got a "true" append mode, so seek to the end.
fseek(f, 0, SEEK_END);
}
return f;
Expand Down

0 comments on commit 3c0fdc1

Please sign in to comment.