Input data: there is a kind of library that spits into stderr (stdout, not fundamentally) in case of errors. It would be desirable to save this business in the variables, but not to spoil the console. Especially since it may not be at all. And in general, I want to determine the time and location of the error message myself.
The simplest solution is to rediscover standard threads and setvbuf . Moreover, the authors of the library provide for their duplication initially. After that, everything becomes as if simple ( lib is a conditional structure containing data for the operation of this library):
setvbuf( lib.StdOut, lib.OutBuf, _IOFBF, LIB_OUTBUF_SIZE ); /* ... много кода ... */ if( someLibFunction() == FIGNYA ) { handleExternalLibError( lib.OutBuf ); /* здесь сообщение об ошибке */ } The question is in the meaning of this very LIB_OUTBUF_SIZE . It was established experimentally (and with the flu from the library sources) that there could be a file name. One thing is important, and some texts. So, PATH_MAX+PATH_MAX to PATH_MAX+PATH_MAX for sure. And if there any .po -shipping, yes in German? Or what language is there with the longest expletives :)
In any case, I want some kind of universal approach. Ideas?
someLibFunction(). - Vladimir Gamalyansetvbufwill only set a buffer for the stream, but will it prevent output to the console? In addition, itYou shouldn't try to access the values in the array directly while the stream is using it for buffering.those. It is not recommended to climb into the buffer. - Vladimir Gamalyan/dev/null, orNUL, it doesn't matter. The question is only in size. Enough to receive a message in the general case . - PinkTuxnul, a sufficiently intelligent system will simply completely ignore the buffer ... :) - Harry