io: Wrap IsRegularFileOrPipe in a more generic preprocessor test.

This way we can turn it off for various console platforms without changes
to this file.
This commit is contained in:
Ryan C. Gordon
2026-03-12 11:26:45 -04:00
parent 803cd7589a
commit 4d675f2bd3

View File

@@ -964,18 +964,22 @@ static bool SDLCALL mem_close(void *userdata)
// Functions to create SDL_IOStream structures from various data sources // Functions to create SDL_IOStream structures from various data sources
#if defined(HAVE_STDIO_H) && !defined(SDL_PLATFORM_WINDOWS) // private platforms might define SKIP_STDIO_DIR_TEST in their build configs, too.
#if defined(SDL_PLATFORM_WINDOWS) || defined(SDL_PLATFORM_EMSCRIPTEN)
#define SKIP_STDIO_DIR_TEST 1
#endif
#if defined(HAVE_STDIO_H) && !defined(SKIP_STDIO_DIR_TEST)
static bool IsRegularFileOrPipe(FILE *f) static bool IsRegularFileOrPipe(FILE *f)
{ {
#ifndef SDL_PLATFORM_EMSCRIPTEN
struct stat st; struct stat st;
if (fstat(fileno(f), &st) < 0 || !(S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode))) { if (fstat(fileno(f), &st) < 0 || !(S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode))) {
return false; return false;
} }
#endif // !SDL_PLATFORM_EMSCRIPTEN
return true; return true;
} }
#else
#define IsRegularFileOrPipe(f) false
#endif #endif
SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode) SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)