From 9e8fd0c2103becfb176e69cfc5b7ed1084a1a4f9 Mon Sep 17 00:00:00 2001 From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137> Date: Fri, 17 Jan 2003 12:20:24 +0000 Subject: [PATCH] Code Janitor work. Moving general-purpose code into utility.[hc]. git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@452 4ea69e1a-61f1-4043-bf83-b5c94c648137 --- sm5/Makefile | 4 ++-- sm5/atacmds.c | 20 ++------------------ sm5/atacmds.cpp | 20 ++------------------ sm5/atacmds.h | 11 +---------- sm5/utility.c | 23 +++++++++++++++++++++-- sm5/utility.cpp | 23 +++++++++++++++++++++-- sm5/utility.h | 14 +++++++++++++- 7 files changed, 62 insertions(+), 53 deletions(-) diff --git a/sm5/Makefile b/sm5/Makefile index 6fe07357c..f71753df7 100644 --- a/sm5/Makefile +++ b/sm5/Makefile @@ -2,7 +2,7 @@ # # Home page: http://smartmontools.sourceforge.net # -# $Id: Makefile,v 1.47 2003/01/16 15:51:09 ballen4705 Exp $ +# $Id: Makefile,v 1.48 2003/01/17 12:20:24 ballen4705 Exp $ # # Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net> # @@ -62,7 +62,7 @@ smartd: smartd.c atacmds.o ataprint.o scsicmds.o utility.o\ $(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartd $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) smartd.c \ atacmds.o ataprint.o scsicmds.o utility.o -atacmds.o: atacmds.h atacmds.c Makefile +atacmds.o: atacmds.c atacmds.h utility.h Makefile $(CC) $(CFLAGS) $(CPPFLAGS) -c atacmds.c ataprint.o: ataprint.c atacmds.h ataprint.h smartctl.h extern.h utility.h Makefile diff --git a/sm5/atacmds.c b/sm5/atacmds.c index b16e49dc6..d98b86ebd 100644 --- a/sm5/atacmds.c +++ b/sm5/atacmds.c @@ -28,8 +28,9 @@ #include <errno.h> #include <stdlib.h> #include "atacmds.h" +#include "utility.h" -const char *atacmds_c_cvsid="$Id: atacmds.c,v 1.52 2003/01/16 15:51:09 ballen4705 Exp $" ATACMDS_H_CVSID; +const char *atacmds_c_cvsid="$Id: atacmds.c,v 1.53 2003/01/17 12:20:24 ballen4705 Exp $" ATACMDS_H_CVSID UTILITY_H_CVSID; // These Drive Identity tables are taken from hdparm 5.2, and are also // given in the ATA/ATAPI specs for the IDENTIFY DEVICE command. Note @@ -194,23 +195,6 @@ char *create_vendor_attribute_arg_list(void){ return s; } -// A replacement for perror() that sends output to our choice of -// printing. -void syserror(const char *message){ - const char *errormessage; - - // Get the correct system error message: - errormessage=strerror(errno); - - // Check that caller has handed a sensible string, and provide - // appropriate output. See perrror(3) man page to understand better. - if (message && *message) - pout("%s: %s\n",message, errormessage); - else - pout("%s\n",errormessage); - - return; -} // We no longer use this function, because the IOCTL appears to return // only the drive identity at the time that the system was booted diff --git a/sm5/atacmds.cpp b/sm5/atacmds.cpp index 282dff7d8..10a4e0b42 100644 --- a/sm5/atacmds.cpp +++ b/sm5/atacmds.cpp @@ -28,8 +28,9 @@ #include <errno.h> #include <stdlib.h> #include "atacmds.h" +#include "utility.h" -const char *atacmds_c_cvsid="$Id: atacmds.cpp,v 1.52 2003/01/16 15:51:09 ballen4705 Exp $" ATACMDS_H_CVSID; +const char *atacmds_c_cvsid="$Id: atacmds.cpp,v 1.53 2003/01/17 12:20:24 ballen4705 Exp $" ATACMDS_H_CVSID UTILITY_H_CVSID; // These Drive Identity tables are taken from hdparm 5.2, and are also // given in the ATA/ATAPI specs for the IDENTIFY DEVICE command. Note @@ -194,23 +195,6 @@ char *create_vendor_attribute_arg_list(void){ return s; } -// A replacement for perror() that sends output to our choice of -// printing. -void syserror(const char *message){ - const char *errormessage; - - // Get the correct system error message: - errormessage=strerror(errno); - - // Check that caller has handed a sensible string, and provide - // appropriate output. See perrror(3) man page to understand better. - if (message && *message) - pout("%s: %s\n",message, errormessage); - else - pout("%s\n",errormessage); - - return; -} // We no longer use this function, because the IOCTL appears to return // only the drive identity at the time that the system was booted diff --git a/sm5/atacmds.h b/sm5/atacmds.h index 541279547..1e4e8eed4 100644 --- a/sm5/atacmds.h +++ b/sm5/atacmds.h @@ -26,7 +26,7 @@ #define _ATACMDS_H_ #ifndef ATACMDS_H_CVSID -#define ATACMDS_H_CVSID "$Id: atacmds.h,v 1.32 2003/01/16 15:51:09 ballen4705 Exp $\n" +#define ATACMDS_H_CVSID "$Id: atacmds.h,v 1.33 2003/01/17 12:20:24 ballen4705 Exp $\n" #endif // These are the major and minor versions for smartd and smartctl @@ -345,14 +345,6 @@ int TestTime(struct ata_smart_values *data,int testtype); // 30 byte string with attribute name into output void ataPrintSmartAttribName(char *output, unsigned char id, unsigned char *defs); -// like printf() except that we can control it better.... -void pout(char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); - -// replacement for perror() with redirected output. -void syserror(const char *message); - - // This checks the n'th attribute in the attribute list, NOT the // attribute with id==n. If the attribute does not exist, or the // attribute is > threshold, then returns zero. If the attribute is @@ -363,7 +355,6 @@ int ataCheckAttribute(struct ata_smart_values *data, struct ata_smart_thresholds *thresholds, int n); - // External handler function, for when a checksum is not correct. Can // simply return if no action is desired, or can print error messages // as needed, or exit. Is passed a string with the name of the Data diff --git a/sm5/utility.c b/sm5/utility.c index 22016c101..75158b084 100644 --- a/sm5/utility.c +++ b/sm5/utility.c @@ -30,11 +30,12 @@ #include <unistd.h> #include <string.h> #include <time.h> +#include <errno.h> +#include <stdlib.h> #include "utility.h" -#include "stdlib.h" // Any local header files should be represented by a CVSIDX just below. -const char* utility_c_cvsid="$Id: utility.c,v 1.2 2003/01/16 15:51:10 ballen4705 Exp $" UTILITY_H_CVSID; +const char* utility_c_cvsid="$Id: utility.c,v 1.3 2003/01/17 12:20:24 ballen4705 Exp $" UTILITY_H_CVSID; // Utility function prints date and time and timezone into a character // buffer of length>=64. All the fuss is needed to get the right @@ -130,3 +131,21 @@ void printone(char *block, const char *cvsid){ return; } + +// A replacement for perror() that sends output to our choice of +// printing. +void syserror(const char *message){ + const char *errormessage; + + // Get the correct system error message: + errormessage=strerror(errno); + + // Check that caller has handed a sensible string, and provide + // appropriate output. See perrror(3) man page to understand better. + if (message && *message) + pout("%s: %s\n",message, errormessage); + else + pout("%s\n",errormessage); + + return; +} diff --git a/sm5/utility.cpp b/sm5/utility.cpp index 0bab41622..edcc2811b 100644 --- a/sm5/utility.cpp +++ b/sm5/utility.cpp @@ -30,11 +30,12 @@ #include <unistd.h> #include <string.h> #include <time.h> +#include <errno.h> +#include <stdlib.h> #include "utility.h" -#include "stdlib.h" // Any local header files should be represented by a CVSIDX just below. -const char* utility_c_cvsid="$Id: utility.cpp,v 1.2 2003/01/16 15:51:10 ballen4705 Exp $" UTILITY_H_CVSID; +const char* utility_c_cvsid="$Id: utility.cpp,v 1.3 2003/01/17 12:20:24 ballen4705 Exp $" UTILITY_H_CVSID; // Utility function prints date and time and timezone into a character // buffer of length>=64. All the fuss is needed to get the right @@ -130,3 +131,21 @@ void printone(char *block, const char *cvsid){ return; } + +// A replacement for perror() that sends output to our choice of +// printing. +void syserror(const char *message){ + const char *errormessage; + + // Get the correct system error message: + errormessage=strerror(errno); + + // Check that caller has handed a sensible string, and provide + // appropriate output. See perrror(3) man page to understand better. + if (message && *message) + pout("%s: %s\n",message, errormessage); + else + pout("%s\n",errormessage); + + return; +} diff --git a/sm5/utility.h b/sm5/utility.h index da875041c..7f8e2cbec 100644 --- a/sm5/utility.h +++ b/sm5/utility.h @@ -26,7 +26,7 @@ #define __UTILITY_H_ #ifndef UTILITY_H_CVSID -#define UTILITY_H_CVSID "$Id: utility.h,v 1.2 2003/01/16 15:51:10 ballen4705 Exp $\n" +#define UTILITY_H_CVSID "$Id: utility.h,v 1.3 2003/01/17 12:20:24 ballen4705 Exp $\n" #endif // Utility function prints date and time and timezone into a character @@ -38,4 +38,16 @@ void dateandtimezone(char *buffer); #define CVSMAXLEN 512 void printone(char *block, const char *cvsid); +// like printf() except that we can control it better. Note -- +// although the prototype is given here, in utility.h, the function +// itself is defined differently in smartctl and smartd. So the +// function definition is in smartd.c and in smartctl.c. +void pout(char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); + +// replacement for perror() with redirected output. +void syserror(const char *message); + + + #endif -- GitLab