summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-03-02 05:45:45 +0000
committerJim Meyering <jim@meyering.net>1996-03-02 05:45:45 +0000
commit815b5ca1d577ad6b9f07d50219c1870d24930545 (patch)
tree549a8e58231efcbd6a92ce87bb2ed8614fc15ecf /src
parent76118226b60d4c3d90c88bf3cadf95778441c759 (diff)
downloadcoreutils-815b5ca1d577ad6b9f07d50219c1870d24930545.tar.xz
(WINDOWS_SETFILEMODE_BINARY): New macro.
(skip) [_WIN32 && _O_BINARY]: Use it. (read_char): Likewise. (read_block): Likewise. Based on changes by Gary Newman <gnewman@shore.net>.
Diffstat (limited to 'src')
-rw-r--r--src/od.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/od.c b/src/od.c
index deea3671b..c54e253a6 100644
--- a/src/od.c
+++ b/src/od.c
@@ -29,7 +29,12 @@
#ifdef _AIX
#pragma alloca
#else /* not _AIX */
+#ifdef _WIN32
+#include <malloc.h>
+#include <io.h>
+#else
char *alloca ();
+#endif /* not _WIN32 */
#endif /* not _AIX */
#endif /* not HAVE_ALLOCA_H */
#endif /* not __GNUC__ */
@@ -87,6 +92,22 @@ typedef double LONG_DOUBLE;
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
+#if defined (_WIN32) && defined (_O_BINARY)
+# define WINDOWS_SETFILEMODE_BINARY(IN_STREAM, FILENAME) \
+ do \
+ { /* Turn off DOS text file modes, "rb" doesn't work on stdin. */\
+ if (_setmode (_fileno ((IN_STREAM)), _O_BINARY) == -1) \
+ { \
+ error (0, errno, "%s", (FILENAME)); \
+ err = 1; \
+ continue; \
+ } \
+ } \
+ while (0)
+#else
+# define WINDOWS_SETFILEMODE_BINARY(IN_STREAM, FILENAME) /* empty */
+#endif
+
/* The default number of input bytes per output line. */
#define DEFAULT_BYTES_PER_BLOCK 16
@@ -941,6 +962,7 @@ skip (off_t n_skip)
continue;
}
}
+ WINDOWS_SETFILEMODE_BINARY (in_stream, input_filename);
if (n_skip == 0)
break;
@@ -1189,6 +1211,7 @@ read_char (int *c)
err = 1;
}
}
+ WINDOWS_SETFILEMODE_BINARY (in_stream, input_filename);
}
while (in_stream == NULL);
}
@@ -1261,6 +1284,7 @@ read_block (size_t n, char *block, size_t *n_bytes_in_buffer)
err = 1;
}
}
+ WINDOWS_SETFILEMODE_BINARY (in_stream, input_filename);
}
while (in_stream == NULL);
}