33 #include <sys/utsname.h> 38 #include <boost/algorithm/string.hpp> 39 #include <boost/format.hpp> 40 #include <boost/function.hpp> 48 boost::function1<std::string, const utsname&> thunk) {
50 if (uname(&info) == -1) {
51 throw std::runtime_error(boost::str(boost::format(
"Could not determine %1% because" 52 " uname(2) failed: %2%")
53 % context % strerror(errno)));
60 if (std::string(info.machine) ==
"i686") {
74 std::string result(info.sysname);
75 boost::algorithm::to_lower(result);
100 if (gethostname(buffer, HOSTNAME_MAX_LENGTH) == 0) {
101 std::string maybeQualifiedHostname(buffer);
102 std::vector<std::string> components;
103 boost::algorithm::split(components, maybeQualifiedHostname,
104 boost::algorithm::is_any_of(
"."));
105 assert(!components.empty());
106 return components[0];
108 throw std::runtime_error(boost::str(boost::format(
"gethostname failed: %1%")
std::string operator()(const utsname &info) const
std::string callWithUtsname(const std::string &context, boost::function1< std::string, const utsname & > thunk)
std::string operator()(const utsname &info) const
std::string operator()(const utsname &info) const
RSC_EXPORT std::string currentHostname()
Determine and return the hostname of the local machine.
RSC_EXPORT std::string currentSoftwareVersion()
Determine and return the version of the operating system within its type, usually the kernel version ...
RSC_EXPORT std::string currentSoftwareType()
Determine and return the type of the operating system, usually the kernel name, running on the local ...
const unsigned int HOSTNAME_MAX_LENGTH
RSC_EXPORT std::string currentMachineType()
Determine and return the machine type, usually CPU architecture, of the local machine.