mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
util: file: use VIR_AUTOCLOSE instead of VIR_FORCE_CLOSE
Signed-off-by: Shi Lei <shi_lei@massclouds.com>
This commit is contained in:
parent
3e0786cc46
commit
bd96c753e2
@ -1969,29 +1969,22 @@ int
|
|||||||
virFileIsCDROM(const char *path)
|
virFileIsCDROM(const char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int fd;
|
VIR_AUTOCLOSE fd = -1;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if ((fd = open(path, O_RDONLY | O_NONBLOCK)) < 0)
|
if ((fd = open(path, O_RDONLY | O_NONBLOCK)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (fstat(fd, &st) < 0)
|
if (fstat(fd, &st) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!S_ISBLK(st.st_mode)) {
|
if (!S_ISBLK(st.st_mode))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Attempt to detect via a CDROM specific ioctl */
|
/* Attempt to detect via a CDROM specific ioctl */
|
||||||
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) >= 0)
|
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) >= 0)
|
||||||
ret = 1;
|
return 1;
|
||||||
else
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user