vocabtree  0.0.1
misc.cxx
Go to the documentation of this file.
1 #include "misc.hpp"
2 #include <cstring>
3 #ifdef WIN32
4  #include <Windows.h>
5  #include <tchar.h>
6 #else
7  #include <unistd.h>
8 #endif
9 
10 namespace misc {
11  std::string get_machine_name() {
12  const int max_len = 150;
13  char name[max_len];
14  memset(name, 0, max_len);
15 
16 #ifdef WIN32
17  TCHAR infoBuf[max_len];
18  DWORD bufCharCount = max_len;
19 
20  if(GetComputerName(infoBuf, &bufCharCount)) {
21  for(int i=0; i<max_len; i++) {
22  name[i] = infoBuf[i];
23  }
24  }
25  else {
26  strcpy(name, "Unknown_Host_Name");
27  }
28 #else
29  gethostname(name, max_len);
30 #endif
31  std::string machine_name = name;
32  return machine_name;
33  }
34 }