summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-01-30 08:24:37 -0600
committerMike Fiore <mfiore@multitech.com>2014-01-30 08:24:37 -0600
commit43287cd1d3216686b92cec8f693e88ed1d6396ed (patch)
tree7ecc1e9154556dccaf646fd971d8af34ebf748c8
parent1bfd53cec9faf1de810e24e697ba487757366203 (diff)
downloadmts-id-eeprom-43287cd1d3216686b92cec8f693e88ed1d6396ed.tar.gz
mts-id-eeprom-43287cd1d3216686b92cec8f693e88ed1d6396ed.tar.bz2
mts-id-eeprom-43287cd1d3216686b92cec8f693e88ed1d6396ed.zip
single function for writing bin data to eeprom
-rw-r--r--src/eeprom_main.c37
1 files 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) {