Skip to content

Commit

Permalink
Amend #3043 by allowing a longer hostname and simplifying the code. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
susilehtola committed Sep 3, 2023
1 parent 81f0da6 commit 97f4680
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions psi4/src/psi4/libciomr/tstart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void PSI_API tstart() {
const long clk_tck = sysconf(_SC_CLK_TCK);
times(&total_tmstime);

// host name has up to HOST_NAME_MAX(==64) + 1 bytes, and must end in the null byte
std::vector<char> name(65);
error = gethostname(name.data(), 65);
if (error != 0) strncpy(name.data(), "nohostname", 11);
// host name has up to HOST_NAME_MAX (64 or 256) + 1 bytes, and must end in the null byte
std::vector<char> name(257);
error = gethostname(name.data(), name.size());
if (error) strncpy(name.data(), "nohostname", name.size());
if (name.back() != '\0') name.push_back('\0');

/// start a global timer
Expand Down Expand Up @@ -105,10 +105,10 @@ void PSI_API tstop() {
struct tms total_tmstime;
double user_s, sys_s;

// host name has up to HOST_NAME_MAX(==64) + 1 bytes, and must end in the null byte
std::vector<char> name(65);
error = gethostname(name.data(), 65);
if (error != 0) strncpy(name.data(), "nohostname", 11);
// host name has up to HOST_NAME_MAX (64 or 256) + 1 bytes, and must end in the null byte
std::vector<char> name(257);
error = gethostname(name.data(), name.size());
if (error) strncpy(name.data(), "nohostname", name.size());
if (name.back() != '\0') name.push_back('\0');

time_end = std::time(nullptr);
Expand Down
8 changes: 4 additions & 4 deletions psi4/src/psi4/libqt/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,10 @@ void timer_done() {
extern Timer_Structure root_timer;
root_timer.turn_off();

// host name has up to HOST_NAME_MAX(==64) + 1 bytes, and must end in the null byte
std::vector<char> host(65);
int error = gethostname(host.data(), 65);
if (error != 0) strncpy(host.data(), "nohostname", 11);
// host name has up to HOST_NAME_MAX (64 or 256) + 1 bytes, and must end in the null byte
std::vector<char> host(257);
int error = gethostname(host.data(), host.size());
if (error) strncpy(host.data(), "nohostname", host.size());
if (host.back() != '\0') host.push_back('\0');

/* Dump the timing data to timer.dat and free the timers */
Expand Down

0 comments on commit 97f4680

Please sign in to comment.