--- subversion/libsvn_subr/orig.cmdline.c	Sat Sep 23 15:32:05 2006
+++ subversion/libsvn_subr/cmdline.c	Sat Sep 23 15:34:20 2006
@@ -17,6 +17,15 @@
  */
 
 
+#ifdef __MVS__
+#define _OPEN_SYS_FILE_EXT 1
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#endif /* __MVS__ */
+
 #include <stdlib.h>             /* for atexit() */
 #include <locale.h>             /* for setlocale() */
 
@@ -50,6 +59,37 @@
 /* The stdout encoding. If null, it's the same as the native encoding. */
 static const char *output_encoding = NULL;
 
+#ifdef __MVS__
+int autocvt_ensure_ascii(FILE *fp)
+{
+  int fd = fileno(fp);
+
+  struct f_cnvrt    fc;
+  int               res;
+
+  memset(&fc, 0, sizeof(fc));
+  fc.cvtcmd = QUERYCVT;
+  if (fcntl(fd, F_CONTROL_CVT, &fc) == -1){
+    fprintf(stderr, "Could not query extended file attributes for fd %d: %s\n",
+            fd, strerror(errno));
+    return -1;
+  }
+  if (fc.pccsid == 819 &&  fc.fccsid == 1047 && fc.cvtcmd == SETCVTON)
+    return 0;
+
+  fc.pccsid = 819;  /* ascii */
+  fc.fccsid = 1047; /* ebcdic */
+  fc.cvtcmd = SETCVTON;
+  if (fcntl(fd, F_CONTROL_CVT, &fc) == -1) {
+    fprintf(stderr, "Could not set extended file attributes for fd %d: %s\n",
+	    fd, strerror(errno));
+    return -1;
+  }
+
+  return 1;
+}
+#endif /* __MVS__ */
+
 
 int
 svn_cmdline_init(const char *progname, FILE *error_stream)
@@ -271,6 +311,10 @@
   svn_error_t *err;
   const char *out;
 
+#ifdef __MVS__
+  autocvt_ensure_ascii(stream);
+#endif /* __MVS__ */
+
   err = svn_cmdline_cstring_from_utf8(&out, string, pool);
 
   if (err)
@@ -284,6 +328,7 @@
      use it if it was set by the below fputs call.  Else, we just return
      a generic error. */
   errno = 0;
+
 
   if (fputs(out, stream) == EOF)
     {


