提交 bd96c753 编写于 作者: S Shi Lei 提交者: Michal Privoznik

util: file: use VIR_AUTOCLOSE instead of VIR_FORCE_CLOSE

Signed-off-by: NShi Lei <shi_lei@massclouds.com>
上级 3e0786cc
......@@ -1969,29 +1969,22 @@ int
virFileIsCDROM(const char *path)
{
struct stat st;
int fd;
int ret = -1;
VIR_AUTOCLOSE fd = -1;
if ((fd = open(path, O_RDONLY | O_NONBLOCK)) < 0)
goto cleanup;
return -1;
if (fstat(fd, &st) < 0)
goto cleanup;
return -1;
if (!S_ISBLK(st.st_mode)) {
ret = 0;
goto cleanup;
}
if (!S_ISBLK(st.st_mode))
return 0;
/* Attempt to detect via a CDROM specific ioctl */
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) >= 0)
ret = 1;
else
ret = 0;
return 1;
cleanup:
VIR_FORCE_CLOSE(fd);
return ret;
return 0;
}
#else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册