我有古蒂尔的 sysinfo.cc 文件,与这个文件相同: https ://github.com/cloudera/kudu/blob/master/src/kudu/gutil/sysinfo.cc#L248 我想知道 InitializeSystemInfo()鉴于我对 C++ 不太熟悉,该函数适用于 Linux。
我在第 248 行找不到这个 do 语句的右括号,那么它还能正确计算 numcpus 吗?
do { // we'll exit when the last read didn't read anything
// Move the next line to the beginning of the buffer
const int oldlinelen = strlen(line);
if (sizeof(line) == oldlinelen + 1) // oldlinelen took up entire line
line[0] = '\0';
else // still other lines left to save
memmove(line, line + oldlinelen+1, sizeof(line) - (oldlinelen+1));
// Terminate the new line, reading more if we can't find the newline
char* newline = strchr(line, '\n');
if (newline == NULL) {
const int linelen = strlen(line);
const int bytes_to_read = sizeof(line)-1 - linelen;
CHECK_GT(bytes_to_read, 0); // because the memmove recovered >=1 bytes
chars_read = read(fd, line + linelen, bytes_to_read);
line[linelen + chars_read] = '\0';
newline = strchr(line, '\n');
}
if (newline != NULL)
*newline = '\0';