The x::passwd
and
x::group
classes provide an interface to the password and the group file,
analogous to the getpw
and getgr
functions:
#include <x/pwd.H> #include <x/grp.H> x::passwd pw(getuid()); x::group gr(getgid()); std::cout << (pw->pw_name ? pw->pw_name:"unknown") << ":" << (gr->gr_name ? gr->gr_name:"unknown") << std::endl;
These classes use the thread safe “_r” variants of the
getpw
and getgr
functions,
and take care of allocating a sufficient buffer for the internal
character strings.
The x::servent
class is an analogous interface to the services/port list:
#include <x/servent.H> x::servent service("https", "tcp"); if (service->s_name) std::cout << "port " << ntohs(service->port) << std::endl;