From: SourceForge.net <no...@so...> - 2004-10-27 18:00:42
|
Read and respond to this message at: https://sourceforge.net/forum/message.php?msg_id=2825273 By: zephyrus00jp Lately I had a non-working program when I ported a program that runs on Solaris/Linux and a few other platforms including CYGWIN to non-CYGWIN mingw platorm using the -mno-cygwin switch to mingw GCC compiler. After a long debugging sessions, it turns out that I have not specified "b" in the second argument to fopen Wrong! fopen(filename, "r") fopen(filename, "w") fopen(filename, "w+r") Correct! fopen(filename, "rb") fopen(filename, "wb") fopen(filename, "w+rb") I initially suspected buggy mingw runtime since the same program works like a charm under cygwin environment. I now recall CYGWIN decided to do away with the distinction of text-mode and binary mode and now supports only binary mode (that is, the cygwin runtime assumes that you intend to have binary mode fopen even if you say, "r", "w", etc. without having "b" in the string. The cygwin runtime takes care of the missing "b" and adds it internally, so to speak.). I think it is a clever move to avoid porting problems like the one I experience here. Will mingw developers consider such modification of the interface provided by mingw runtime? Or if doing away the text and binry modes distinction is too much (since some windows programmers may depend on it), will developers be interested in providing some kind of wrappers like the following? This will warn the programmers about the missing "b" when people port programs from other platforms. They can disable such warning by setting the value of a global variable. So it is a good reminder, but can be made silent. The following is a rough outline of the code , but you will get the idea. In the header somewhere: extern void * __mingw32_check_fopen_mode(char *m); #define fopen(f,m) fopen(f,__mingw32_check_fopen_mode(m)) In the runtime library. int __mingw32_c_f_m_shutup; void * __mingw32_check_fopen_mode(char *m) { if(__mingw32_c_f_m_shutup == 0 && strchr(m, "b") == NULL) { /* We may want to use write() directly instead of using stderr, but you get the idea here.*/ fprintf(stderr,"The second argument to fopen, '%s' doesn't contain \b\. \n", m); fprintf(stderr,"We suggest you add it for maximum compatibility with other platforms. \n"); fprintf(stderr,"You can silence this message by setting a global variable int __mingw32_c_f_m_shutup to 1.\n"); } return m; } You can simply concatenate "b" to the argument m by copying m into a static array of a suitable size and then add "b" at the end to provide CYGWIN-like "forget text-mode vs binary mode distinction" support. Mabye if we set __mingw32_c_f_m_shutup to 2, we could do that automatically and return the concatenated string as the value passed to fopen. Any way, thank you for the great package and I hope my suggestion here might be helpful to future programmers who port programs from other platforms to mingw environment. ______________________________________________________________________ You are receiving this email because you elected to monitor this forum. To stop monitoring this forum, login to SourceForge.net and visit: https://sourceforge.net/forum/unmonitor.php?forum_id=286529 |