#! /bin/ksh

# ===== self-applying patch file =====
# Documentation and patch file are inline at bottom of script.

set -x

    unset _BPX_SHAREAS
    ANAME=apache_1.3.9
    ARCHIVE="$ANAME.tar.gz"
    PATCHFILE="`whence     $0`" ||
    PATCHFILE="`type -path $0`"

# The "-o to=$charmap" is needed to convert the ASCII archive
# to EBCDIC.  You must not download as a text file; the conversion
# must be performed after the uncompress.

    unset PAXOPT
    if eval "export `locale -ck charmap`"; then
        # "locale" is broken on OS/390 v1r2.  Circumvent.
        case "$charmap" in
          "") ;;
        \\x*) export charmap=IBM-1047
            PAXOPT="-o to=$charmap";;
        *) PAXOPT="-o to=$charmap";; esac;  fi

    # depending on mount options, may need to convert ARCHIVE
    #     from EBCDIC to ASCII, or even from ASCII to EBCDIC.
    # try several ways and hope one works.
    inflate() {
        gunzip <"$ARCHIVE" ||
        iconv -f "$charmap" -t ISO8859-1 "$ARCHIVE" | gunzip ||
	/pub/ccmdbs/NCS_20/bin/cl_iconv -t IBM-1047 "$ARCHIVE" |
            gunzip || exit $?;  }

    inflate | pax -rv $PAXOPT

    # Undo ASCII to EBCDIC conversion for binary files.
    inflate | pax -rv \
	    $ANAME/htdocs/apache_pb.gif \
	    $ANAME/htdocs/manual/images \
	    $ANAME/icons \

    # Copy EBCDIC support files into os/unix source directory.
    (   cd   $ANAME/src/os/unix
	( cd ../tpf    && tar -cf - ebcdic.* ) | tar -xvf -
    )

# "export UPDATE_APACHE=false" to generate unpatched reference tree. 
    ${UPDATE_APACHE} && (
	cd apache_1.3.9
	patch -l -p1 ) <"$PATCHFILE"
exit $?

========================================================================
This document suggests steps to install Apache on OS/390 systems.

========================================================================
o Download the archive file apache_1.3.9.tar.gz in BINARY from
	http://www.apache.org/dist/apache_1.3.9.tar.gz

o Unpack and update by running this file as a shell script.

========================================================================

o Configure with:

    /bin/time ./configure \
        --prefix=/pub/unsup/test/.arch/$MTYPES \
        --shadow &

o Build and test:
    (   gmake -k --jobs 5 &
	gmake install
	gmake install-programs
    )
    /pub/unsup/test/.arch/$MTYPES/bin/apachectl start

========================================================================

o Generate patch file with:

    mkdir orig
    cd orig
    ln -s ../$ARCHIVE .
    export UPDATE_APACHE=false
    # re-extract

    (	cd .. && diff -brc orig/apache_1.3.9 apache_1.3.9 ) |
    grep -v ^Only >apache.patch

========================================================================
diff -bru orig/apache_1.3.9/configure apache_1.3.9/configure
--- orig/apache_1.3.9/configure	Sat Aug 14 02:29:05 1999
+++ apache_1.3.9/configure	Tue Nov 23 07:47:09 1999
@@ -549,7 +549,7 @@
             #   Makefile is for platform bootstrapping, so don't hardcode paths)
             gnutriple=`$aux/GuessOS | sed -e 's:/:-:g' | awk '{ printf("%s",$1); }'`
             #   create Makefile wrapper (the first time only)
-            if [ "x`ls $top/src.* 2>/dev/null`" = "x" ]; then
+            if ls $top/src.* Makefile 2>/dev/null 1>&2; then :; else
                 if [ "x$quiet" = "xno" ]; then
                     echo " + creating Makefile (shadow wrapper)"
                 fi
@@ -562,9 +562,9 @@
                 else
                     echo "SHADOW=." >> Makefile
                 fi
-                echo "GNUTRIPLE=\`$aux/GuessOS | sed -e 's:/:-:g' | $AWK '{ printf(\"%s\",\$\$1); }'\`" >> Makefile
+                echo "GNUTRIPLE=\`$aux/GuessOS | sed -e 's:/:-:g' | awk '{ printf(\"%s\",\$\$1); }'\`" >> Makefile
                 echo "" >> Makefile
-                echo "all build install install-quiet clean distclean:" >> Makefile
+                echo "all build install install-quiet install-programs clean distclean:" >> Makefile
                 echo "	@cd \$(SHADOW); \$(MAKE) -f Makefile.\$(GNUTRIPLE) \$(MFLAGS) \$@" >> Makefile
                 echo "" >> Makefile
             fi
diff -bru orig/apache_1.3.9/src/Configure apache_1.3.9/src/Configure
--- orig/apache_1.3.9/src/Configure	Sun Aug 15 18:49:08 1999
+++ apache_1.3.9/src/Configure	Mon Nov 22 15:22:20 1999
@@ -616,6 +616,17 @@
        LIBS="$LIBS"
        SUBTARGET="target_compile_only"
        ;;
+    *-*-os390*)
+	OS='OS390'
+	OSDIR='os/unix'
+	CC="_C89_CCMODE=1 c89"
+	CFLAGS="$CFLAGS -DCHARSET_EBCDIC -DOS390"
+	CFLAGS="$CFLAGS -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE"
+	CFLAGS="$CFLAGS -DNO_DLOPEN"
+#####   CFLAGS="$CFLAGS -D_OE_SOCKETS"
+	DEF_WANTHSREGEX=yes
+	DBM_LIB=""
+       ;;
     BS2000*-siemens-sysv4*)
 	OS='BS2000'
 	OSDIR='os/bs2000'
@@ -848,7 +859,7 @@
 #
 # If $TCC is null, then no such line exists in Configuration
 #
-TCC=`egrep '^CC=' Makefile.config | tail -1 | awk -F= '{print $2}'`
+TCC=`egrep '^CC=' Makefile.config | tail -1 | sed -e 's!^[^=]*=!!'`
 if [ "x$TCC" = "x" ]; then
     if [ "x$CC" = "x" ]; then
 	# At this point, CC is not set in Configuration or above, so we
@@ -870,8 +881,6 @@
 	fi
 	CC=$COMPILER
     fi
-    echo " + setting C compiler to $CC"
-fi
 
 ####################################################################
 ## Write the value of $CC to Makefile.config... We only do this
@@ -879,7 +888,7 @@
 ## If there was an entry for it, then set $CC for our own internal
 ## use.
 ##
-if [ "x$TCC" = "x" ]; then
+    echo " + setting C compiler to $CC"
     echo "CC=$CC" >> Makefile.config
 else
     CC=$TCC
@@ -888,11 +897,11 @@
 ####################################################################
 ## Now check how we can _directly_ run the C pre-processor
 ##
-TCPP=`egrep '^CPP=' Makefile.config | tail -1 | awk -F= '{print $2}'`
+TCPP=`egrep '^CPP=' Makefile.config | tail -1 | sed -e 's!^[^=]*=!!'`
 if [ "x$TCPP" != "x" ]; then
-    CPP=`CC=$CC CPP=$TCPP ./helpers/findcpp.sh`
+    CPP=`CC="$CC" CPP="$TCPP" export CC CPP; ./helpers/findcpp.sh`
 else
-    CPP=`CC=$CC ./helpers/findcpp.sh`
+    CPP=`CC="$CC" export CC; ./helpers/findcpp.sh`
 fi
 if [ "x$TCPP" = "x" ]; then
     echo "CPP=$CPP" >> Makefile.config
diff -bru orig/apache_1.3.9/src/ap/ap_execve.c apache_1.3.9/src/ap/ap_execve.c
--- orig/apache_1.3.9/src/ap/ap_execve.c	Sun Mar  7 06:51:19 1999
+++ apache_1.3.9/src/ap/ap_execve.c	Thu Nov 25 00:30:05 1999
@@ -99,7 +99,7 @@
 #undef execle
 #undef execve
 
-static const char **hashbang(const char *filename, char **argv);
+static const char **hashbang(const char *filename, char * const *argv);
 
 
 /* Historically, a list of arguments on the stack was often treated as
@@ -133,7 +133,7 @@
 
     /* Pass two --- copy the argument strings into the result space */
     va_start(adummy, argv0);
-    argv[0] = argv0;
+    ((const char **)argv)[0] = argv0;
     for (argc = 1; (argv[argc] = va_arg(adummy, char *)) != NULL; ++argc) {
 	continue;
     }
@@ -149,7 +149,7 @@
 /* Count number of entries in vector "args", including the trailing NULL entry
  */
 static int
-count_args(const char **args)
+count_args(char * const *args)
 {
     int i;
     for (i = 0; args[i] != NULL; ++i) {
@@ -163,14 +163,14 @@
  * We have to fiddle with the argv array to make it work on platforms
  * which don't support the "hashbang" interpreter line by default.
  */
-int ap_execve(const char *filename, const char *argv[],
-	      const char *envp[])
+int ap_execve(const char *filename, char * const argv[],
+	      char * const envp[])
 {
     const char **script_argv;
     extern char **environ;
 
     if (envp == NULL) {
-	envp = (const char **) environ;
+	envp = (char * const *)environ;
     }
 
     /* Try to execute the file directly first: */
@@ -211,7 +211,7 @@
 		script_argv[0] = argv[0];
 	    }
 
-	    execve(filename, script_argv, envp);
+	    execve(filename, (char * const *)script_argv, envp);
 
 	    free(script_argv);
 	}
@@ -236,7 +236,7 @@
 		--i;
 	    }
 
-	    execve(SHELL_PATH, script_argv, envp);
+	    execve(SHELL_PATH, (char * const *)script_argv, envp);
 
 	    free(script_argv);
 	}
@@ -257,7 +257,7 @@
  */
 #define HACKBUFSZ 1024		/* Max chars in #! vector */
 #define HACKVECSZ 128		/* Max words in #! vector */
-static const char **hashbang(const char *filename, char **argv)
+static const char **hashbang(const char *filename, char * const *argv)
 {
     char lbuf[HACKBUFSZ];
     char *sargv[HACKVECSZ];
@@ -347,7 +347,7 @@
 	    }
 	    ++i;
 
-	    newargv = (char **) malloc((p - lbuf + 1)
+	    newargv = (const char **) malloc((p - lbuf + 1)
                       + (i + sargc + 1) * sizeof(*newargv));
 	    if (newargv == NULL) {
 		fprintf(stderr, "Ouch!  Out of memory in hashbang()!\n");
diff -bru orig/apache_1.3.9/src/helpers/GuessOS apache_1.3.9/src/helpers/GuessOS
--- orig/apache_1.3.9/src/helpers/GuessOS	Mon Aug  9 01:38:44 1999
+++ apache_1.3.9/src/helpers/GuessOS	Mon Nov 22 15:22:20 1999
@@ -154,6 +154,10 @@
 	echo "${MACHINE}-tandem-oss"; exit 0; 
 	;;
 
+    OS/390:*:*:*)
+	echo "i370-ibm-os390v${VERSION}r${RELEASE}";  exit 0
+	;;
+
     QNX:*)
 	if [ "$VERSION" -gt 422 ]; then
 	    echo "${MACHINE}-qssl-qnx32"
@@ -326,5 +330,5 @@
 # At this point we gone through all the one's
 # we know of: Punt
 
-echo "${MACHINE}-whatever-${SYSTEM}|${RELEASE}|${VERSION}" 
+echo "${MACHINE}-whatever-${SYSTEM}-${RELEASE}-${VERSION}" 
 exit 0
diff -bru orig/apache_1.3.9/src/include/ap.h apache_1.3.9/src/include/ap.h
--- orig/apache_1.3.9/src/include/ap.h	Thu Aug 12 12:06:20 1999
+++ apache_1.3.9/src/include/ap.h	Wed Nov 24 16:02:51 1999
@@ -68,7 +68,6 @@
 API_EXPORT(char *) ap_cpystrn(char *, const char *, size_t);
 int ap_slack(int, int);
 int ap_execle(const char *, const char *, ...);
-int ap_execve(const char *, const char *argv[], const char *envp[]);
 API_EXPORT(int) ap_getpass(const char *prompt, char *pwbuf, size_t bufsiz);
 
 /* small utility macros to make things easier to read */
diff -bru orig/apache_1.3.9/src/include/ap_config.h apache_1.3.9/src/include/ap_config.h
--- orig/apache_1.3.9/src/include/ap_config.h	Mon Aug  9 01:38:45 1999
+++ apache_1.3.9/src/include/ap_config.h	Wed Nov 24 18:26:12 1999
@@ -115,7 +115,8 @@
 #include "os.h"
 #endif
 
-#if !defined(QNX) && !defined(MPE) && !defined(WIN32) && !defined(TPF)
+#if !defined(QNX) && !defined(MPE) && !defined(WIN32) && !defined(TPF) \
+    && !defined(OS390)
 #include <sys/param.h>
 #endif
 
@@ -905,6 +906,10 @@
 
 /* All windows stuff is now in os/win32/os.h */
 
+#elif defined(OS390) /* IBM OS/390 Unix Services */
+#include <sys/time.h>
+#define NEED_HASHBANG_EMUL
+
 #elif defined(TPF) /* IBM Transaction Processing Facility operating system */
 
 #include <tpfeq.h>
@@ -1050,6 +1055,9 @@
 #include <netinet/in.h>
 #endif /* TPF */
 #include <netdb.h>
+#if defined(OS390) && !defined(NO_ADDRESS)
+#define NO_ADDRESS NO_DATA  /* Not defined properly by OS/390 v1r2 */
+#endif
 #include <sys/ioctl.h>
 #if !defined(MPE) && !defined(BEOS) && !defined(TPF)
 #include <arpa/inet.h>		/* for inet_ntoa */
@@ -1227,8 +1235,8 @@
  */
 #ifdef NEED_HASHBANG_EMUL
 extern int ap_execle(const char *filename, const char *arg,...);
-extern int ap_execve(const char *filename, const char *argv[],
-                     const char *envp[]);
+extern int ap_execve(const char *filename, char * const argv[],
+                     char * const envp[]);
 /* ap_execle() is a wrapper function around ap_execve(). */
 #define execle  ap_execle
 #define execve(path,argv,envp)  ap_execve(path,argv,envp)
diff -bru orig/apache_1.3.9/src/main/http_main.c apache_1.3.9/src/main/http_main.c
--- orig/apache_1.3.9/src/main/http_main.c	Tue Aug 10 07:54:48 1999
+++ apache_1.3.9/src/main/http_main.c	Mon Nov 22 23:29:14 1999
@@ -116,7 +116,7 @@
 #endif
 #ifdef WIN32
 #include "../os/win32/getopt.h"
-#elif !defined(BEOS) && !defined(TPF)
+#elif !defined(BEOS) && !defined(TPF) && !defined(OS390)
 #include <netinet/tcp.h>
 #endif
 
@@ -3817,7 +3817,7 @@
 	    usr1_just_die = 0;
 	    for (;;) {
 		clen = sizeof(sa_client);
-		csd = ap_accept(sd, &sa_client, &clen);
+		csd = ap_accept(sd, &sa_client, (unsigned int *)&clen);
 		if (csd >= 0 || errno != EINTR)
 		    break;
 		if (deferred_die) {
@@ -3967,7 +3967,7 @@
 	 */
 
 	clen = sizeof(sa_server);
-	if (getsockname(csd, &sa_server, &clen) < 0) {
+	if (getsockname(csd, &sa_server, (unsigned int *)&clen) < 0) {
 	    ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname");
 	    continue;
 	}
@@ -4690,6 +4690,11 @@
     int sock_out;
     char *s;
     
+#ifdef OS390
+    /* Dummy call to initialize translation tables. */
+    ebcdic2ascii(NULL, NULL, 0);
+#endif
+
 #ifdef SecureWare
     if (set_auth_parameters(argc, argv) < 0)
 	perror("set_auth_parameters");
@@ -4916,14 +4921,14 @@
 #endif
 
 	l = sizeof(sa_client);
-	if ((getpeername(sock_in, &sa_client, &l)) < 0) {
+	if ((getpeername(sock_in, &sa_client, (unsigned int *)&l)) < 0) {
 /* get peername will fail if the input isn't a socket */
 	    perror("getpeername");
 	    memset(&sa_client, '\0', sizeof(sa_client));
 	}
 
 	l = sizeof(sa_server);
-	if (getsockname(sock_in, &sa_server, &l) < 0) {
+	if (getsockname(sock_in, &sa_server, (unsigned int *)&l) < 0) {
 	    perror("getsockname");
 	    fprintf(stderr, "Error getting local address\n");
 	    exit(1);
diff -bru orig/apache_1.3.9/src/main/rfc1413.c apache_1.3.9/src/main/rfc1413.c
--- orig/apache_1.3.9/src/main/rfc1413.c	Fri Jul 30 08:06:56 1999
+++ apache_1.3.9/src/main/rfc1413.c	Mon Nov 22 15:22:22 1999
@@ -148,7 +148,7 @@
 
     /* send query to server. Handle short write. */
 #ifdef CHARSET_EBCDIC
-    ebcdic2ascii(&buffer, &buffer, buflen);
+    ebcdic2ascii(buffer, buffer, buflen);
 #endif
     i = 0;
     while(i < strlen(buffer)) {
@@ -191,7 +191,7 @@
 
 /* RFC1413_USERLEN = 512 */
 #ifdef CHARSET_EBCDIC
-    ascii2ebcdic(&buffer, &buffer, (size_t)i);
+    ascii2ebcdic(buffer, buffer, (size_t)i);
 #endif
     if (sscanf(buffer, "%u , %u : USERID :%*[^:]:%512s", &rmt_port, &our_port,
 	       user) != 3 || ntohs(rmt_sin->sin_port) != rmt_port
diff -bru orig/apache_1.3.9/src/main/util_script.c apache_1.3.9/src/main/util_script.c
--- orig/apache_1.3.9/src/main/util_script.c	Thu Aug 12 12:34:15 1999
+++ apache_1.3.9/src/main/util_script.c	Wed Nov 24 22:52:47 1999
@@ -155,6 +155,15 @@
     return res;
 }
 
+#ifdef   OS390
+/* ANSI C 4.10.4.4 states "The string pointed to ... may be modified
+ * by a subsequent call to getenv.  OS/390 does this.  Sigh.
+ */
+#define ap_getenv(p, s) (ap_pstrdup(p, getenv(s)))
+#else  /*OS390*/
+#define ap_getenv(p, s) getenv((s))
+#endif /*OS390*/
+
 API_EXPORT(char **) ap_create_environment(pool *p, table *t)
 {
     array_header *env_arr = ap_table_elts(t);
@@ -250,7 +259,7 @@
 	}
     }
 
-    if (!(env_path = getenv("PATH"))) {
+    if (!(env_path = ap_getenv(r->pool, "PATH"))) {
 	env_path = DEFAULT_PATH;
     }
 
diff -bru orig/apache_1.3.9/src/os/unix/Makefile.tmpl apache_1.3.9/src/os/unix/Makefile.tmpl
--- orig/apache_1.3.9/src/os/unix/Makefile.tmpl	Mon Sep  7 00:59:35 1998
+++ apache_1.3.9/src/os/unix/Makefile.tmpl	Mon Nov 22 16:05:58 1999
@@ -43,5 +43,6 @@
  $(INCDIR)/ap_mmn.h $(INCDIR)/ap_config_auto.h \
  $(OSDIR)/os.h $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h
 os.o: os.c $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \
+ os-aix-dso.c ebcdic.c \
  $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \
  $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h os.h
diff -bru orig/apache_1.3.9/src/os/unix/ebcdic.c apache_1.3.9/src/os/unix/ebcdic.c
--- orig/apache_1.3.9/src/os/unix/ebcdic.c	Fri Jan  1 12:05:29 1999
+++ apache_1.3.9/src/os/unix/ebcdic.c	Tue Nov 23 07:50:30 1999
@@ -57,8 +57,38 @@
 
 
 #ifdef CHARSET_EBCDIC
+#include "httpd.h"
+#include "http_core.h"
 #include "ap_config.h"
-#include "ebcdic.h"
+
+#ifdef   OS390
+static unsigned char os_toascii_strictly[256];
+unsigned char os_toascii[256];
+unsigned char os_toebcdic[256];
+static int Initted = 0;
+#define INITTAB { if (!Initted) InitTables(); }
+
+/* Use OS/390's built-in translation function to initialize tables.
+ */
+static void InitTables()
+{
+    register int i, j;
+
+    for (i = 0; i<256; i++) os_toebcdic[i] = i;
+
+    __atoe_l((char *) os_toebcdic, 256);
+    for (i = 0; i<256; i++) {
+        j = os_toebcdic[i];
+        os_toascii_strictly[j] = os_toascii[j] = i;
+    }
+    os_toascii[012] = 012;
+    os_toascii[015] = 015;
+        
+    Initted = 1;
+}
+
+#else  /*OS390*/
+#define INITTAB { }
 /*
 This code does basic character mapping for IBM's TPF operating system.
 It is a modified version of <Martin.Kraemer@Mch.SNI.De>'s code for
@@ -186,6 +216,7 @@
     0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, /* f0-ff:           */
     0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf  /* ................ */
 };
+#endif /*OS390*/
 
 /* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)
  * dest and srce may be identical, or separate memory blocks, but
@@ -196,6 +227,7 @@
 {
     unsigned char *udest = dest;
     const unsigned char *usrce = srce;
+    INITTAB;
     while (count-- != 0) {
         *udest++ = os_toascii[*usrce++];
     }
@@ -217,5 +249,42 @@
                 *udest++ = os_toebcdic[*usrce++];
     }
 }
-#endif /*CHARSET_EBCDIC*/
+#include "http_core.h"
  
+/* Check the Content-Type to decide if conversion is needed */
+int ap_checkconv(struct request_rec *r)
+{
+    int convert_to_ascii;
+    const char *type;
+
+    /* To make serving of "raw ASCII text" files easy (they serve faster 
+     * since they don't have to be converted from EBCDIC), a new
+     * "magic" type prefix was invented: text/x-ascii-{plain,html,...}
+     * If we detect one of these content types here, we simply correct
+     * the type to the real text/{plain,html,...} type. Otherwise, we
+     * set a flag that translation is required later on.
+     */
+ 
+    type = (r->content_type == NULL) ? ap_default_type(r) : r->content_type;
+
+    /* If no content type is set then treat it as (ebcdic) text/plain */
+    convert_to_ascii = (type == NULL);
+
+    /* Conversion is applied to text/ files only, if ever. */
+    if (type && (strncasecmp(type, "text/", 5) == 0 ||
+		 strncasecmp(type, "message/", 8) == 0)) {
+	if (strncasecmp(type, ASCIITEXT_MAGIC_TYPE_PREFIX,
+			sizeof(ASCIITEXT_MAGIC_TYPE_PREFIX)-1) == 0)
+	    r->content_type = ap_pstrcat(r->pool, "text/",
+					 type+sizeof(ASCIITEXT_MAGIC_TYPE_PREFIX)-1,
+					 NULL);
+        else
+	    /* translate EBCDIC to ASCII */
+	    convert_to_ascii = 1;
+    } 
+    /* Enable conversion if it's a text document */
+    ap_bsetflag(r->connection->client, B_EBCDIC2ASCII, convert_to_ascii);
+
+    return convert_to_ascii;
+} 
+#endif /*CHARSET_EBCDIC*/
diff -bru orig/apache_1.3.9/src/os/unix/ebcdic.h apache_1.3.9/src/os/unix/ebcdic.h
--- orig/apache_1.3.9/src/os/unix/ebcdic.h	Tue Nov  3 15:06:31 1998
+++ apache_1.3.9/src/os/unix/ebcdic.h	Mon Nov 22 23:17:28 1999
@@ -1,8 +1,17 @@
+#ifndef  APACHE_EBCDIC_H
+#define  APACHE_EBCDIC_H
 #include <sys/types.h>
 
+#ifdef OS390
+extern       unsigned char os_toascii[256];
+extern       unsigned char os_toebcdic[256];
+#else
 extern const unsigned char os_toascii[256];
 extern const unsigned char os_toebcdic[256];
+#endif
+
 void ebcdic2ascii(void *dest, const void *srce, size_t count);
 void ebcdic2ascii_strictly(unsigned char *dest, const unsigned char *srce, size_t count);
 void ascii2ebcdic(void *dest, const void *srce, size_t count);
 
+#endif /*APACHE_EBCDIC_H*/
diff -bru orig/apache_1.3.9/src/os/unix/os.c apache_1.3.9/src/os/unix/os.c
--- orig/apache_1.3.9/src/os/unix/os.c	Mon Aug  9 01:38:48 1999
+++ apache_1.3.9/src/os/unix/os.c	Mon Nov 22 15:22:23 1999
@@ -21,6 +21,13 @@
 #endif
 
 /*
+ * Insert the EBCDIC support code for OS/390
+ */
+#ifdef   CHARSET_EBCDIC
+#include "ebcdic.c"
+#endif /*CHARSET_EBCDIC*/
+
+/*
  *  Abstraction layer for loading
  *  Apache modules under run-time via 
  *  dynamic shared object (DSO) mechanism
@@ -113,8 +120,11 @@
     (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000))
     return dlopen((char *)path, RTLD_NOW | RTLD_GLOBAL);
 
-#else
+#elif !defined(NO_DLOPEN)
     return dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+
+#else
+    return NULL;
 #endif
 }
 
@@ -126,7 +136,7 @@
 #elif defined(HAVE_DYLD)
     NSUnLinkModule(handle,FALSE);
 
-#else
+#elif !defined(NO_DLOPEN)
     dlclose(handle);
 #endif
 
@@ -164,8 +174,11 @@
 #elif defined(SEQUENT)
     return dlsym(handle, (char *)symname);
 
-#else
+#elif !defined(NO_DLOPEN)
     return dlsym(handle, symname);
+
+#else
+    return NULL;
 #endif
 }
 
@@ -175,7 +188,9 @@
     return strerror(errno);
 #elif defined(HAVE_DYLD)
     return NULL;
-#else
+#elif !defined(NO_DLOPEN)
     return dlerror();
+#else
+    return strerror(errno);
 #endif
 }
diff -bru orig/apache_1.3.9/src/os/unix/os.h apache_1.3.9/src/os/unix/os.h
--- orig/apache_1.3.9/src/os/unix/os.h	Mon May  3 20:57:14 1999
+++ apache_1.3.9/src/os/unix/os.h	Mon Nov 22 15:22:23 1999
@@ -144,4 +144,17 @@
 void *      ap_os_dso_sym(void *, const char *);
 const char *ap_os_dso_error(void);
 
+#ifdef   CHARSET_EBCDIC
+
+/* Sorry if this is ugly, but the include order doesn't allow me
+ * to use request_rec here... */
+struct request_rec;
+extern int ap_checkconv(struct request_rec *r);
+
+#ifndef  APACHE_EBCDIC_H
+#include "ebcdic.h"
+#endif /*APACHE_EBCDIC_H*/
+
+#endif /*CHARSET_EBCDIC*/
+
 #endif	/* !APACHE_OS_H */
diff -bru orig/apache_1.3.9/src/support/htdigest.c apache_1.3.9/src/support/htdigest.c
--- orig/apache_1.3.9/src/support/htdigest.c	Mon Aug  2 04:45:36 1999
+++ apache_1.3.9/src/support/htdigest.c	Mon Nov 22 15:22:23 1999
@@ -72,7 +72,7 @@
 #include "ap_md5.h"
 #if defined(MPE) || defined(QNX) || defined(WIN32) || defined(__TANDEM)
 #include <signal.h>
-#else
+#elif !defined(OS390)
 #include <sys/signal.h>
 #endif
 
