From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 17 21:07:55 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DE12E9F for ; Sat, 17 Jan 2015 21:07:55 +0000 (UTC) Received: from mst-rip6-missouri-out.um.umsystem.edu (mst-rip6-missouri-out.um.umsystem.edu [198.209.50.149]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "um-tip1.um.umsystem.edu", Issuer "InCommon RSA Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8AFB0988 for ; Sat, 17 Jan 2015 21:07:55 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiUFAGHNulTPoJ7U/2dsb2JhbABZgwaBLsQJhUeCTwKBDkMBAQEBAQN6hA0BBXgRAgEIGAkWDwkDAgECASAlAgQBDAgBAYgoyzsBg1cBCgEBAR6PRjqEKQWOTJsZIoNugjR+AQEB X-IPAS-Result: AiUFAGHNulTPoJ7U/2dsb2JhbABZgwaBLsQJhUeCTwKBDkMBAQEBAQN6hA0BBXgRAgEIGAkWDwkDAgECASAlAgQBDAgBAYgoyzsBg1cBCgEBAR6PRjqEKQWOTJsZIoNugjR+AQEB Received: from um-ncas6.um.umsystem.edu ([207.160.158.212]) by mst-rip6-exch-relay.um.umsystem.edu with ESMTP; 17 Jan 2015 15:06:45 -0600 Received: from UM-MBX-N02.um.umsystem.edu ([169.254.5.23]) by UM-NCAS6.um.umsystem.edu ([207.160.158.212]) with mapi id 14.03.0210.002; Sat, 17 Jan 2015 15:06:45 -0600 From: "Montgomery-Smith, Stephen" To: less xss , "freebsd-hackers@freebsd.org" Subject: Re: ctrl-d appends characters to output Thread-Topic: ctrl-d appends characters to output Thread-Index: AQHQMoq4BXOKvIQ6l0u+m3Cgq79pjZzFJFMAgAAMkQCAAAGZgA== Date: Sat, 17 Jan 2015 21:06:44 +0000 Message-ID: <54BACEE3.9080500@missouri.edu> References: <54BAC302.7050800@missouri.edu> <54BACD8C.3050703@missouri.edu> In-Reply-To: <54BACD8C.3050703@missouri.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 x-originating-ip: [207.160.158.206] Content-Type: text/plain; charset="Windows-1252" Content-ID: <50E9E6513A254A408ACE9A432FF002C6@missouri.edu> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2015 21:07:56 -0000 On 01/17/2015 03:01 PM, Montgomery-Smith, Stephen wrote: > On 01/17/2015 02:16 PM, Montgomery-Smith, Stephen wrote: >> On 01/17/2015 11:59 AM, less xss wrote: >>> I've searched around quite a bit with no luck on this matter. I current= ly >>> have an issue where I send EOF (ctrl-d) to some simple K&R2 exercises a= nd >>> the terminal returns the D character appended to my data when EOF is se= nt. >>> I wish to prevent any and all extra characters from being appended and = I >>> would also like to understand why it's happening. The following code >>> is an example exercise from K&R2 that yield said problem. >>> >>> #include >>> >>> int main() { >>> double nc; >>> >>> for (nc =3D 0; getchar() !=3D EOF; ++nc) { >>> ; /* syntactic null statement */ >>> } >>> >>> printf("%.0f\n", nc); >>> } >>> >>> $ ./a.out >>> 0D >>> $ >> >> I did a bit of experimenting with this issue. First, I cannot reproduce >> it on my Linux box. Second, this simpler program does the same thing: >> >> #include >> >> int main() { >> >> while (getchar() !=3D EOF) { >> ; /* syntactic null statement */ >> } >> >> printf("\n"); >> } >> >> In this case I get: >> >> % ./a.out >> ^D >> % >> >> However, if I remove that last printf statement, then no ^D is displayed= . >> >> Considering the inconsistent nature of when this ^D appears, I would >> prefer to call it a bug than a feature. But it must have been put there >> by design. >=20 > OK, that last printf is NOT responsible for the ^D. It is just that the > prompt wipes it out. Try this code: >=20 > #include > #include >=20 > int main() { >=20 > while (getchar() !=3D EOF) { > ; /* syntactic null statement */ > } > sleep(10); > } >=20 > Then the ^D shows until the prompt appears 10 seconds later. Even simpler - you don't even have to write a program: cat | sleep 10