mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-13 08:05:16 +00:00
tests: Introduce testQemuCapsIterate()
This function iterates over a directory containing capabilities-related data, extract some useful bits of information from the file name, and calls a user-provided callback. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Acked-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
6000bd1342
commit
30439c1b81
@ -865,3 +865,56 @@ testQemuGetLatestCapsForArch(const char *dirname,
|
|||||||
virDirClose(&dir);
|
virDirClose(&dir);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
testQemuCapsIterate(const char *dirname,
|
||||||
|
const char *suffix,
|
||||||
|
testQemuCapsIterateCallback callback,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
struct dirent *ent;
|
||||||
|
DIR *dir = NULL;
|
||||||
|
int rc;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!callback)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (virDirOpen(&dir, dirname) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
while ((rc = virDirRead(dir, &ent, dirname) > 0)) {
|
||||||
|
char *tmp = ent->d_name;
|
||||||
|
char *base = NULL;
|
||||||
|
char *archName = NULL;
|
||||||
|
|
||||||
|
/* Strip the trailing suffix, moving on if it's not present */
|
||||||
|
if (!virStringStripSuffix(tmp, suffix))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Find the last dot, moving on if none is present */
|
||||||
|
if (!(archName = strrchr(tmp, '.')))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* The base name is everything before the last dot, and
|
||||||
|
* the architecture name everything after it */
|
||||||
|
base = tmp;
|
||||||
|
archName[0] = '\0';
|
||||||
|
archName++;
|
||||||
|
|
||||||
|
/* Run the user-provided callback */
|
||||||
|
if (callback(base, archName, opaque) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virDirClose(&dir);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -63,6 +63,14 @@ char *testQemuGetLatestCapsForArch(const char *dirname,
|
|||||||
const char *arch,
|
const char *arch,
|
||||||
const char *suffix);
|
const char *suffix);
|
||||||
|
|
||||||
|
typedef int (*testQemuCapsIterateCallback)(const char *base,
|
||||||
|
const char *archName,
|
||||||
|
void *opaque);
|
||||||
|
int testQemuCapsIterate(const char *dirname,
|
||||||
|
const char *suffix,
|
||||||
|
testQemuCapsIterateCallback callback,
|
||||||
|
void *opaque);
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif /* LIBVIRT_TESTUTILSQEMU_H */
|
#endif /* LIBVIRT_TESTUTILSQEMU_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user