From b7f2be7ee0f122e912bd52878e1a001075616090 Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Sun, 15 Dec 2002 16:54:29 +0000
Subject: [PATCH] Replaced ackward constructions with simpler ones by using
 strerror()

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@374 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/smartd.c   | 27 ++++++---------------------
 sm5/smartd.cpp | 27 ++++++---------------------
 2 files changed, 12 insertions(+), 42 deletions(-)

diff --git a/sm5/smartd.c b/sm5/smartd.c
index 17a1fabaa..bab69402b 100644
--- a/sm5/smartd.c
+++ b/sm5/smartd.c
@@ -50,7 +50,7 @@
 
 // CVS ID strings
 extern const char *CVSid1, *CVSid2;
-const char *CVSid6="$Id: smartd.c,v 1.85 2002/12/08 12:56:52 pjwilliams Exp $" 
+const char *CVSid6="$Id: smartd.c,v 1.86 2002/12/15 16:54:29 ballen4705 Exp $" 
 CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
 
 // global variable used for control of printing, passing arguments, etc.
@@ -359,10 +359,7 @@ void Usage (void){
 int opendevice(char *device){
   int fd = open(device, O_RDONLY);
   if (fd<0) {
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"Device: %s, %s, open() failed\n",device, sys_errlist[errno]);
-    else
-      printout(LOG_INFO,"Device: %s, open() failed\n",device);
+    printout(LOG_INFO,"Device: %s, %s, open() failed\n",device, strerror(errno));
     return -1;
   }
   // device opened sucessfully
@@ -371,10 +368,7 @@ int opendevice(char *device){
 
 int closedevice(int fd, char *name){
   if (close(fd)){
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"Device: %s, %s, close(%d) failed\n", name, sys_errlist[errno], fd);
-    else
-      printout(LOG_INFO,"Device: %s, close(%d) failed\n",name, fd);
+    printout(LOG_INFO,"Device: %s, %s, close(%d) failed\n", name, strerror(errno), fd);
     return 1;
   }
   // device sucessfully closed
@@ -1102,10 +1096,7 @@ int parseconfigline(int entry, int lineno,char *line){
   static int numtokens=0;
 
   if (!(copy=strdup(line))){
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"No memory to parse file: %s line %d, %s\n", CONFIGFILE, lineno, sys_errlist[errno]);
-    else
-      printout(LOG_INFO,"No memory to parse file: %s line %d\n", CONFIGFILE, lineno);
+    printout(LOG_INFO,"No memory to parse file: %s line %d, %s\n", CONFIGFILE, lineno, strerror(errno));
     exit(1);
   }
   
@@ -1146,10 +1137,7 @@ int parseconfigline(int entry, int lineno,char *line){
   cfg->trackatt=(unsigned char *)calloc(32,1);
   
   if (!cfg->name || !cfg->failatt || !cfg->trackatt) {
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"No memory to store file: %s line %d, %s\n", CONFIGFILE, lineno, sys_errlist[errno]);
-    else
-      printout(LOG_INFO,"No memory to store file: %s line %d\n", CONFIGFILE, lineno);
+    printout(LOG_INFO,"No memory to store file: %s line %d, %s\n", CONFIGFILE, lineno, strerror(errno));
     exit(1);
   }
 
@@ -1421,10 +1409,7 @@ int makeconfigentries(int num, char *name, int isata, int start){
     cfg->failatt=(unsigned char *)calloc(32,1);
     cfg->trackatt=(unsigned char *)calloc(32,1);
     if (!cfg->name || !cfg->failatt || !cfg->trackatt) {
-      if (errno<sys_nerr)
-	printout(LOG_INFO,"No memory for %d'th device after %s, %s\n", i, name, sys_errlist[errno]);
-      else
-	printout(LOG_INFO,"No memory for %d'th device after %s\n", i, name);
+	printout(LOG_INFO,"No memory for %d'th device after %s, %s\n", i, name, strerror(errno));
       exit(1);
     }
 
diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp
index c717b6c91..ab392c9c0 100644
--- a/sm5/smartd.cpp
+++ b/sm5/smartd.cpp
@@ -50,7 +50,7 @@
 
 // CVS ID strings
 extern const char *CVSid1, *CVSid2;
-const char *CVSid6="$Id: smartd.cpp,v 1.85 2002/12/08 12:56:52 pjwilliams Exp $" 
+const char *CVSid6="$Id: smartd.cpp,v 1.86 2002/12/15 16:54:29 ballen4705 Exp $" 
 CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
 
 // global variable used for control of printing, passing arguments, etc.
@@ -359,10 +359,7 @@ void Usage (void){
 int opendevice(char *device){
   int fd = open(device, O_RDONLY);
   if (fd<0) {
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"Device: %s, %s, open() failed\n",device, sys_errlist[errno]);
-    else
-      printout(LOG_INFO,"Device: %s, open() failed\n",device);
+    printout(LOG_INFO,"Device: %s, %s, open() failed\n",device, strerror(errno));
     return -1;
   }
   // device opened sucessfully
@@ -371,10 +368,7 @@ int opendevice(char *device){
 
 int closedevice(int fd, char *name){
   if (close(fd)){
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"Device: %s, %s, close(%d) failed\n", name, sys_errlist[errno], fd);
-    else
-      printout(LOG_INFO,"Device: %s, close(%d) failed\n",name, fd);
+    printout(LOG_INFO,"Device: %s, %s, close(%d) failed\n", name, strerror(errno), fd);
     return 1;
   }
   // device sucessfully closed
@@ -1102,10 +1096,7 @@ int parseconfigline(int entry, int lineno,char *line){
   static int numtokens=0;
 
   if (!(copy=strdup(line))){
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"No memory to parse file: %s line %d, %s\n", CONFIGFILE, lineno, sys_errlist[errno]);
-    else
-      printout(LOG_INFO,"No memory to parse file: %s line %d\n", CONFIGFILE, lineno);
+    printout(LOG_INFO,"No memory to parse file: %s line %d, %s\n", CONFIGFILE, lineno, strerror(errno));
     exit(1);
   }
   
@@ -1146,10 +1137,7 @@ int parseconfigline(int entry, int lineno,char *line){
   cfg->trackatt=(unsigned char *)calloc(32,1);
   
   if (!cfg->name || !cfg->failatt || !cfg->trackatt) {
-    if (errno<sys_nerr)
-      printout(LOG_INFO,"No memory to store file: %s line %d, %s\n", CONFIGFILE, lineno, sys_errlist[errno]);
-    else
-      printout(LOG_INFO,"No memory to store file: %s line %d\n", CONFIGFILE, lineno);
+    printout(LOG_INFO,"No memory to store file: %s line %d, %s\n", CONFIGFILE, lineno, strerror(errno));
     exit(1);
   }
 
@@ -1421,10 +1409,7 @@ int makeconfigentries(int num, char *name, int isata, int start){
     cfg->failatt=(unsigned char *)calloc(32,1);
     cfg->trackatt=(unsigned char *)calloc(32,1);
     if (!cfg->name || !cfg->failatt || !cfg->trackatt) {
-      if (errno<sys_nerr)
-	printout(LOG_INFO,"No memory for %d'th device after %s, %s\n", i, name, sys_errlist[errno]);
-      else
-	printout(LOG_INFO,"No memory for %d'th device after %s\n", i, name);
+	printout(LOG_INFO,"No memory for %d'th device after %s, %s\n", i, name, strerror(errno));
       exit(1);
     }
 
-- 
GitLab