|
@@ -970,16 +970,13 @@ static bool SDLCALL mem_close(void *userdata)
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_STDIO_H) && !defined(SKIP_STDIO_DIR_TEST)
|
|
#if defined(HAVE_STDIO_H) && !defined(SKIP_STDIO_DIR_TEST)
|
|
|
-static bool IsRegularFileOrPipe(FILE *f)
|
|
|
|
|
|
|
+static bool IsStdioFileADirectory(FILE *f)
|
|
|
{
|
|
{
|
|
|
struct stat st;
|
|
struct stat st;
|
|
|
- if (fstat(fileno(f), &st) < 0 || !(S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode))) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ return ((fstat(fileno(f), &st) == 0) && (S_ISDIR(st.st_mode)));
|
|
|
}
|
|
}
|
|
|
#else
|
|
#else
|
|
|
-#define IsRegularFileOrPipe(f) false
|
|
|
|
|
|
|
+#define IsStdioFileADirectory(f) false
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|
SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|
@@ -1001,9 +998,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|
|
if (*file == '/') {
|
|
if (*file == '/') {
|
|
|
FILE *fp = fopen(file, mode);
|
|
FILE *fp = fopen(file, mode);
|
|
|
if (fp) {
|
|
if (fp) {
|
|
|
- if (!IsRegularFileOrPipe(fp)) {
|
|
|
|
|
|
|
+ if (IsStdioFileADirectory(fp)) {
|
|
|
fclose(fp);
|
|
fclose(fp);
|
|
|
- SDL_SetError("%s is not a regular file or pipe", file);
|
|
|
|
|
|
|
+ SDL_SetError("%s is a directory", file);
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
return SDL_IOFromFP(fp, true);
|
|
return SDL_IOFromFP(fp, true);
|
|
@@ -1032,9 +1029,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|
|
FILE *fp = fopen(path, mode);
|
|
FILE *fp = fopen(path, mode);
|
|
|
SDL_free(path);
|
|
SDL_free(path);
|
|
|
if (fp) {
|
|
if (fp) {
|
|
|
- if (!IsRegularFileOrPipe(fp)) {
|
|
|
|
|
|
|
+ if (IsStdioFileADirectory(fp)) {
|
|
|
fclose(fp);
|
|
fclose(fp);
|
|
|
- SDL_SetError("%s is not a regular file or pipe", path);
|
|
|
|
|
|
|
+ SDL_SetError("%s is a directory", path);
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
return SDL_IOFromFP(fp, true);
|
|
return SDL_IOFromFP(fp, true);
|
|
@@ -1098,9 +1095,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|
|
|
|
|
|
|
if (!fp) {
|
|
if (!fp) {
|
|
|
SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
|
|
SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
|
|
|
- } else if (!IsRegularFileOrPipe(fp)) {
|
|
|
|
|
|
|
+ } else if (IsStdioFileADirectory(fp)) {
|
|
|
fclose(fp);
|
|
fclose(fp);
|
|
|
- SDL_SetError("%s is not a regular file or pipe", file);
|
|
|
|
|
|
|
+ SDL_SetError("%s is a directory", file);
|
|
|
} else {
|
|
} else {
|
|
|
iostr = SDL_IOFromFP(fp, true);
|
|
iostr = SDL_IOFromFP(fp, true);
|
|
|
}
|
|
}
|
|
@@ -1121,9 +1118,9 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|
|
|
|
|
|
|
if (!fp) {
|
|
if (!fp) {
|
|
|
SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
|
|
SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
|
|
|
- } else if (!IsRegularFileOrPipe(fp)) {
|
|
|
|
|
|
|
+ } else if (IsStdioFileADirectory(fp)) {
|
|
|
fclose(fp);
|
|
fclose(fp);
|
|
|
- SDL_SetError("%s is not a regular file or pipe", file);
|
|
|
|
|
|
|
+ SDL_SetError("%s is a directory", file);
|
|
|
} else {
|
|
} else {
|
|
|
iostr = SDL_IOFromFP(fp, true);
|
|
iostr = SDL_IOFromFP(fp, true);
|
|
|
}
|
|
}
|