mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
use fstat when we can
This avoids having things change between the stat and open.
This commit is contained in:
parent
45c62dfde6
commit
ff4a314022
2 changed files with 18 additions and 21 deletions
|
|
@ -59,21 +59,7 @@ int spa_v4l2_open(struct spa_v4l2_device *dev, const char *path)
|
|||
|
||||
spa_log_debug(dev->log, "v4l2: Playback device is '%s'", path);
|
||||
|
||||
if (stat(path, &st) < 0) {
|
||||
err = errno;
|
||||
spa_log_error(dev->log, "v4l2: Cannot identify '%s': %d, %s",
|
||||
path, err, strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!S_ISCHR(st.st_mode)) {
|
||||
spa_log_error(dev->log, "v4l2: %s is no device", path);
|
||||
err = ENODEV;
|
||||
goto error;
|
||||
}
|
||||
|
||||
dev->fd = open(path, O_RDWR | O_NONBLOCK, 0);
|
||||
|
||||
if (dev->fd == -1) {
|
||||
err = errno;
|
||||
spa_log_error(dev->log, "v4l2: Cannot open '%s': %d, %s",
|
||||
|
|
@ -81,6 +67,19 @@ int spa_v4l2_open(struct spa_v4l2_device *dev, const char *path)
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (fstat(dev->fd, &st) < 0) {
|
||||
err = errno;
|
||||
spa_log_error(dev->log, "v4l2: Cannot identify '%s': %d, %s",
|
||||
path, err, strerror(err));
|
||||
goto error_close;
|
||||
}
|
||||
|
||||
if (!S_ISCHR(st.st_mode)) {
|
||||
spa_log_error(dev->log, "v4l2: %s is no device", path);
|
||||
err = ENODEV;
|
||||
goto error_close;
|
||||
}
|
||||
|
||||
if (xioctl(dev->fd, VIDIOC_QUERYCAP, &dev->cap) < 0) {
|
||||
err = errno;
|
||||
spa_log_error(dev->log, "v4l2: '%s' QUERYCAP: %m", path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue