diff options
-rw-r--r-- | hardware.c | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -12,11 +12,11 @@ ** Removes a trailing newline character if present */ static void removeNewLine(char * s) { - int len = strlen(s); - - if(len > 0 && s[len - 1] == '\n') { - s[len - 1] = '\0'; - } + int len = strlen(s); + + if(len > 0 && s[len - 1] == '\n') { + s[len - 1] = '\0'; + } } /*************** @@ -26,21 +26,21 @@ static void removeNewLine(char * s) { ** The pointer result must point to a pre-allocated array of at least BUF_SIZ */ static void runCommand (const char *command, char *result) { - FILE * pipe; - - pipe = popen(command, "r"); - if(pipe == NULL) { - /* command failed */ - result[0] = '\0'; - } else { - if(NULL == fgets(result, BUF_SIZ, pipe)) { - /* command failed */ - result[0] = '\0'; - } - pclose(pipe); - } + FILE * pipe; - removeNewLine(result); + pipe = popen(command, "r"); + if(pipe == NULL) { + /* command failed */ + result[0] = '\0'; + } else { + if(NULL == fgets(result, BUF_SIZ, pipe)) { + /* command failed */ + result[0] = '\0'; + } + pclose(pipe); + } + + removeNewLine(result); } /******************** @@ -82,22 +82,22 @@ static void readProcCpuInfo (char *model, char *cache) { */ void hardware(void) { - char os[BUF_SIZ]; - char model[BUF_SIZ]; - char cache[BUF_SIZ]; - const char os_command[] = "uname -s -r"; + char os[BUF_SIZ]; + char model[BUF_SIZ]; + char cache[BUF_SIZ]; + const char os_command[] = "uname -s -r"; #ifdef NO_UNAME - os[0] = '\0'; + os[0] = '\0'; #else - runCommand(os_command, os); + runCommand(os_command, os); #endif - if(NULL != strstr(os, "Linux")) { - readProcCpuInfo (model, cache); - } else { - model[0] = '\0'; - cache[0] = '\0'; - } - printf("CPU : %s\n", model); - printf("L2 Cache : %s\n", cache); - printf("OS : %s\n", os); + if(NULL != strstr(os, "Linux")) { + readProcCpuInfo (model, cache); + } else { + model[0] = '\0'; + cache[0] = '\0'; + } + printf("CPU : %s\n", model); + printf("L2 Cache : %s\n", cache); + printf("OS : %s\n", os); } |