This allows extensions to switch fh to binary mode.

Enjoy,
Ilya

--- ./util.c.a	Fri Dec  5 01:56:48 1997
+++ ./util.c	Mon Dec 15 02:30:58 1997
@@ -1853,6 +1853,46 @@ VTOH(vtohs,short)
 VTOH(vtohl,long)
 #endif
 
+int
+do_binmode(PerlIO *fp, int iotype, int flag)
+{
+    if (flag != TRUE)
+	croak("panic: unsetting binmode"); /* Not implemented yet */
+#ifdef DOSISH
+#ifdef atarist
+    if (!PerlIO_flush(fp) && (fp->_flag |= _IOBIN))
+	return 1;
+    else
+	return 0;
+#else
+    if (setmode(PerlIO_fileno(fp), OP_BINARY) != -1) {
+#if defined(WIN32) && defined(__BORLANDC__)
+	/* The translation mode of the stream is maintained independent
+	 * of the translation mode of the fd in the Borland RTL (heavy
+	 * digging through their runtime sources reveal).  User has to
+	 * set the mode explicitly for the stream (though they don't
+	 * document this anywhere). GSAR 97-5-24
+	 */
+	PerlIO_seek(fp,0L,0);
+	fp->flags |= _F_BIN;
+#endif
+	return 1;
+    }
+    else
+	return 0;
+#endif
+#else
+#if defined(USEMYBINMODE)
+    if (my_binmode(fp,iotype) != NULL)
+	return 1;
+    else
+	return 0;
+#else
+    return 1;
+#endif
+#endif
+}
+
     /* VMS' my_popen() is in VMS.c, same with OS/2. */
 #if (!defined(DOSISH) || defined(HAS_FORK) || defined(AMIGAOS)) && !defined(VMS)
 PerlIO *
--- ./proto.h~	Tue Nov 25 04:46:58 1997
+++ ./proto.h	Mon Dec 15 02:25:38 1997
@@ -86,6 +86,7 @@ OP*	die _((const char* pat,...));
 OP*	die_where _((char* message));
 void	dounwind _((I32 cxix));
 bool	do_aexec _((SV* really, SV** mark, SV** sp));
+int	do_binmode _((PerlIO *fp, int iotype, int flag));
 void    do_chop _((SV* asv, SV* sv));
 bool	do_close _((GV* gv, bool not_implicit));
 bool	do_eof _((GV* gv));
--- ./global.sym~	Tue Nov 25 06:50:12 1997
+++ ./global.sym	Mon Dec 15 02:25:58 1997
@@ -52,6 +52,7 @@ dec_amg
 di
 div_amg
 div_ass_amg
+do_binmode
 do_undump
 ds
 egid
--- ./pod/perlguts.pod~	Thu Dec  4 01:00:18 1997
+++ ./pod/perlguts.pod	Mon Dec 15 02:32:40 1997
@@ -1568,6 +1568,13 @@ to indicate the number of items on the s
 Sets up the C<ix> variable for an XSUB which has aliases.  This is usually
 handled automatically by C<xsubpp>.
 
+=item do_binmode
+
+Switches filehandle to binmode.  C<iotype> is what C<IoTYPE(io)> would
+contain.
+
+	do_binmode(fp, iotype, TRUE);
+
 =item ENTER
 
 Opening bracket on a callback.  See C<LEAVE> and L<perlcall>.
--- ./pp_sys.c~	Tue Nov 25 06:55:14 1997
+++ ./pp_sys.c	Mon Dec 15 02:27:52 1997
@@ -469,40 +469,10 @@ PP(pp_binmode)
     if (!(io = GvIO(gv)) || !(fp = IoIFP(io)))
 	RETPUSHUNDEF;
 
-#ifdef DOSISH
-#ifdef atarist
-    if (!PerlIO_flush(fp) && (fp->_flag |= _IOBIN))
+    if (do_binmode(fp,IoTYPE(io),TRUE)) 
 	RETPUSHYES;
     else
-	RETPUSHUNDEF;
-#else
-    if (setmode(PerlIO_fileno(fp), OP_BINARY) != -1) {
-#if defined(WIN32) && defined(__BORLANDC__)
-	/* The translation mode of the stream is maintained independent
-	 * of the translation mode of the fd in the Borland RTL (heavy
-	 * digging through their runtime sources reveal).  User has to
-	 * set the mode explicitly for the stream (though they don't
-	 * document this anywhere). GSAR 97-5-24
-	 */
-	PerlIO_seek(fp,0L,0);
-	fp->flags |= _F_BIN;
-#endif
-	RETPUSHYES;
-    }
-    else
-	RETPUSHUNDEF;
-#endif
-#else
-#if defined(USEMYBINMODE)
-    if (my_binmode(fp,IoTYPE(io)) != NULL)
-	RETPUSHYES;
-	else
-	RETPUSHUNDEF;
-#else
-    RETPUSHYES;
-#endif
-#endif
-
+	RETPUSHUNDEF;	
 }
 
 
