News for hackers. Stuff that matters.
Re:Make your STDERR red by bdonlan on Tuesday December 13, 2011 @06:27PM (#3349856)
Or use writev for that matter.

Note that using ordinary write multiple times has atomicity implications - if you have multiple processes writing to STDERR, you might find their output interleaved in unfortunate ways. Using a single write with a temporary buffer or writev avoids this (provided you're not writing more than PIPE_BUF bytes total)

Re:Make your STDERR red by nviennot on Tuesday December 13, 2011 @07:19PM (#3350007)
Re:Make your STDERR red by agwa on Tuesday December 13, 2011 @07:27PM (#3350040)
I agree that writev is a better approach. But your patch doesn't look thread-safe because it uses that static iovec struct.
Re:Make your STDERR red by nviennot on Tuesday December 13, 2011 @07:34PM (#3350061)
You are right, and there are other issues: - I don't return the proper return value (should not return the number of bytes from the color strings) - I don't handle the case where writev() returns a number of bytes between 0 and count (e.g. You are writing 10Mb of data, a signal arrives, and you only wrote 5Mb -- the color thing will get all confused)