United States-English |
|
|
HP-UX Reference > Ccmpt_getbynum(3)HP-UX 11i Version 3: February 2007 |
|
NAMEcmpt_getbynum(), cmpt_endent(), cmpt_getbyname(), cmpt_getent(), cmpt_setent() — map compartment name to number or number to name SYNOPSIS#include <sys/cmpt.h> void cmpt_endent(struct cmpt_state **state); cmpt_t cmpt_getbyname(const char *cmpt_name); char *cmpt_getbynum(cmpt_t cmpt_num); int cmpt_setent(struct cmpt_state **state); const struct cmpt_pair *cmpt_getent(struct cmpt_state **state); DESCRIPTIONCompartments are referenced by strings in configuration files under /etc/cmpt, but are maintained as numbers internally. The functions cmpt_getbyname(), cmpt_getbynum(), cmpt_setent(), cmpt_getent(), and cmpt_setent() query and iterate over this database.
RETURN VALUEcmpt_getbyname() returns the following values:
cmpt_getbynum() returns the following values:
The caller is responsible for freeing the result. cmpt_setent() returns the following values:
cmpt_getent() returns the following values:
cmpt_getent() sets errno to 0 and returns a null pointer when all entries have been exhausted. ERRORSIf any of the following conditions occur, the functions fail and set errno.
EXAMPLESExample 1Get 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 2Get 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 3Iterate 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) { perror("cmpt_setent failed"); exit(1); } /* get entries until a NULL returned */ while ( pair = cmpt_getent(&state) ) { printf("\nCompartment Nnumber : %d Name : %s\n", pair->cmpt_num, pair->cmpt_name); } if (errno == 0) { printf("\nAll Entries printed\n"); } else { printf("\nError getting compartment entry\n"); } cmpt_endent(); } |
Printable version | ||
|