From mint-bounce@lists.fishpool.fi Tue Jan 22 17:31:43 2008 X-Original-To: fnaumann@mail.boerde.de Delivered-To: fnaumann@mail.boerde.de Message-ID: <4777C310.40504@freesbee.fr> Date: Sun, 30 Dec 2007 17:10:56 +0100 From: =?ISO-8859-1?Q?Vincent_Rivi=E8re?= User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: mint@fishpool.com Subject: Re: [MiNT] stdio write problem in mintlib References: <20071230010610.GA29673@fairlite.demon.co.uk> <47775FEF.5060708@freesbee.fr> <20071230102935.GB32676@fairlite.demon.co.uk> <20071230142950.GA1737@fairlite.demon.co.uk> In-Reply-To: <20071230142950.GA1737@fairlite.demon.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-ecartis-version: Ecartis v1.0.0 Sender: mint-bounce@lists.fishpool.fi Errors-To: mint-bounce@lists.fishpool.fi X-original-sender: vincent.riviere@freesbee.fr Precedence: bulk List-help: List-unsubscribe: List-Id: X-List-ID: List-subscribe: List-owner: List-post: X-Virus-Scanned: by amavisd-new at relay.boerde.de X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on relay.boerde.de X-Spam-Status: No, hits=-1.0 tagged_above=-50.5 required=7.0 tests=BAYES_00 X-Spam-Level: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by freemint id m0MGP1ch004618 Status: X-Status: X-Keywords: Alan Hourihane a écrit : > Yeah, it's o.k. turns out to be the shell. > > Not to worry. Unfortunately, you're wrong. The problem is in the MiNTLib. The main idea is that the text mode (CR+LF) should only be used with regular files (if not disabled by UNIXMODE=b), and never used with pipes. The shell statement `command` does exactly what is expected : it runs the command to a pipe, then replaces spaces and LF by single spaces. The CR characters are treated as normal characters (not removed). It should not be a problem, because no end-of-line CR should be present in the pipe. I know very well the problem, because some time ago, I had a discussion about that with Cygwin people, where the situation is similar. The current MiNTLib always configures stdout in textmode, regardless if it is connected to a device (console), a file, or a pipe. It really should check for that, like Cygwin. A workaround is to configure the correct mode by hand at the beginning of the program. #include #include main() { /* Never use text mode to pipes. */ struct stat st; fstat(1, &st); if (S_ISSOCK(st.st_mode)) __set_binmode(stdout, 1); putchar('a'); putchar('\n'); } This will work as expected in all cases. Note that during my tests, I got the same results with putchar() and printf(), maybe you made a mistake somewhere. -- Vincent Rivière