From patchwork Mon Aug 2 06:23:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 60511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 4CE1B1007D3 for ; Mon, 2 Aug 2010 16:23:47 +1000 (EST) Received: (qmail 30304 invoked by alias); 2 Aug 2010 06:23:43 -0000 Received: (qmail 30287 invoked by uid 22791); 2 Aug 2010 06:23:43 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Aug 2010 06:23:37 +0000 Received: by iwn34 with SMTP id 34so3871465iwn.20 for ; Sun, 01 Aug 2010 23:23:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.172.70 with SMTP id k6mr6419328ibz.125.1280730215778; Sun, 01 Aug 2010 23:23:35 -0700 (PDT) Received: by 10.231.153.7 with HTTP; Sun, 1 Aug 2010 23:23:35 -0700 (PDT) Date: Mon, 2 Aug 2010 09:23:35 +0300 Message-ID: Subject: [Patch, libfortran] Don't update position flag for non-seekable files From: Janne Blomqvist To: Fortran List , GCC Patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, I've committed the attached patch as obvious to trunk (r162810). The practical offshoot is that for writing to stdout (or other non-seekable non-buffered units) we avoid two failed lseek() syscalls after every record which previously resulted in the position flag being set to POSITION_APPEND, now it's left at whatever it was before. 2010-08-02 Janne Blomqvist * io/unit.c (update_position): Don't update the position flag for non-seekable files, check for stell() error. diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index a0018db..1d52217 100644 --- a/libgfortran/io/unit.c +++ b/libgfortran/io/unit.c @@ -714,12 +714,19 @@ close_units (void) void update_position (gfc_unit *u) { - if (stell (u->s) == 0) - u->flags.position = POSITION_REWIND; - else if (file_length (u->s) == stell (u->s)) - u->flags.position = POSITION_APPEND; - else - u->flags.position = POSITION_ASIS; + /* If unit is not seekable, this makes no sense (and the standard is + silent on this matter), and thus we don't change the position for + a non-seekable file. */ + if (is_seekable (u->s)) + { + gfc_offset cur = stell (u->s); + if (cur == 0) + u->flags.position = POSITION_REWIND; + else if (cur != -1 && (file_length (u->s) == cur)) + u->flags.position = POSITION_APPEND; + else + u->flags.position = POSITION_ASIS; + } }