--- dcraw.c.bak 2007-11-13 00:09:17.889052611 +0200 +++ dcraw.c 2007-11-13 00:10:25.741054564 +0200 @@ -116,6 +116,7 @@ unsigned tile_width, tile_length; ushort raw_height, raw_width, height, width, top_margin, left_margin; ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; int flip, tiff_flip, colors; +int do_fsync; double pixel_aspect, aber[4]={1,1,1,1}; ushort (*image)[4], white[8][8], curve[0x4001], cr2_slice[3], sraw_mul[4]; float bright=1, user_mul[4]={0,0,0,0}, threshold=0; @@ -7947,6 +7948,7 @@ int CLASS main (int argc, char **argv) puts(_("-e Extract embedded thumbnail image")); puts(_("-i Identify files without decoding them")); puts(_("-i -v Identify files and show metadata")); + puts(_("-F fsync every written file")); puts(_("-z Change file dates to camera timestamp")); puts(_("-w Use camera white balance, if possible")); puts(_("-a Average the whole image for white balance")); @@ -8021,6 +8023,7 @@ int CLASS main (int argc, char **argv) case 'v': verbose = 1; break; case 'h': half_size = 1; /* "-h" implies "-f" */ case 'f': four_color_rgb = 1; break; + case 'F': do_fsync = 1; break; case 'A': FORC4 greybox[c] = atoi(argv[arg++]); case 'a': use_auto_wb = 1; break; case 'w': use_camera_wb = 1; break; @@ -8262,7 +8265,33 @@ thumbnail: fprintf (stderr,_("Writing data to %s ...\n"), ofname); (*write_fun)(ofp); fclose(ifp); - if (ofp != stdout) fclose(ofp); + if (ferror(ofp)) { + status = 1; + clearerr(ofp); + fprintf (stderr,_("Writing to %s failed\n"), ofname); + } + if (fflush(ofp) == EOF) { + status = 1; + fprintf (stderr,_("fflush %s failed: %s\n"), ofname, strerror(errno)); + } + if (do_fsync) { + if (verbose) + fprintf (stderr,_("fsync()ing data to %s ... "), ofname); + if (fsync(fileno(ofp)) == -1) { + status = 1; + fprintf (stderr,_("fsync %s failed: %s\n"), ofname, strerror(errno)); + } else { + if (verbose) + fprintf (stderr,_("OK.\n")); + } + } + if (ofp != stdout) { + if (fclose(ofp) == EOF) { + status = 1; + fprintf (stderr,_("fclose %s failed: %s\n"), ofname, strerror(errno)); + } + } + cleanup: if (meta_data) free (meta_data); if (ofname) free (ofname);