summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-18 00:00:57 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-18 00:00:57 +0000
commit2adbcbb2ff1c89ab345eeb2177f15f9b355766f8 (patch)
tree84f3bfe23a8486d10aed7238645b6bf49e6e5bd8
parent9cdf45006ed170a6bc9ba946cbe4baedf3732832 (diff)
Minor cleanups in hardware.c
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@80 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-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