diff options
author | khali <khali> | 2003-06-17 12:30:32 +0000 |
---|---|---|
committer | khali <khali> | 2003-06-17 12:30:32 +0000 |
commit | 9e112cb196759b42531cc836676bfcbd69dddcbc (patch) | |
tree | f9cff72f7b06fab74c12ed1a012e73a6ee5ede04 | |
parent | 7a887511ae58c24ed57d65a82a0fa6999f0aad27 (diff) | |
download | dmidecode-9e112cb196759b42531cc836676bfcbd69dddcbc.tar.gz |
Moved common "util" functions to util.c.
-rw-r--r-- | CHANGELOG | 7 | ||||
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | biosdecode.c | 59 | ||||
-rw-r--r-- | dmidecode.c | 59 | ||||
-rw-r--r-- | types.h | 7 |
5 files changed, 36 insertions, 115 deletions
@@ -1,3 +1,10 @@ +2003-06-17 Jean Delvare <khali@linux-fr.org> + + * dmidecode.c, biosdecode.c: Moved common "util" functions to util.c. + * util.c, util.h: New. + * types.h: New. + * Makefile: Updated accordingly. + 2003-06-10 Jean Delvare <khali@linux-fr.org> * dmidecode.c: Fixed typo in IPMI register spacing table. @@ -19,11 +19,20 @@ PREFIX = /usr/local all : dmidecode biosdecode -dmidecode : dmidecode.c version.h - $(CC) $(CFLAGS) $< -o $@ +dmidecode : dmidecode.o util.o + $(CC) $^ -o $@ -biosdecode : biosdecode.c version.h - $(CC) $(CFLAGS) $< -o $@ +biosdecode : biosdecode.o util.o + $(CC) $^ -o $@ + +dmidecode.o : dmidecode.c version.h types.h util.h + $(CC) $(CFLAGS) -c $< -o $@ + +biosdecode.o : biosdecode.c version.h types.h util.h + $(CC) $(CFLAGS) -c $< -o $@ + +util.o : util.c types.h util.h + $(CC) $(CFLAGS) -c $< -o $@ install : dmidecode biosdecode install -m 755 dmidecode $(PREFIX)/sbin @@ -34,4 +43,4 @@ uninstall : rm -f $(PREFIX)/sbin/biosdecode clean : - rm -f dmidecode biosdecode + rm -f *.o dmidecode biosdecode diff --git a/biosdecode.c b/biosdecode.c index 1ec1df4..5d64e3b 100644 --- a/biosdecode.c +++ b/biosdecode.c @@ -1,11 +1,8 @@ /* * BIOS Decode * - * (C) 2000-2002 Alan Cox <alan@redhat.com> - * (C) 2002-2003 Jean Delvare <khali@linux-fr> - * - * Licensed under the GNU Public license. If you want to use it in with - * another license just ask. + * (C) 2000-2002 Alan Cox <alan@redhat.com> + * (C) 2002-2003 Jean Delvare <khali@linux-fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,14 +52,10 @@ #include <fcntl.h> #include <string.h> #include <stdlib.h> -#include <errno.h> -#include <ctype.h> #include "version.h" - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; +#include "types.h" +#include "util.h" #ifdef BIGENDIAN typedef struct { @@ -88,50 +81,6 @@ struct bios_entry { int (*decode)(const u8*, size_t); }; -/* - * Tools - */ - -static int myread(int fd, u8 *buf, size_t count, const char *prefix) -{ - ssize_t r=1; - size_t r2=0; - - while(r2!=count && r!=0) - { - r=read(fd, buf+r2, count-r2); - if(r==-1) - { - if(errno!=EINTR) - { - close(fd); - perror(prefix); - return -1; - } - } - else - r2+=r; - } - - if(r2!=count) - { - close(fd); - fprintf(stderr, "%s: Unexpected end of file\n", prefix); - return -1; - } - - return 0; -} - -static __inline__ int checksum(const u8 *buf, size_t len) -{ - u8 sum=0; - size_t a; - - for(a=0; a<len; a++) - sum+=buf[a]; - return (sum==0); -} /* * SMBIOS diff --git a/dmidecode.c b/dmidecode.c index e999fcc..bbaddee 100644 --- a/dmidecode.c +++ b/dmidecode.c @@ -1,12 +1,8 @@ /* * DMI Decode * - * (C) 2000-2002 Alan Cox <alan@redhat.com> - * (C) 2002-2003 Jean Delvare <khali@linux-fr> - * - * - * Licensed under the GNU Public license. If you want to use it in with - * another license just ask. + * (C) 2000-2002 Alan Cox <alan@redhat.com> + * (C) 2002-2003 Jean Delvare <khali@linux-fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,18 +51,14 @@ #include <fcntl.h> #include <string.h> #include <stdlib.h> -#include <errno.h> #include "version.h" +#include "types.h" +#include "util.h" static const char *out_of_spec = "<OUT OF SPEC>"; static const char *bad_index = "<BAD INDEX>"; -typedef unsigned char u8; -typedef unsigned short u16; -typedef signed short i16; -typedef unsigned int u32; - /* * The specification isn't very clear on endianness problems, so we better * have macros for these. It also helps us solve problems on systems that @@ -145,40 +137,6 @@ struct dmi_header #define HANDLE(x) x->handle #endif -/* - * Tools - */ - -static int myread(int fd, u8 *buf, size_t count, const char *prefix) -{ - ssize_t r=1; - size_t r2=0; - - while(r2!=count && r!=0) - { - r=read(fd, buf+r2, count-r2); - if(r==-1) - { - if(errno!=EINTR) - { - close(fd); - perror(prefix); - return -1; - } - } - else - r2+=r; - } - - if(r2!=count) - { - close(fd); - fprintf(stderr, "%s: Unexpected end of file\n", prefix); - return -1; - } - - return 0; -} /* * Type-independant Stuff @@ -3851,15 +3809,6 @@ static void dmi_table(int fd, u32 base, u16 len, u16 num, u16 ver, const char *p } -static int checksum(u8 *buf, u8 len) -{ - u8 sum=0, a; - - for(a=0; a<len; a++) - sum+=buf[a]; - return (sum==0); -} - int main(int argc, const char *argv[]) { u8 buf[0x20]; @@ -0,0 +1,7 @@ +#ifndef TYPES_H +#define TYPES_H +typedef unsigned char u8; +typedef unsigned short u16; +typedef signed short i16; +typedef unsigned int u32; +#endif |