X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=rMAc1dWeozWacuE8okYdLOwvwWEX3 sLcJFyo+YMe4r4DcjPRr5In53EZg4UC5rLLgKYAIr39zXE60V/qhLN8ucKMh2tSl tGubcIDnPlilJuvBcg8bhXD0sZBNcm5C9ENBE64PtJ2oZnX2ZJUi2XzLum5Y4MDY yMSpRRUn6YIZyw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=TWEYTSnu6e8GWbvBpXqeT99ikP0=; b=w6U EYTiX5SXf18lc1F8Nl7g7B5xuntkwQ3VemWOIbsnDPvRMSMXbqaVq5q+iRU2AAFB W+JpfRMAsdKUxCZ7fJeCsuD1tvkJFbktmxjBsr+28L95/1KY26LhEJUHLh4RvcAr EIeTFJ386fVgL6eAjGFOGHZbpvSJIRYlXYlBjLtg= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 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) Date: Sat, 26 Aug 2017 22:52:24 +0100 From: Adam Dinwoodie To: cygwin AT cygwin DOT 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 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