summaryrefslogtreecommitdiff
path: root/hardware.c
diff options
context:
space:
mode:
Diffstat (limited to 'hardware.c')
-rw-r--r--hardware.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/hardware.c b/hardware.c
index 46ecfc8..390b8ec 100644
--- a/hardware.c
+++ b/hardware.c
@@ -12,12 +12,13 @@
** Removes a trailing newline character if present
*/
static void removeNewLine(char * s) {
- if(strlen(s)>0 && s[strlen(s)-1] == '\n') {
- s[strlen(s)-1] = '\0';
- }
+ int len = strlen(s);
+
+ if(len > 0 && s[len - 1] == '\n') {
+ s[len - 1] = '\0';
+ }
}
-
/***************
** runCommand **
****************
@@ -25,23 +26,23 @@ 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;
+ 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);
+ }
- 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);
+ removeNewLine(result);
}
-
/********************
** readProcCpuInfo **
*********************
@@ -58,13 +59,13 @@ static void readProcCpuInfo (char *model, char *cache) {
switch (info->cpus) {
case 1:
- strncpy(format, "%s %s %.0fMHz", 32);
+ strcpy(format, "%s %s %.0fMHz");
break;
case 2:
- strncpy(format, "Dual %s %s %.0fMHz", 32);
+ strcpy(format, "Dual %s %s %.0fMHz");
break;
default:
- strncpy(format, "%d CPUs %s %s %.0fMHz", 32);
+ strcpy(format, "%d CPUs %s %s %.0fMHz");
break;
}
snprintf(model, BUF_SIZ, format, info->hardware_platform, info->architecture, info->frequency);
@@ -72,7 +73,6 @@ static void readProcCpuInfo (char *model, char *cache) {
proccpuinfo_free(info);
}
-
/*************
** hardware **
**************
@@ -82,10 +82,10 @@ static void readProcCpuInfo (char *model, char *cache) {
*/
void hardware(void) {
- 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';
#else