Add support for getting the hostname
authorNathan Binkert <binkertn@umich.edu>
Mon, 15 Dec 2003 23:24:02 +0000 (18:24 -0500)
committerNathan Binkert <binkertn@umich.edu>
Mon, 15 Dec 2003 23:24:02 +0000 (18:24 -0500)
--HG--
extra : convert_revision : 498a950e574059eac2e3b1969880ecc04cf53f31

base/hostinfo.cc
base/hostinfo.hh

index 5efb7735623121daa5899c34ee4e545e6cd4b33a..cb5c04efcf473105bf7eee164962a39a4717f8eb 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <ctype.h>
 #include <errno.h>
 #include <math.h>
+#include <unistd.h>
 
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <string>
+
+#include "base/misc.hh"
 #include "sim/host.hh"
 
+using namespace std;
+
+string
+__get_hostname()
+{
+    char host[256];
+    if (gethostname(host, sizeof host) == -1)
+        warn("could not get host name!");
+    return host;
+}
+
+string &
+hostname()
+{
+    static string hostname = __get_hostname();
+    return hostname;
+}
+
 uint64_t
 procInfo(char *filename, char *target)
 {
index 2293d2b6a7fbfcb4a96fff0c5cd7d9e6ae5f4dc6..453a1e69a87319250aaf8ea21897f7a3dffd00ec 100644 (file)
 #ifndef __HOSTINFO_HH__
 #define __HOSTINFO_HH__
 
+#include <string>
+
 #include "sim/host.hh"
 
+std::string &hostname();
+
 uint64_t procInfo(char *filename, char *target);
 
 inline uint64_t memUsage()