本文整理汇总了C++中ARRAY_CARDINALITY函数的典型用法代码示例。如果您正苦于以下问题:C++ ARRAY_CARDINALITY函数的具体用法?C++ ARRAY_CARDINALITY怎么用?C++ ARRAY_CARDINALITY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ARRAY_CARDINALITY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testQemuAddArmGuest
static int testQemuAddArmGuest(virCapsPtr caps)
{
static const char *machines[] = { "vexpress-a9",
"vexpress-a15",
"versatilepb" };
virCapsGuestMachinePtr *capsmachines = NULL;
virCapsGuestPtr guest;
capsmachines = virCapabilitiesAllocMachines(machines,
ARRAY_CARDINALITY(machines));
if (!capsmachines)
goto error;
guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_ARMV7L,
"/usr/bin/qemu-system-arm", NULL,
ARRAY_CARDINALITY(machines),
capsmachines);
if (!guest)
goto error;
if (!virCapabilitiesAddGuestDomain(guest, "qemu", NULL, NULL, 0, NULL))
goto error;
return 0;
error:
virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines));
return -1;
}
示例2: testQemuAddS390Guest
static int testQemuAddS390Guest(virCapsPtr caps)
{
static const char *s390_machines[] = { "s390-virtio",
"s390-ccw-virtio" };
virCapsGuestMachinePtr *machines = NULL;
virCapsGuestPtr guest;
machines = virCapabilitiesAllocMachines(s390_machines,
ARRAY_CARDINALITY(s390_machines));
if (!machines)
goto error;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_S390X,
"/usr/bin/qemu-system-s390x", NULL,
ARRAY_CARDINALITY(s390_machines),
machines);
if (!guest)
goto error;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
goto error;
return 0;
error:
virCapabilitiesFreeMachines(machines, ARRAY_CARDINALITY(s390_machines));
return -1;
}
示例3: testAddCPUModels
static int
testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy)
{
const char *newModels[] = {
"Opteron_G3", "Opteron_G2", "Opteron_G1",
"Nehalem", "Penryn", "Conroe",
};
const char *legacyModels[] = {
"n270", "athlon", "pentium3", "pentium2", "pentium",
"486", "coreduo", "kvm32", "qemu32", "kvm64",
"core2duo", "phenom", "qemu64",
};
size_t i;
for (i = 0; i < ARRAY_CARDINALITY(newModels); i++) {
if (virQEMUCapsAddCPUDefinition(caps, newModels[i]) < 0)
return -1;
}
if (skipLegacy)
return 0;
for (i = 0; i < ARRAY_CARDINALITY(legacyModels); i++) {
if (virQEMUCapsAddCPUDefinition(caps, legacyModels[i]) < 0)
return -1;
}
return 0;
}
示例4: testQemuAddAARCH64Guest
static int testQemuAddAARCH64Guest(virCapsPtr caps)
{
static const char *machines[] = { "virt"};
virCapsGuestMachinePtr *capsmachines = NULL;
virCapsGuestPtr guest;
capsmachines = virCapabilitiesAllocMachines(machines,
ARRAY_CARDINALITY(machines));
if (!capsmachines)
goto error;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_AARCH64,
"/usr/bin/qemu-system-aarch64", NULL,
ARRAY_CARDINALITY(machines),
capsmachines);
if (!guest)
goto error;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
goto error;
return 0;
error:
virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines));
return -1;
}
示例5: testQemuAddArmGuest
static int testQemuAddArmGuest(virCapsPtr caps)
{
static const char *machines[] = { "vexpress-a9",
"vexpress-a15",
"versatilepb" };
virCapsGuestMachinePtr *capsmachines = NULL;
virCapsGuestPtr guest;
capsmachines = virCapabilitiesAllocMachines(machines,
ARRAY_CARDINALITY(machines));
if (!capsmachines)
goto error;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_ARMV7L,
QEMUBinList[TEST_UTILS_QEMU_BIN_ARM],
NULL,
ARRAY_CARDINALITY(machines),
capsmachines);
if (!guest)
goto error;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
goto error;
return 0;
error:
virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines));
return -1;
}
示例6: qemuTestCapsCacheInsert
int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache,
virQEMUCapsPtr caps)
{
size_t i;
virQEMUCapsPtr tmpCaps;
if (caps) {
tmpCaps = caps;
} else {
if (!(tmpCaps = virQEMUCapsNew()))
return -ENOMEM;
}
for (i = 0; i < ARRAY_CARDINALITY(QEMUBinList); i++) {
virObjectRef(tmpCaps);
if (virHashUpdateEntry(cache->binaries,
QEMUBinList[i],
tmpCaps) < 0) {
virObjectUnref(tmpCaps);
return -1;
}
}
if (!caps)
virObjectUnref(tmpCaps);
return 0;
}
示例7: gather_capability
static int
gather_capability(LibHalContext *ctx, const char *udi,
const char *cap_name,
virNodeDevCapsDefPtr *caps_p)
{
caps_tbl_entry *entry;
entry = bsearch(&cap_name, caps_tbl, ARRAY_CARDINALITY(caps_tbl),
sizeof(caps_tbl[0]), cmpstringp);
if (entry) {
virNodeDevCapsDefPtr caps;
if (VIR_ALLOC(caps) < 0)
return ENOMEM;
caps->type = entry->type;
if (entry->gather_fn) {
int rv = (*entry->gather_fn)(ctx, udi, &caps->data);
if (rv != 0) {
virNodeDevCapsDefFree(caps);
return rv;
}
}
caps->next = *caps_p;
*caps_p = caps;
}
return 0;
}
示例8: virCapabilitiesAllocMachines
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
virCapsGuestMachinePtr *machines;
static const char *const x86_machines[] = {
"pc", "isapc"
};
machines = virCapabilitiesAllocMachines(x86_machines,
ARRAY_CARDINALITY(x86_machines));
if (machines == NULL)
return NULL;
*nmachines = ARRAY_CARDINALITY(x86_machines);
return machines;
}
示例9: read_bd_stat
static int64_t
read_bd_stat(int device, int domid, const char *str)
{
static const char *paths[] = {
"/sys/bus/xen-backend/devices/vbd-%d-%d/statistics/%s",
"/sys/bus/xen-backend/devices/tap-%d-%d/statistics/%s",
"/sys/devices/xen-backend/vbd-%d-%d/statistics/%s",
"/sys/devices/xen-backend/tap-%d-%d/statistics/%s"
};
int i;
char *path;
int64_t r;
for (i = 0; i < ARRAY_CARDINALITY(paths); ++i) {
if (virAsprintf(&path, paths[i], domid, device, str) < 0) {
virReportOOMError();
return -1;
}
r = read_stat(path);
VIR_FREE(path);
if (r >= 0) {
return r;
}
}
return -1;
}
示例10: mymain
static int
mymain(void)
{
int ret = 0;
int i;
const char *nodeData[] = {
"test1",
# if !(defined(__powerpc__) || \
defined(__powerpc64__))
"test2",
"test3",
"test4",
"test5",
"test6",
# endif
};
if (virInitialize() < 0)
return EXIT_FAILURE;
for (i = 0 ; i < ARRAY_CARDINALITY(nodeData); i++)
if (virtTestRun(nodeData[i], 1, linuxTestNodeInfo, nodeData[i]) != 0)
ret = -1;
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
示例11: lxcContainerPopulateDevices
static int lxcContainerPopulateDevices(void)
{
int i;
const struct {
int maj;
int min;
mode_t mode;
const char *path;
} devs[] = {
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_NULL, 0666, "/dev/null" },
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_ZERO, 0666, "/dev/zero" },
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_FULL, 0666, "/dev/full" },
{ LXC_DEV_MAJ_TTY, LXC_DEV_MIN_CONSOLE, 0600, "/dev/console" },
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_RANDOM, 0666, "/dev/random" },
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_URANDOM, 0666, "/dev/urandom" },
};
/* Populate /dev/ with a few important bits */
for (i = 0 ; i < ARRAY_CARDINALITY(devs) ; i++) {
dev_t dev = makedev(devs[i].maj, devs[i].min);
if (mknod(devs[i].path, S_IFCHR, dev) < 0 ||
chmod(devs[i].path, devs[i].mode)) {
virReportSystemError(errno,
_("Failed to make device %s"),
devs[i].path);
return -1;
}
}
if (access("/dev/pts/ptmx", W_OK) == 0) {
if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) {
virReportSystemError(errno, "%s",
_("Failed to create symlink /dev/ptmx to /dev/pts/ptmx"));
return -1;
}
} else {
dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX);
if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 ||
chmod("/dev/ptmx", 0666)) {
virReportSystemError(errno, "%s",
_("Failed to make device /dev/ptmx"));
return -1;
}
}
/* XXX we should allow multiple consoles per container
* for tty2, tty3, etc, but the domain XML does not
* handle this yet
*/
if (symlink("/dev/pts/0", "/dev/tty1") < 0) {
virReportSystemError(errno, "%s",
_("Failed to symlink /dev/pts/0 to /dev/tty1"));
return -1;
}
return 0;
}
示例12: lxcContainerMountBasicFS
static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
{
const struct {
const char *src;
const char *dst;
const char *type;
} mnts[] = {
{ "/dev", "/dev", "tmpfs" },
{ "/proc", "/proc", "proc" },
{ "/sys", "/sys", "sysfs" },
#if WITH_SELINUX
{ "none", "/selinux", "selinuxfs" },
#endif
};
int i, rc = -1;
char *devpts;
if (virAsprintf(&devpts, "/.oldroot%s/dev/pts", root->src) < 0) {
virReportOOMError();
return rc;
}
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
if (virFileMakePath(mnts[i].dst) != 0) {
virReportSystemError(errno,
_("Failed to mkdir %s"),
mnts[i].src);
goto cleanup;
}
if (mount(mnts[i].src, mnts[i].dst, mnts[i].type, 0, NULL) < 0) {
virReportSystemError(errno,
_("Failed to mount %s on %s"),
mnts[i].type, mnts[i].type);
goto cleanup;
}
}
if ((rc = virFileMakePath("/dev/pts") != 0)) {
virReportSystemError(rc, "%s",
_("Cannot create /dev/pts"));
goto cleanup;
}
VIR_DEBUG("Trying to move %s to %s", devpts, "/dev/pts");
if ((rc = mount(devpts, "/dev/pts", NULL, MS_MOVE, NULL)) < 0) {
virReportSystemError(errno, "%s",
_("Failed to mount /dev/pts in container"));
goto cleanup;
}
rc = 0;
cleanup:
VIR_FREE(devpts);
return rc;
}
示例13: testHashInit
static virHashTablePtr
testHashInit(int size)
{
virHashTablePtr hash;
ssize_t i;
if (!(hash = virHashCreate(size, NULL)))
return NULL;
/* entires are added in reverse order so that they will be linked in
* collision list in the same order as in the uuids array
*/
for (i = ARRAY_CARDINALITY(uuids) - 1; i >= 0; i--) {
ssize_t oldsize = virHashTableSize(hash);
if (virHashAddEntry(hash, uuids[i], (void *) uuids[i]) < 0) {
virHashFree(hash);
return NULL;
}
if (virHashTableSize(hash) != oldsize && virTestGetDebug()) {
VIR_WARN("hash grown from %zd to %zd",
(size_t)oldsize, (size_t)virHashTableSize(hash));
}
}
for (i = 0; i < ARRAY_CARDINALITY(uuids); i++) {
if (!virHashLookup(hash, uuids[i])) {
if (virTestGetVerbose()) {
VIR_WARN("\nentry \"%s\" could not be found\n",
uuids[i]);
}
virHashFree(hash);
return NULL;
}
}
if (size && size != virHashTableSize(hash) && virTestGetDebug())
fprintf(stderr, "\n");
return hash;
}
示例14: VBoxCGlueInit
/**
* Tries to locate and load VBoxXPCOMC.so/dylib/dll, resolving all the related
* function pointers.
*
* @returns 0 on success, -1 on failure.
*/
int
VBoxCGlueInit(unsigned int *version)
{
int i;
static const char *knownDirs[] = {
"/usr/lib/virtualbox",
"/usr/lib/virtualbox-ose",
"/usr/lib64/virtualbox",
"/usr/lib64/virtualbox-ose",
"/usr/lib/VirtualBox",
"/opt/virtualbox",
"/opt/VirtualBox",
"/opt/virtualbox/i386",
"/opt/VirtualBox/i386",
"/opt/virtualbox/amd64",
"/opt/VirtualBox/amd64",
"/usr/local/lib/virtualbox",
"/usr/local/lib/VirtualBox",
"/Applications/VirtualBox.app/Contents/MacOS"
};
const char *home = getenv("VBOX_APP_HOME");
/* If the user specifies the location, try only that. */
if (home != NULL) {
if (tryLoadOne(home, false, false, version) < 0) {
return -1;
}
}
/* Try the additionally configured location. */
if (VBOX_XPCOMC_DIR[0] != '\0') {
if (tryLoadOne(VBOX_XPCOMC_DIR, true, true, version) >= 0) {
return 0;
}
}
/* Try the known locations. */
for (i = 0; i < ARRAY_CARDINALITY(knownDirs); ++i) {
if (tryLoadOne(knownDirs[i], true, true, version) >= 0) {
return 0;
}
}
/* Finally try the dynamic linker search path. */
if (tryLoadOne(NULL, false, true, version) >= 0) {
return 0;
}
/* No luck, return failure. */
return -1;
}
示例15: testRemoveCommonRules
static void testRemoveCommonRules(char *rules)
{
size_t i;
char *offset = rules;
for (i = 0; i < ARRAY_CARDINALITY(commonRules); i++) {
char *tmp = strstr(offset, commonRules[i]);
size_t len = strlen(commonRules[i]);
if (tmp) {
memmove(tmp, tmp + len, (strlen(tmp) + 1) - len);
offset = tmp;
}
}
}