Creideiki <creideiki+pythonb...@ferretporn.se> added the comment:

I ran this program:


#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

void print(const char *s, size_t l)
{
   errno = 0;
   fwrite(s, l, 1, stdout);
   int saved_errno = errno;
   fprintf(stderr,
           "After \"%s\": ferror(): %i, strerror(): %s\n",
           s, ferror(stdout), strerror(saved_errno));
   clearerr(stdout);
}

int main()
{
   usleep(5 * 1000 * 1000);
   print("A", 1);
   print("\n", 1);
   print("B\nC", 3);
   print("\n", 1);
   print("D", 1);
   print("\n", 1);
   return 0;
}



Got this result:


write(2, "After \"A\": ferror(): 0, strerror(): Success\n", 44) = -1 EIO 
(Input/output error)
write(1, "A\n", 2)                      = -1 EIO (Input/output error)
write(2, "After \"\n\": ferror(): 1, strerror(): Input/output error\n", 55) = 
-1 EIO (Input/output error)
write(1, "B\n", 2)                      = -1 EIO (Input/output error)
write(2, "After \"B\nC\": ferror(): 1, strerror(): Input/output error\n", 57) = 
-1 EIO (Input/output error)
write(1, "\n", 1)                       = -1 EIO (Input/output error)
write(2, "After \"\n\": ferror(): 1, strerror(): Input/output error\n", 55) = 
-1 EIO (Input/output error)
write(2, "After \"D\": ferror(): 0, strerror(): Success\n", 44) = -1 EIO 
(Input/output error)
write(1, "D\n", 2)                      = -1 EIO (Input/output error)
write(2, "After \"\n\": ferror(): 1, strerror(): Input/output error\n", 55) = 
-1 EIO (Input/output error)


So, fwrite() with a string which does not contain a newline is buffered and 
ferror() returns 0. fwrite() with a string which does contain a newline, in the 
middle or at the end, flushes the buffer and makes ferror() return 1.

I think this means that after print('A') gets turned into write(1, "A\n", 2), 
ferror() should still be 1.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32345>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to