From bea966c0d9a65fd0c7b909fc5f8b2b2ff7635537 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Sat, 19 Oct 2002 20:26:26 +0000 Subject: * 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. --- winsup/mingw/samples/fmode/jamfile | 2 ++ winsup/mingw/samples/fmode/test2.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 winsup/mingw/samples/fmode/test2.c (limited to 'winsup/mingw/samples') diff --git a/winsup/mingw/samples/fmode/jamfile b/winsup/mingw/samples/fmode/jamfile index 33455ec59..5b7a1cb06 100644 --- a/winsup/mingw/samples/fmode/jamfile +++ b/winsup/mingw/samples/fmode/jamfile @@ -1,5 +1,7 @@ Main test.exe : test.c ; +Main test2.exe : test2.c ; + Main all.exe : all.c ; diff --git a/winsup/mingw/samples/fmode/test2.c b/winsup/mingw/samples/fmode/test2.c new file mode 100644 index 000000000..b7d6b1891 --- /dev/null +++ b/winsup/mingw/samples/fmode/test2.c @@ -0,0 +1,37 @@ +/* + * 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 + * Danny Smith + */ + +#include +#include /* _fmode */ +#include /* _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); +} + -- cgit v1.2.3