From patchwork Tue Sep 21 02:54:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [libgfortran] PR45723 opening /dev/null for appending writes fails From: Jerry DeLisle X-Patchwork-Id: 65270 Message-Id: <4C981E53.1080608@frontier.com> To: gfortran Cc: gcc patches Date: Mon, 20 Sep 2010 19:54:11 -0700 Hi, This patch is simple. Test case attached. Regression tested on x86-64. OK for trunk? Jerry 2010-09-20 Jerry DeLisle PR libfortran/45723 * io/open.c (new_unit): On POSITION_APPEND don't seek if file length is zero. ! { dg-do run } ! PR45723 opening /dev/null for appending writes fails logical :: thefile inquire(file="/dev/null",exist=thefile) if (thefile) then open(unit=7,file="/dev/null",position="append") close(7) endif end Index: open.c =================================================================== --- open.c (revision 164472) +++ open.c (working copy) @@ -555,7 +555,7 @@ new_unit (st_parameter_open *opp, gfc_unit *u, uni if (flags->position == POSITION_APPEND) { - if (sseek (u->s, 0, SEEK_END) < 0) + if (file_size (opp->file, opp->file_len) > 0 && sseek (u->s, 0, SEEK_END) < 0) generate_error (&opp->common, LIBERROR_OS, NULL); u->endfile = AT_ENDFILE; }