It's not a big deal for a game config file, but this code isn't great, in that it has a race condition. You first check with opendir whether the directory exists. If it does not, you try to create it with mkdir. It is possible that between the time that you check for its existence and the time that you try to create it, someone else could create it.
A better solution would be to just call mkdir unconditionally and check its return code: if it reports that the directory was created, or that the directory already existed, then you're fine; if it reports some other error, you should report it to the user, via whatever means you usually use to do that.
Sorry, this is the correct patch.
It's not a big deal for a game config file, but this code isn't great, in that it has a race condition. You first check with
opendirwhether the directory exists. If it does not, you try to create it withmkdir. It is possible that between the time that you check for its existence and the time that you try to create it, someone else could create it.A better solution would be to just call
mkdirunconditionally and check its return code: if it reports that the directory was created, or that the directory already existed, then you're fine; if it reports some other error, you should report it to the user, via whatever means you usually use to do that.