From 43287cd1d3216686b92cec8f693e88ed1d6396ed Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Thu, 30 Jan 2014 08:24:37 -0600 Subject: single function for writing bin data to eeprom --- src/eeprom_main.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/eeprom_main.c b/src/eeprom_main.c index 8abe744..c7956e8 100644 --- a/src/eeprom_main.c +++ b/src/eeprom_main.c @@ -188,7 +188,7 @@ static int dc_yaml_out(const char *name, struct mts_dc_eeprom_layout *dc_eeprom) return 0; } -static int id_bin_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) +static int bin_out(const char *name, char *eeprom) { int fd; int tmp; @@ -203,36 +203,7 @@ static int id_bin_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) } } - tmp = write(fd, (char*) id_eeprom, eeprom_size); - if (tmp < 0) { - log_error("writing %s failed: %m", name); - return fd; - } else if (tmp != eeprom_size) { - log_error("only wrote %d bytes to %s", tmp, name); - return -1; - } - - close(fd); - - return tmp; -} - -static int dc_bin_out(const char *name, struct mts_dc_eeprom_layout *dc_eeprom) -{ - int fd; - int tmp; - - if (!strcmp(name, "-")) { - fd = fileno(stdout); - } else { - fd = open(name, O_CREAT | O_WRONLY, 0644); - if (fd < 0) { - log_error("could not open %s: %m", name); - return fd; - } - } - - tmp = write(fd, (char*) dc_eeprom, eeprom_size); + tmp = write(fd, eeprom, eeprom_size); if (tmp < 0) { log_error("writing %s failed: %m", name); return fd; @@ -622,9 +593,9 @@ int main(int argc, char *argv[]) { if (out_file) { if (!strcmp(out_format, "bin")) { if (! daughter_card) { - id_bin_out(out_file, &id_eeprom); + bin_out(out_file, (char*) &id_eeprom); } else { - dc_bin_out(out_file, &dc_eeprom); + bin_out(out_file, (char*) &dc_eeprom); } } else if (!strcmp(out_format, "yaml")) { if (! daughter_card) { -- cgit v1.2.3