From c1fd61b4196e770f14af5f2293dcc799aa44d56b Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Wed, 1 Sep 2004 16:40:26 +0000 Subject: [PATCH] use portable file io --- ipmitool/include/ipmitool/helper.h | 3 ++- ipmitool/lib/ipmi_sdr.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ipmitool/include/ipmitool/helper.h b/ipmitool/include/ipmitool/helper.h index 73a3374..32d6e1a 100644 --- a/ipmitool/include/ipmitool/helper.h +++ b/ipmitool/include/ipmitool/helper.h @@ -38,6 +38,7 @@ #define IPMI_HELPER_H #include +#include struct valstr { unsigned short val; @@ -52,7 +53,7 @@ const char * buf2str(unsigned char * buf, int len); void printbuf(const unsigned char * buf, int len, const char * desc); void signal_handler(int sig, void * handler); unsigned char ipmi_csum(unsigned char * d, int s); -int ipmi_open_file(const char * file, int flags); +FILE * ipmi_open_file(const char * file, int flags); #define ipmi_open_file_read(file) ipmi_open_file(file, 0) #define ipmi_open_file_write(file) ipmi_open_file(file, 1) diff --git a/ipmitool/lib/ipmi_sdr.c b/ipmitool/lib/ipmi_sdr.c index af0f73f..1069760 100644 --- a/ipmitool/lib/ipmi_sdr.c +++ b/ipmitool/lib/ipmi_sdr.c @@ -1387,10 +1387,10 @@ static int ipmi_sdr_dump_bin(struct ipmi_intf * intf, const char * ofile) { struct sdr_get_rs * header; struct ipmi_sdr_iterator * itr; - int fd; + FILE * fp; - fd = ipmi_open_file_write(ofile); - if (fd < 0) { + fp = ipmi_open_file_write(ofile); + if (!fp) { return -1; } @@ -1398,7 +1398,7 @@ static int ipmi_sdr_dump_bin(struct ipmi_intf * intf, const char * ofile) itr = ipmi_sdr_start(intf); if (!itr) { printf("Unable to open SDR for reading\n"); - close(fd); + fclose(fp); return -1; } @@ -1423,21 +1423,22 @@ static int ipmi_sdr_dump_bin(struct ipmi_intf * intf, const char * ofile) h[3] = header->type; h[4] = header->length; - r = write(fd, h, 5); + r = fwrite(h, 1, 5, fp); if (r != 5) { - printf("Error writing %d byte to output file\n", 5); + printf("Error writing header to output file %s\n", ofile); break; } /* write sdr entry */ - r = write(fd, rec, header->length); + r = fwrite(rec, 1, header->length, fp); if (r != header->length) { - printf("Error writing %d bytes to output file\n", header->length); + printf("Error writing %d record bytes to output file %s\n", + header->length, ofile); break; } } - close(fd); + fclose(fp); return 0; }