(camera/drivers/video4linux2.c) Use path_is_character_special

This commit is contained in:
twinaphex 2015-09-22 21:16:58 +02:00
parent 385e030261
commit ff1078a98b
3 changed files with 56 additions and 29 deletions

View File

@ -24,7 +24,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/ioctl.h>
@ -35,6 +34,7 @@
#include <memmap.h>
#include <retro_miscellaneous.h>
#include <gfx/scaler/scaler.h>
#include <retro_stat.h>
#include <compat/strl.h>
@ -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;

View File

@ -72,6 +72,53 @@
#include <retro_miscellaneous.h>
#include <boolean.h>
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);
}
/**

View File

@ -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);
/**