- if (mode == O_RDWR) {
- if (HaveRedundEnv) {
- /* switch to next partition for writing */
- dev_target = !dev_current;
- /* dev_target: fd_target, erase_target */
- fd_target = open (DEVNAME (dev_target), mode);
- if (fd_target < 0) {
- fprintf (stderr,
- "Can't open %s: %s\n",
- DEVNAME (dev_target),
- strerror (errno));
- rc = -1;
- goto exit;
- }
- } else {
- dev_target = dev_current;
- fd_target = fd_current;
+err:
+ if (dup_name)
+ free(dup_name);
+
+ return rc;
+}
+
+static int flash_io_write(int fd_current)
+{
+ int fd_target = -1, rc, dev_target;
+ const char *dname, *target_temp = NULL;
+
+ if (have_redund_env) {
+ /* switch to next partition for writing */
+ dev_target = !dev_current;
+ /* dev_target: fd_target, erase_target */
+ fd_target = open(DEVNAME(dev_target), O_RDWR);
+ if (fd_target < 0) {
+ fprintf(stderr,
+ "Can't open %s: %s\n",
+ DEVNAME(dev_target), strerror(errno));
+ rc = -1;
+ goto exit;