From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from konig.elte.hu (konig.elte.hu [157.181.6.22]) by euclid.skiles.gatech.edu (8.7.3/8.7.3) with SMTP id OAA10628 for ; Tue, 12 Mar 1996 14:04:14 -0500 (EST) Received: (from hzoli@localhost) by bolyai.cs.elte.hu (8.6.12/8.6.12) id UAA10007 for zsh-workers@math.gatech.edu; Tue, 12 Mar 1996 20:03:50 +0100 From: Zoltan Hidvegi Message-Id: <199603121903.UAA10007@bolyai.cs.elte.hu> Subject: Buffered stderr on Linux To: zsh-workers@math.gatech.edu (zsh-workers) Date: Tue, 12 Mar 1996 20:03:49 +0100 (MET) Organization: Dept. of Comp. Sci., Eotvos University, Budapest, Hungary Phone: (36 1)2669833 ext: 2667, home phone: (36 1) 2752368 X-Mailer: ELM [version 2.4 PL25 ME8b+] Mime-Version: 1.0 Content-Type: application/pgp; format=text; x-action=sign Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- setvbuf(stderr, NULL, _IOFBF, 0) should set stderr to be fully buffered. Unfortunately it does not work on Linux. It works for stdout but not for stderr. But there is no problem if an explicit buffer is given. The patch below fixes that problem. I seems that this problem is Linux specific (and maybe libc-5.2.18 - 5.3.5 specific) but it can be used unconditionally since it does not requires more memory than the NULL pointer solituion since stdio allocates a buffer anyway if there is none given. Now I wander why is it necessary to use malloc to allocate these buffers. Is there anything against using static char[BUFSIZ] buffers? Zoltan *** Src/init.c 1996/03/05 01:44:31 1.13 --- Src/init.c 1996/03/11 01:13:13 *************** *** 346,354 **** argzero = ztrdup(argzero); } - #ifndef _IOFBF static char *outbuf, *errbuf; - #endif /**/ void --- 346,352 ---- *************** *** 360,375 **** int i; #endif - /* stdout, stderr fully buffered */ - #ifdef _IOFBF - setvbuf(stdout, NULL, _IOFBF, 0); - setvbuf(stderr, NULL, _IOFBF, 0); - #else if (!outbuf) outbuf = (char *) malloc(BUFSIZ); if (!errbuf) errbuf = (char *) malloc(BUFSIZ); setbuffer(stdout, outbuf, BUFSIZ); setbuffer(stderr, errbuf, BUFSIZ); #endif --- 358,373 ---- int i; #endif if (!outbuf) outbuf = (char *) malloc(BUFSIZ); if (!errbuf) errbuf = (char *) malloc(BUFSIZ); + /* stdout, stderr fully buffered */ + #ifdef _IOFBF + setvbuf(stdout, outbuf, _IOFBF, BUFSIZ); + setvbuf(stderr, errbuf, _IOFBF, BUFSIZ); + #else setbuffer(stdout, outbuf, BUFSIZ); setbuffer(stderr, errbuf, BUFSIZ); #endif -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAwUBMUXKkwupSCiLN749AQGerAP9Hd/jakBNjyc/GO64gL3raF2aAoqNc0ZL HbIeZMbF6E8fXgRpwuwfCfrf3/CePDLlLGM4f20d+M9cI6NfI+XgqEScEhzhyebR PJPgbKfv6fZdOLDDnI2dtXEIR1HjJczIZRFWb1kL9q69KzdyRChN/36oFEagbJzT Mt6UDNEokmw= =MDY2 -----END PGP SIGNATURE-----