Open giulianobelinassi opened 1 year ago
The following code seems to be a reliable way of circunventing this issue:
FILE *slim_fopen(const char *path, const char *mode)
{
bool read = false;
const char *pmode = mode;
while (*pmode != '\0') {
switch (*pmode) {
case 'r':
read = true;
break;
default:
break;
}
pmode++;
}
/* If read is enabled then we need to check if the file exists. */
if (read && access(path, F_OK) != 0) {
/* File do not exist. */
return NULL;
}
return fopen(path, mode);
}
Call slim_fopen instead of fopen.
If file
f
is not present in the filesystem, attempting toWhich makes the library not work when detecting if a file exists with a simple fopen.