mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 05:25:18 +00:00
Add virDirOpenIfExists
Just like virDirOpen, but it returns 0 without reporting an error on ENOENT.
This commit is contained in:
parent
e81de04c10
commit
941ccbc174
@ -1496,6 +1496,7 @@ virBuildPathInternal;
|
|||||||
virDirClose;
|
virDirClose;
|
||||||
virDirCreate;
|
virDirCreate;
|
||||||
virDirOpen;
|
virDirOpen;
|
||||||
|
virDirOpenIfExists;
|
||||||
virDirRead;
|
virDirRead;
|
||||||
virFileAbsPath;
|
virFileAbsPath;
|
||||||
virFileAccessibleAs;
|
virFileAccessibleAs;
|
||||||
|
@ -2723,10 +2723,12 @@ virFileRemove(const char *path,
|
|||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDirOpenInternal(DIR **dirp, const char *name)
|
virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT)
|
||||||
{
|
{
|
||||||
*dirp = opendir(name);
|
*dirp = opendir(name);
|
||||||
if (!*dirp) {
|
if (!*dirp) {
|
||||||
|
if (ignoreENOENT && errno == ENOENT)
|
||||||
|
return 0;
|
||||||
virReportSystemError(errno, _("cannot open directory '%s'"), name);
|
virReportSystemError(errno, _("cannot open directory '%s'"), name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2744,7 +2746,22 @@ virDirOpenInternal(DIR **dirp, const char *name)
|
|||||||
int
|
int
|
||||||
virDirOpen(DIR **dirp, const char *name)
|
virDirOpen(DIR **dirp, const char *name)
|
||||||
{
|
{
|
||||||
return virDirOpenInternal(dirp, name);
|
return virDirOpenInternal(dirp, name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDirOpenIfExists
|
||||||
|
* @dirp: directory stream
|
||||||
|
* @name: path of the directory
|
||||||
|
*
|
||||||
|
* Returns 1 on success.
|
||||||
|
* If opendir returns ENOENT, 0 is returned without reporting an error.
|
||||||
|
* On other errors, -1 is returned and an error is reported.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virDirOpenIfExists(DIR **dirp, const char *name)
|
||||||
|
{
|
||||||
|
return virDirOpenInternal(dirp, name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,6 +232,8 @@ int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
|
|||||||
unsigned int flags) ATTRIBUTE_RETURN_CHECK;
|
unsigned int flags) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virDirOpen(DIR **dirp, const char *dirname)
|
int virDirOpen(DIR **dirp, const char *dirname)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int virDirOpenIfExists(DIR **dirp, const char *dirname)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname)
|
int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
void virDirClose(DIR **dirp)
|
void virDirClose(DIR **dirp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user