mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-01-21 16:42:19 +08:00
use portable file io
This commit is contained in:
parent
4763dcf560
commit
c1fd61b419
@ -38,6 +38,7 @@
|
|||||||
#define IPMI_HELPER_H
|
#define IPMI_HELPER_H
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct valstr {
|
struct valstr {
|
||||||
unsigned short val;
|
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 printbuf(const unsigned char * buf, int len, const char * desc);
|
||||||
void signal_handler(int sig, void * handler);
|
void signal_handler(int sig, void * handler);
|
||||||
unsigned char ipmi_csum(unsigned char * d, int s);
|
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_read(file) ipmi_open_file(file, 0)
|
||||||
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)
|
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)
|
||||||
|
|||||||
@ -1387,10 +1387,10 @@ static int ipmi_sdr_dump_bin(struct ipmi_intf * intf, const char * ofile)
|
|||||||
{
|
{
|
||||||
struct sdr_get_rs * header;
|
struct sdr_get_rs * header;
|
||||||
struct ipmi_sdr_iterator * itr;
|
struct ipmi_sdr_iterator * itr;
|
||||||
int fd;
|
FILE * fp;
|
||||||
|
|
||||||
fd = ipmi_open_file_write(ofile);
|
fp = ipmi_open_file_write(ofile);
|
||||||
if (fd < 0) {
|
if (!fp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1398,7 +1398,7 @@ static int ipmi_sdr_dump_bin(struct ipmi_intf * intf, const char * ofile)
|
|||||||
itr = ipmi_sdr_start(intf);
|
itr = ipmi_sdr_start(intf);
|
||||||
if (!itr) {
|
if (!itr) {
|
||||||
printf("Unable to open SDR for reading\n");
|
printf("Unable to open SDR for reading\n");
|
||||||
close(fd);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1423,21 +1423,22 @@ static int ipmi_sdr_dump_bin(struct ipmi_intf * intf, const char * ofile)
|
|||||||
h[3] = header->type;
|
h[3] = header->type;
|
||||||
h[4] = header->length;
|
h[4] = header->length;
|
||||||
|
|
||||||
r = write(fd, h, 5);
|
r = fwrite(h, 1, 5, fp);
|
||||||
if (r != 5) {
|
if (r != 5) {
|
||||||
printf("Error writing %d byte to output file\n", 5);
|
printf("Error writing header to output file %s\n", ofile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write sdr entry */
|
/* write sdr entry */
|
||||||
r = write(fd, rec, header->length);
|
r = fwrite(rec, 1, header->length, fp);
|
||||||
if (r != header->length) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user