This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Creideiki
Recipients Creideiki, pitrou
Date 2017-12-20.13:10:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1513775412.66.0.213398074469.issue32345@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-12-20 13:10:12Creideikisetrecipients: + Creideiki, pitrou
2017-12-20 13:10:12Creideikisetmessageid: <1513775412.66.0.213398074469.issue32345@psf.upfronthosting.co.za>
2017-12-20 13:10:12Creideikilinkissue32345 messages
2017-12-20 13:10:12Creideikicreate