Commit 9e8fd0c2 authored by ballen4705's avatar ballen4705
Browse files

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
parent bd544df8
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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;
}
......@@ -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;
}
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment