cmpt_getbynum.3 (2010 09)
c
cmpt_getbynum(3) cmpt_getbynum(3)
0 Successful completion.
-1 Function failed.
errno is set to indicate the error.
cmpt_getent()
returns the following values:
pointer
Succesaful completions. Returns a non-null pointer to a
cmpt_pair structure.
NULL pointer
Function failed or entries are exhausted. In case of an error,
errno is set to indicate the
error.
cmpt_getent()
sets errno to 0 and returns a null pointer when all entries have been exhausted.
ERRORS
If any of the following conditions occur, the functions fail and set
errno.
[ENOENT] Compartment name or number does not exist.
[ENOSYS] Compartmentalization is not enabled on this system.
[ENOMEM] The function failed to allocate sufficient memory for its operation.
EXAMPLES
Example 1
Get the compartment number associated with a name.
#include <sys/cmpt.h>
void main(int argc, char **argv) {
cmpt_t cmptid;
cmptid = cmpt_getbyname("INIT");
if (cmptid != -1) {
printf("\nCompartment id : %d\n", cmptid);
} else {
printf("\nError getting compartment number\n");
}
}
Example 2
Get the compartment name associated with a number.
#include <sys/cmpt.h>
void main(int argc, char **argv) {
char *name;
name = cmpt_getbynum((cmpt_t)2);
if (name) {
printf("\nCompartment name : %s\n", name);
free(name);
} else {
printf("\nError getting compartment name\n");
}
}
Example 3
Iterate through compartment mapping entries.
#include <errno.h>
#include <sys/cmpt.h>
void main(int argc, char **argv) {
struct cmpt_pair *pair;
struct cmpt_state *state
if (cmpt_setent(&state) != 0) {
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: September 2010