From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58764 invoked by alias); 26 Aug 2017 21:52:32 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 58754 invoked by uid 89); 26 Aug 2017 21:52:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=adam, H*F:U*adam, king, seeking X-HELO: mail-wr0-f172.google.com Received: from mail-wr0-f172.google.com (HELO mail-wr0-f172.google.com) (209.85.128.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 26 Aug 2017 21:52:29 +0000 Received: by mail-wr0-f172.google.com with SMTP id a47so8308848wra.4 for ; Sat, 26 Aug 2017 14:52:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=70vOWG42MqJHa5Jw79S8ib79KWkKFofn0Ku5z9Is1HE=; b=T0jfuwY62zUJhCZ79oj6otqjzOzn5qKkbRqQNfcL6G2Afu43aLE3/y9Hk1T9miUxgz lF6yO0efJrhzd2IhU9FVzVa3jwGxEMvGeUvLu2J85FcNui5ZE59mr/GQRGhKBZK5hcIQ 6s8BvNS/POcYM6okdC5v13hMWTmibs4icZAnqo6ILuvx8C08EwIY9VFwFduGlhD0HggC qOWUivfr82zDGUygAgFzHAXP4liiW0NYL5ZF5Oe7fgxpboe4qpUpjU30gSsBEVox2EOv sKoZnux423nOn2KVx4I/x8AhVP6oXaqJZR84ht2NxhnoQ9AsfmcL16aEos3vJNSGxi5k ie/g== X-Gm-Message-State: AHYfb5j24JSdwpMZObRuAdGPrWb1WGG9Dsrp0dlwzrX9QMn9DoVgDoTp 8oGMijxxncKmYT8pM/PX8A== X-Received: by 10.223.174.81 with SMTP id u17mr1938795wrd.237.1503784347454; Sat, 26 Aug 2017 14:52:27 -0700 (PDT) Received: from dinwoodie.org ([2001:ba8:0:1c0::9:1]) by smtp.gmail.com with ESMTPSA id s1sm7547454wra.75.2017.08.26.14.52.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Aug 2017 14:52:26 -0700 (PDT) Date: Sat, 26 Aug 2017 21:52:00 -0000 From: Adam Dinwoodie To: cygwin@cygwin.com Subject: fflush(NULL) empties stdin Message-ID: <20170826215224.GD10378@dinwoodie.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00244.txt.bz2 Hello, I seem to have found a bug in Cygwin's fflush implementation, where fflush(NULL) is unexpectedly flushing stdin. Working through https://cygwin.com/snapshots/ with the STC below, this behaviour does not appear in the 2017-03-08 snapshot, and 2017-03-10 is the first snapshot in which this does appear, with thanks to Ramsay Jones on the Git mailing list for initially pointing me at the change coming in some time between 2.7.0 and 2.8.0. With thanks to Jeff King on the Git mailing list, here's a simple test case: $ cat a.c #include int main(void) { char buf[256]; while (fgets(buf, sizeof(buf), stdin)) { fprintf(stdout, "got: %s", buf); fflush(NULL); } return 0; } $ gcc a.c $ seq 10 | ./a.exe got: 1 Compare this to the expected output, which I see on my handy CentOS 6 box: $ seq 10 | ./a.out got: 1 got: 2 got: 3 got: 4 got: 5 got: 6 got: 7 got: 8 got: 9 got: 10 By my reading of Cygwin's fflush(3p), the stdin stream should be unaffected by a fflush(NULL), as it is neither an output stream, an update stream, nor a file capable of seeking. I originally noticed this behaviour due to it causing a failure in one of the Git test scripts. Cheers, Adam -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple