diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:38:33 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:38:33 +0300 |
commit | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch) | |
tree | dc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/mingw/samples/fmode/all.c | |
parent | 369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff) |
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/mingw/samples/fmode/all.c')
-rw-r--r-- | winsup/mingw/samples/fmode/all.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/winsup/mingw/samples/fmode/all.c b/winsup/mingw/samples/fmode/all.c new file mode 100644 index 000000000..52f93d1c1 --- /dev/null +++ b/winsup/mingw/samples/fmode/all.c @@ -0,0 +1,46 @@ +/*
+ * A sample program demonstrating how to use _CRT_fmode to change the default
+ * file opening mode to binary AND change stdin, stdout and stderr. Redirect
+ * stdout to a file from the command line to see the difference.
+ *
+ * Also try directing a file into stdin. If you type into stdin you will get
+ * \r\n at the end of every line... unlike UNIX. But at least if you
+ * redirect a file in you will get exactly the characters in the file as input.
+ *
+ * THIS CODE IS IN THE PUBLIC DOMAIN.
+ *
+ * Colin Peters <colin@fu.is.saga-u.ac.jp>
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+
+unsigned int _CRT_fmode = _O_BINARY;
+
+main ()
+{
+ char* sz = "This is line one.\nThis is line two.\n";
+ FILE* fp;
+ int c;
+
+ printf (sz);
+
+ /* Note how this fopen does NOT indicate "wb" to open the file in
+ * binary mode. */
+ fp = fopen ("all.out", "w");
+
+ fprintf (fp, sz);
+
+ fclose (fp);
+
+ if (_isatty (_fileno(stdin)))
+ {
+ fprintf (stderr, "Waiting for input, press Ctrl-Z to finish.\n");
+ }
+
+ while ((c = fgetc(stdin)) != EOF)
+ {
+ printf ("\'%c\' %02X\n", (char) c, c);
+ }
+}
+
|