Adjusted alternate version to preserve formatting
The first alt version added some whitespaces that broke the outline, so I simply filled those up. I also expanded tabs to spaces since there is no size limit restriction for the alternate version. The second alt version attempted to force binary mode with _setmode() and _fileno() calls, plus some additional headers. Rather than doing it this way, I hack in the binary mode adjustments via preprocessor. Actually I did a similar trick for IOCCC 2011, but I guess I didn't submit that version: https://uguu.org/archive/ioccc2011/akari/source/binmode_main.h The file above uses _setmode() and _fileno(). The leading underscore indicates that they were nonstandard extensions. For the binmode_main.h in this change, I have opted for setmode() and STDIN_FILENO instead, which are more widely available.
This commit is contained in:
1 parent
376f51c489
commit
aff78be8f9
5 files changed
+93
-117
No files matched your search
@@ -0,0 +1,39 @@
|
||||
/* Preprocessor hack to set binary mode for stdin and stdout.
|
||||
|
||||
This replaces main() with an alternative function forces binary
|
||||
modes. This is intended to included via compiler arguments, so we
|
||||
would be able to enable binary modes without modifying the original
|
||||
program source. Conceptually, it's similar to LD_PRELOAD, except
|
||||
we hack it in via preprocessor.
|
||||
|
||||
It only works for programs where main() occurs just once.
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<io.h>
|
||||
#include<unistd.h>
|
||||
|
||||
#define main \
|
||||
/* Forward declaration for the updated main(), now renamed */ \
|
||||
/* binmode_main(). Return type is omitted since this macro */ \
|
||||
/* is expanded just after the return type. */ \
|
||||
binmode_main(int argc, char **argv); \
|
||||
\
|
||||
/* Updated main(). */ \
|
||||
int main(int argc, char **argv) \
|
||||
{ \
|
||||
/* Set binary modes. */ \
|
||||
setmode(STDIN_FILENO, O_BINARY); \
|
||||
setmode(STDOUT_FILENO, O_BINARY); \
|
||||
\
|
||||
/* Call the original main(). */ \
|
||||
return binmode_main(argc, argv); \
|
||||
} \
|
||||
\
|
||||
/* Definition for the original main. Function arguments are */ \
|
||||
/* omitted since this macro is expanded just before the arguments. */ \
|
||||
int binmode_main
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user