라벨이 freopen인 게시물 표시

Porting to OS/2: Case #11 freopen()

freopen() is used to reopen a file with a pre-existed stream pointer. kLIBC supports freopen() well. However, it has a problem. First, let's see the prototype of freopen(). FILE *freopen(const char * filename , const char * mode , FILE * stream ); If filename is NULL, freopen() changes the mode of stream. That is, read/write, text/binary and so on. And if freopen() fails, then it returns NULL. By the way, kLIBC freopen() returns NULL even if it succeeds when filename is NULL. For examples, the following code returns NULL. freopen( NULL, "wb", stdout ); However, stdout is changed to binary mode correctly. So in this case, the return value should be ignored. Nevertheless, you should not always ignore NULL. Then what is the way to distinguish them ? freopen() sets 'errno' variable to a proper error value if it fails. So if you check errno, then it is possible to distinguish them. Use the following macro. Colored By Color Scripter ™ 1 2 #define  freopen...