emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `message' not outputting the newline "atomically"


From: Eli Zaretskii
Subject: Re: `message' not outputting the newline "atomically"
Date: Tue, 02 Jul 2019 17:47:28 +0300

> Cc: address@hidden
> From: Daniele Nicolodi <address@hidden>
> Date: Tue, 2 Jul 2019 09:58:34 +0200
> 
> On 01/07/2019 20:28, Eli Zaretskii wrote:
> >> From: Daniele Nicolodi <address@hidden>
> >> Date: Mon, 1 Jul 2019 19:01:18 +0200
> >>
> >> I think you didn't understand my point, and your selective quoting makes
> >> me thing you are trying to warp what i wrote in your favor. I was
> >> arguing that in the case of a fprintf() with a format string that ends
> >> in a new line there is no way to obtain a partial output, with stderr
> >> unbuffered or line buffered. On any sane implementation of the c library
> >> Either you will get it all or nothing.
> > 
> > And I was saying that this is wrong.  With unbuffered stderr, you
> > _can_ obtain partial output.
> 
> I still disagree.

Then maybe you should have a look at the implementation in the various
libc's out there.  In all those I looked at, fwrite, fprintf,
etc. call fputc or its moral equivalent to emit every single character
they produce; they rely on the lower-level buffering layer to DTRT
regarding buffering.  IOW, none of the functions that write to FILE
stream pay any attention to the newline.  In particular, using fputc
for every character means that in an unbuffered stream each character
will be immediately written out, modulo the low-level device-specific
buffering in the OS.

> Can you please write a piece of C code that achieves that, having a
> fprintf() function call error out, in whichever way you prefer, such
> that it's output is partial? I tried to achieve that myself and I
> haven't found a way.

See one such example below.  The effect might be system-dependent, but
it crashes in the middle of output for me both on GNU/Linux and on
MS-Windows.

(I still don't understand why you insist on an example.  It should be
clear that such situations are possible, even if rare.  We are talking
about a general-purpose diagnostic facility, not something designed
for special-purpose use cases.)

======================================================================
#include <stdio.h>

char foo[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, \
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

int
main (void)
{
  fprintf (stderr, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s 
%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s 
%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s 
%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s 
%s %s %s %s %s %s %s %s %s %s\n", foo, foo, foo, foo, foo, foo, foo, foo, foo, 
foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, 
foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, 
foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, 
foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, 
foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, 
foo, foo);
  return 0;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]