(MINGW_OBJS): Add txtmode.o.
(SRCDIST_FILES): Add txtmode.c binmode.c.
crt1.c: Don't include fcntrl.h, stdlib.h.
(_fmode): Declare, without dllimport attribute.
(__p__fmode): Declare access function for dll's _fmode.
(_mingw32_init_fmode): Sync dll _fmode with staticly linked
_fmode for app.
* txtmode.c: New file.
* binmode.c: New file.
* samples/fmode/test2.c: New file.
* samples/fmode/jamfile: Add test2.exe target.
+2002-10-19 Danny Smith <dannysmith@users.sourceforge.net>
+
+ * Makefile.in (CRT0S): Add txtmode.o binmode.o.
+ (MINGW_OBJS): Add txtmode.o.
+ (SRCDIST_FILES): Add txtmode.c binmode.c.
+ crt1.c: Don't include fcntrl.h, stdlib.h.
+ (_fmode): Declare, without dllimport attribute.
+ (__p__fmode): Declare access function for dll's _fmode.
+ (_mingw32_init_fmode): Sync dll _fmode with staticly linked
+ _fmode for app.
+ * txtmode.c: New file.
+ * binmode.c: New file.
+ * samples/fmode/test2.c: New file.
+ * samples/fmode/jamfile: Add test2.exe target.
+
2002-10-11 Danny Smith <dannysmith@users.sourceforge.net>
* include/stdint.h (INT64_C, UINT64_C ): Append suffix to let
TARFILEEXT="$(TARFILEEXT)"
CRT0S = crt1.o dllcrt1.o crt2.o dllcrt2.o CRT_noglob.o crtmt.o crtst.o \
- CRT_fp8.o CRT_fp10.o
+ CRT_fp8.o CRT_fp10.o txtmode.o binmode.o
MINGW_OBJS = CRTglob.o CRTfmode.o CRTinit.o dllmain.o gccmain.o \
- main.o crtst.o mthr_stub.o CRT_fp10.o
+ main.o crtst.o mthr_stub.o CRT_fp10.o txtmode.o
MOLD_OBJS = ctype_old.o string_old.o
LIBS = libcrtdll.a libmsvcrt.a libmsvcrt20.a libmsvcrt40.a libmingw32.a \
gccmain.c init.c install-sh jamfile main.c mkinstalldirs moldname-crtdll.def \
moldname-msvcrt.def moldname.def moldname.def.in msvcrt.def msvcrt20.def \
msvcrt40.def mthr.c mthr_init.c mthr_stub.c readme.txt string_old.c \
-CRT_fp8.c CRT_fp10.c test_headers.c
+CRT_fp8.c CRT_fp10.c test_headers.c txtmode.c binmode.c
all_dlls_host = @all_dlls_host@
install_dlls_host = @install_dlls_host@
--- /dev/null
+#include <fcntl.h>
+
+/* Set default file mode to binary */
+
+int _fmode = _O_BINARY;
*
*/
-#include <stdlib.h>
#include <stdio.h>
#include <io.h>
-#include <fcntl.h>
#include <process.h>
#include <float.h>
#include <windows.h>
__MINGW_IMPORT void __set_app_type(int);
#endif /* __MSVCRT__ */
+/* Global _fmode for this .exe, not the one in msvcrt.dll,
+ The default is set in txtmode.o in libmingw32.a */
+#undef _fmode
+extern int _fmode;
+extern int* __p__fmode(void); /* To access the dll _fmode */
+
/*
* Setup the default file handles to have the _CRT_fmode mode, as well as
* any new files created by the user.
_setmode (_fileno (stderr), _CRT_fmode);
}
}
+
+ /* Now sync the dll _fmode to the one for this .exe. */
+ *__p__fmode() = _fmode;
+
}
/* This function will be called when a trap occurs. Thanks to Jacob
_mingw32_init_mainargs ();
/*
- * Sets the default file mode for stdin, stdout and stderr, as well
- * as files later opened by the user, to _CRT_fmode.
+ * Sets the default file mode.
+ * If _CRT_fmode is set, also set mode for stdin, stdout
+ * and stderr, as well
* NOTE: DLLs don't do this because that would be rude!
*/
_mingw32_init_fmode ();
Main test.exe : test.c ;
+Main test2.exe : test2.c ;
+
Main all.exe : all.c ;
--- /dev/null
+/*
+ * A sample program demonstrating how to use fmode to change the default
+ * file opening mode to binary. Compare this file, which sets _fmode
+ * at file level to test.c, which sets the dll variable directly within
+ * main.
+ * NOTE: Does not change stdin, stdout or stderr.
+ *
+ * THIS CODE IS IN THE PUBLIC DOMAIN.
+ *
+ * Colin Peters <colin@fu.is.saga-u.ac.jp>
+ * Danny Smith <dannysmith@users.sourceforge.net>
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* _fmode */
+#include <fcntl.h> /* _O_BINARY */
+
+#undef _fmode
+int _fmode = _O_BINARY;
+
+main ()
+{
+
+ char* sz = "This is line one.\nThis is line two.\n";
+ FILE* fp;
+
+ printf (sz);
+
+ /* Note how this fopen does NOT indicate "wb" to open the file in
+ * binary mode. */
+ fp = fopen ("test2.out", "w");
+
+ fprintf (fp, sz);
+
+ fclose (fp);
+}
+
--- /dev/null
+#include <fcntl.h>
+
+/* Set default file mode to text */
+
+/* Is this correct? Default value of _fmode in msvcrt.dll is 0. */
+
+int _fmode = _O_TEXT;