Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow shared file opening when using secure CRT functions #331

Merged

Conversation

Jamiras
Copy link
Member

@Jamiras Jamiras commented Apr 19, 2024

https://discord.com/channels/310192285306454017/1230730290650026055/1230929459574607952

fopen_s and _wfopen_s cannot open files already opened by another piece of code.

The fopen_s and _wfopen_s functions can't open a file for sharing. If you need to share the file, use _fsopen or _wfsopen with the appropriate sharing mode constant

This switches them out for _fsopen and _wfsopen, which also don't generate the secure CRT warning and support opening files already open by another piece of code. These are Windows only, so fopen_s is still used if WINVER is not defined, but the likelihood of that happening and __STDC_WANT_SECURE_LIB__ being defined is minimal.

The need for opening files in shared mode stems from the blueMSX core holding a write lock on a dsk file so it can potentially modify it. The core should not be modifying the original dsk file. Instead it should be creating a copy to modify (see libretro/blueMSX-libretro#134).

@Jamiras Jamiras added this to the 11.3.0 milestone Apr 19, 2024
@Jamiras Jamiras merged commit 2de5c9b into RetroAchievements:develop May 1, 2024
7 checks passed
@Jamiras Jamiras deleted the bugfix/secure_fopen_sharing branch May 1, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant