diff --git a/camera/drivers/video4linux2.c b/camera/drivers/video4linux2.c index 4dca67ee90..07e142e76d 100644 --- a/camera/drivers/video4linux2.c +++ b/camera/drivers/video4linux2.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include #include +#include #include @@ -300,7 +300,6 @@ static void v4l_free(void *data) static void *v4l_init(const char *device, uint64_t caps, unsigned width, unsigned height) { - struct stat st; video4linux_t *v4l = NULL; if ((caps & (UINT64_C(1) << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER)) == 0) @@ -320,14 +319,7 @@ static void *v4l_init(const char *device, uint64_t caps, v4l->height = height; v4l->ready = false; - if (stat(v4l->dev_name, &st) == -1) - { - RARCH_ERR("Cannot identify '%s' : %d, %s\n", v4l->dev_name, - errno, strerror(errno)); - goto error; - } - - if (!S_ISCHR(st.st_mode)) + if (!path_is_character_special(v4l->dev_name)) { RARCH_ERR("%s is no device.\n", v4l->dev_name); goto error; diff --git a/libretro-common/file/retro_stat.c b/libretro-common/file/retro_stat.c index 49ac1e86bb..e92e0e1b19 100644 --- a/libretro-common/file/retro_stat.c +++ b/libretro-common/file/retro_stat.c @@ -72,6 +72,53 @@ #include #include +enum stat_mode +{ + IS_DIRECTORY = 0, + IS_CHARACTER_SPECIAL +}; + +static bool path_stat(const char *path, enum stat_mode mode) +{ +#if defined(VITA) || defined(PSP) + SceIoStat buf; + if (sceIoGetstat(path, &buf) < 0) + return false; +#elif defined(__CELLOS_LV2__) + CellFsStat buf; + if (cellFsStat(path, &buf) < 0) + return false; +#elif defined(_WIN32) + DWORD ret = GetFileAttributes(path); +#else + struct stat buf; + if (stat(path, &buf) < 0) + return false; +#endif + + switch (mode) + { + case IS_DIRECTORY: +#if defined(VITA) || defined(PSP) + return FIO_SO_ISDIR(buf.st_mode); +#elif defined(__CELLOS_LV2__) + return ((buf.st_mode & S_IFMT) == S_IFDIR); +#elif defined(_WIN32) + return (ret & FILE_ATTRIBUTE_DIRECTORY) && (ret != INVALID_FILE_ATTRIBUTES); +#else + return S_ISDIR(buf.st_mode); +#endif + case IS_CHARACTER_SPECIAL: +#if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) || defined(_WIN32) + return false; +#else + return S_ISCHR(buf.st_mode); +#endif + } + + return false; +} + /** * path_is_directory: * @path : path @@ -82,26 +129,12 @@ */ bool path_is_directory(const char *path) { -#if defined(VITA) || defined(PSP) - SceIoStat buf; - if (sceIoGetstat(path, &buf) < 0) - return false; - return FIO_SO_ISDIR(buf.st_mode); -#elif defined(__CELLOS_LV2__) - CellFsStat buf; - if (cellFsStat(path, &buf) < 0) - return false; - return ((buf.st_mode & S_IFMT) == S_IFDIR); -#elif defined(_WIN32) - DWORD ret = GetFileAttributes(path); - return (ret & FILE_ATTRIBUTE_DIRECTORY) && (ret != INVALID_FILE_ATTRIBUTES); -#else - struct stat buf; - if (stat(path, &buf) < 0) - return false; + return path_stat(path, IS_DIRECTORY); +} - return S_ISDIR(buf.st_mode); -#endif +bool path_is_character_special(const char *path) +{ + return path_stat(path, IS_CHARACTER_SPECIAL); } /** diff --git a/libretro-common/include/retro_stat.h b/libretro-common/include/retro_stat.h index 1682c1ad44..eaec86889f 100644 --- a/libretro-common/include/retro_stat.h +++ b/libretro-common/include/retro_stat.h @@ -38,6 +38,8 @@ */ bool path_is_directory(const char *path); +bool path_is_character_special(const char *path); + bool path_is_valid(const char *path); /**