Re:Make your STDERR red
by cnvogel on Wednesday December 14, 2011 @03:48AM
(#3351133)
While it might not be relevant in practice, there's the possibility of data corruption if someone closes all filedescriptors (for whatever reason) and then operates on the newly generated ones. This implementation just checks for filedescriptor number 2, a more sensible implementation for sure should hook the stdio FILE or iostream mechanisms to restrict colorization only to the "standard error" case.
for(i=0;i<1024;i++) close(i); /* close a lot of fd /
/ open will yield the lowest free fds, here it's 0,1,2 /
for(i=0;i<1024;i++) close(i); /* close a lot of fd /
/ open will yield the lowest free fds, here it's 0,1,2 /
f=open("inputfile",O_RDONLY);
g=open("outputfile1",O_RDWR|O_CREAT,0666);
h=open("outputfile2",O_RDWR|O_CREAT,0666);
read(f,buf,1024);
write(g,buf,1024);
write(h,buf,1024); / <-- data is colorized! */