ref: 35b98e0f4f5d021690beb4f274e637e327063e62
parent: 6918be14d1e6822a592ec4ad12dccb4c98388d60
author: cbagwell <cbagwell>
date: Mon Feb 20 22:06:54 EST 2006
Under windows, make piped inputs use binary mode.
--- a/src/stio.c
+++ b/src/stio.c
@@ -23,6 +23,15 @@
#define fstat _fstat
#endif
+/* Based from zlib's minigzip: */
+#if defined(WIN32) || defined(__NT__)
+# include <fcntl.h>
+# include <io.h>
+# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+# define SET_BINARY_MODE(file)
+#endif
+
static int is_seekable(ft_t ft)
{
struct stat st;
@@ -115,7 +124,10 @@
* if the filename is "-"
*/
if (!strcmp(ft->filename, "-"))
+ {
+ SET_BINARY_MODE(stdin);
ft->fp = stdin;
+ }
else if ((ft->fp = fopen(ft->filename, "rb")) == NULL)
{
st_warn("Can't open input file '%s': %s", ft->filename,
@@ -189,7 +201,10 @@
len = strlen(ft->filename);
- /* Use filename extension to determine audio type. */
+ /* Use filename extension to determine audio type.
+ * Search for the last '.' appearing in the filename, same
+ * as for input files.
+ */
chop = ft->filename + len;
while (chop > ft->filename && *chop != LASTCHAR && *chop != '.')
chop--;
@@ -226,7 +241,7 @@
if (!(ft->h->flags & ST_FILE_NOSTDIO))
{
- /* Open file handler based on input name. Used stdin file handler
+ /* Open file handler based on output name. Used stdout file handler
* if the filename is "-"
*/
if (!strcmp(ft->filename, "-"))