This commit was manufactured by cvs2svn to create tag
'APACHE_2_0_40'.

git-svn-id: https://svn.apache.org/repos/asf/apr/apr-iconv/tags/APACHE_2_0_40@57646 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 0000000..b0eab7a
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1,14 @@
+apriconv.vcproj
+libapriconv.vcproj
+config.cache
+config.log
+config.nice
+config.status
+configure
+libtool
+shlibtool
+Debug
+Release
+LibD
+LibR
+*.plg
diff --git a/CHANGES b/CHANGES
new file mode 100644
index 0000000..7f8f068
--- /dev/null
+++ b/CHANGES
@@ -0,0 +1,16 @@
+Changes with APR-ICONV a15
+
+  *) A second pass at a working build system - now builds on linux,
+     some namespace protection added.
+     [jean-frederic clere <jfrederic.clere@fujitsu-siemens.com>]
+
+  *) A first blush at a working build system.
+     [jean-frederic clere <jfrederic.clere@fujitsu-siemens.com>]
+
+  *) First set of changes for APR compatibility (eliminated __inline).
+     [jean-frederic clere <jfrederic.clere@fujitsu-siemens.com>]
+
+Changes with APR-ICONV a9
+
+  *) Source moved from the apr library into it's own repository
+     due to size concerns.  Still requires portability overhaul.
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 6907d93..e2cc986 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,3 @@
-SUBDIR=	ccs ces
+SUBDIR= lib ccs ces util
 
 .include <bsd.subdir.mk>
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..0d3c273
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,78 @@
+#
+# Top-level Makefile for APRICONV
+#
+TARGET_LIB = lib/libapriconv.la
+TARGET_EXPORTS = lib/apriconv.exports
+
+TARGETS = delete-lib $(TARGET_LIB) delete-exports $(TARGET_EXPORTS)
+
+# bring in rules.mk for standard functionality
+@INCLUDE_RULES@
+
+SUBDIRS = lib ccs ces util
+CLEAN_SUBDIRS = . lib ccs ces util
+
+CLEAN_TARGETS = $(TARGET_EXPORTS)
+DISTCLEAN_TARGETS = config.cache config.log config.status \
+	export_vars.sh
+EXTRACLEAN_TARGETS = configure libtool aclocal.m4
+
+### install location
+prefix=@prefix@
+exec_prefix=@prefix@/bin
+lib_prefix=@prefix@/lib
+libdir=@iconv_libdir@
+includedir=@includedir@
+
+
+delete-lib:
+	@if test -f $(TARGET_LIB); then \
+	    objects="`find $(SUBDIRS) -name '*.lo' -a -newer $(TARGET_LIB)`" ; \
+	    if test -n "$$objects"; then \
+		echo Found newer objects. Will relink $(TARGET_LIB). ; \
+		echo $(RM) -f $(TARGET_LIB) ; \
+		$(RM) -f $(TARGET_LIB) ; \
+	    fi \
+	fi
+
+install: $(TARGET_LIB)
+	if [ ! -d $(includedir) ]; then \
+	    @APR_SOURCE_DIR@/build/mkdir.sh $(includedir); \
+	fi; \
+	cp lib/*.h $(includedir); \
+	if [ ! -d $(lib_prefix) ]; then \
+	    @APR_SOURCE_DIR@/build/mkdir.sh $(lib_prefix); \
+	fi; \
+	$(LIBTOOL) --mode=install cp $(TARGET_LIB) $(lib_prefix)
+	if [ ! -d $(libdir) ]; then \
+	    @APR_SOURCE_DIR@/build/mkdir.sh $(libdir); \
+	fi; \
+	(cd ccs; $(LIBTOOL) --mode=install cp *.la $(libdir))
+	(cd ces; $(LIBTOOL) --mode=install cp *.la $(libdir))
+	if [ ! -d $(exec_prefix) ]; then \
+	    @APR_SOURCE_DIR@/build/mkdir.sh $(exec_prefix); \
+	fi; \
+	(cd util/.libs; $(LIBTOOL) --mode=install cp iconv $(exec_prefix))
+
+$(TARGET_LIB):
+	(cd lib; make)
+
+delete-exports:
+	@if test -f $(TARGET_EXPORTS); then \
+	    headers="`find lib/*.h -newer $(TARGET_EXPORTS)`" ; \
+	    if test -n "$$headers"; then \
+		echo Found newer headers. Will rebuild $(TARGET_EXPORTS). ; \
+		echo $(RM) -f $(TARGET_EXPORTS) ; \
+		$(RM) -f $(TARGET_EXPORTS) ; \
+	    fi \
+	fi
+
+$(TARGET_EXPORTS):
+	$(AWK) -f @APR_SOURCE_DIR@/build/make_export.awk lib/*.h > $@ ;
+
+docs:
+	mkdir ./docs
+	perl @APR_SOURCE_DIR@/build/scandoc.pl -i./build/default.pl -p./docs/ ./lib/*.h
+
+
+.PHONY: delete-lib delete-exports
diff --git a/Makefile.new b/Makefile.new
new file mode 100644
index 0000000..6907d93
--- /dev/null
+++ b/Makefile.new
@@ -0,0 +1,3 @@
+SUBDIR=	ccs ces
+
+.include <bsd.subdir.mk>
diff --git a/STATUS b/STATUS
new file mode 100644
index 0000000..7430e39
--- /dev/null
+++ b/STATUS
@@ -0,0 +1,31 @@
+APR-ICONV LIBRARY STATUS:
+Last modified at [$Date: 2000/12/10 18:34:56 $]
+
+Release:
+
+RELEASE SHOWSTOPPERS:
+
+    * Determine the package's relationship to apr/i18n/unix
+      and integrate into the apr build.
+
+RELEASE NON-SHOWSTOPPERS BUT WOULD BE REAL NICE TO WRAP THESE UP:
+
+    * Drop modules.c code and replace much functionality with the
+      apr dso methods, etc.
+
+Other bugs that need fixing:
+
+
+Other features that need writing:
+
+
+Documentation that needs writing:
+
+    * API documentation
+        Status:
+
+
+Available Patches:
+
+
+Open Issues:
diff --git a/apriconv.dsp b/apriconv.dsp
new file mode 100644
index 0000000..2a4d97e
--- /dev/null
+++ b/apriconv.dsp
@@ -0,0 +1,129 @@
+# Microsoft Developer Studio Project File - Name="apriconv" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=apriconv - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "apriconv.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "apriconv.mak" CFG="apriconv - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "apriconv - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "apriconv - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "apriconv - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "LibR"
+# PROP BASE Intermediate_Dir "LibR"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "LibR"
+# PROP Intermediate_Dir "LibR"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MD /W3 /O2 /I "../apr/include" /D "NDEBUG" /D "APR_DECLARE_STATIC" /D "API_DECLARE_STATIC" /D "WIN32" /D "_WINDOWS" /Fd"LibR\apriconv" /FD /c
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF  "$(CFG)" == "apriconv - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "LibD"
+# PROP BASE Intermediate_Dir "LibD"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "LibD"
+# PROP Intermediate_Dir "LibD"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /Zi /Od /I "../apr/include" /D "_DEBUG" /D "APR_DECLARE_STATIC" /D "API_DECLARE_STATIC" /D "WIN32" /D "_WINDOWS" /Fd"LibD\apriconv" /FD /c
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF 
+
+# Begin Target
+
+# Name "apriconv - Win32 Release"
+# Name "apriconv - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter ".c"
+# Begin Group "lib"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\lib\iconv.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_ces.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_ces_euc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_ces_iso2022.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_int.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_module.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_uc.c
+# End Source File
+# End Group
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter ".h"
+# Begin Source File
+
+SOURCE=.\lib\iconv.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/build/.cvsignore b/build/.cvsignore
new file mode 100644
index 0000000..29d51bb
--- /dev/null
+++ b/build/.cvsignore
@@ -0,0 +1 @@
+rules.mk
diff --git a/build/apr-iconv.m4 b/build/apr-iconv.m4
new file mode 100644
index 0000000..60af3ba
--- /dev/null
+++ b/build/apr-iconv.m4
@@ -0,0 +1,43 @@
+
+dnl
+dnl custom autoconf rules for APRICONV
+dnl
+
+dnl
+dnl APU_FIND_APR: figure out where APR is located
+dnl that a copy from apr-util...
+dnl
+AC_DEFUN(APU_FIND_APR,[
+
+AC_MSG_CHECKING(for APR)
+AC_ARG_WITH(apr,
+[  --with-apr=DIR          path to APR source or the APR includes],
+[
+    if test "$withval" = "yes"; then
+        AC_MSG_ERROR(You need to specify a directory with --with-apr)
+    fi
+    absdir="`cd $withval ; pwd`"
+    if test -f "$absdir/apr_pools.h"; then
+	APR_INCLUDES="$absdir"
+    elif test -f "$absdir/include/apr_pools.h"; then
+	APR_SOURCE_DIR="$absdir"
+    fi
+],[
+    dnl see if we can find APR
+    if test -f "$srcdir/apr/include/apr_pools.h"; then
+	APR_SOURCE_DIR="$srcdir/apr"
+    elif test -f "$srcdir/../apr/include/apr_pools.h"; then
+	APR_SOURCE_DIR="`cd $srcdir/../apr ; pwd`"
+    fi
+])
+if test -n "$APR_SOURCE_DIR"; then
+    APR_INCLUDES="$APR_SOURCE_DIR/include"
+fi
+if test -z "$APR_INCLUDES"; then
+    AC_MSG_RESULT(not found)
+    AC_MSG_ERROR(APR could not be located. Please use the --with-apr option.)
+fi
+AC_MSG_RESULT($APR_INCLUDES)
+
+AC_SUBST(APR_SOURCE_DIR)
+])
diff --git a/build/rules.mk.in b/build/rules.mk.in
new file mode 100644
index 0000000..02f36e8
--- /dev/null
+++ b/build/rules.mk.in
@@ -0,0 +1,175 @@
+# ====================================================================
+# The Apache Software License, Version 1.1
+#
+# Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
+# reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+#
+# 3. The end-user documentation included with the redistribution,
+#    if any, must include the following acknowledgment:
+#       "This product includes software developed by the
+#        Apache Software Foundation (http://www.apache.org/)."
+#    Alternately, this acknowledgment may appear in the software itself,
+#    if and wherever such third-party acknowledgments normally appear.
+#
+# 4. The names "Apache" and "Apache Software Foundation" must
+#    not be used to endorse or promote products derived from this
+#    software without prior written permission. For written
+#    permission, please contact apache@apache.org.
+#
+# 5. Products derived from this software may not be called "Apache",
+#    nor may "Apache" appear in their name, without prior written
+#    permission of the Apache Software Foundation.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+# ====================================================================
+#
+# This software consists of voluntary contributions made by many
+# individuals on behalf of the Apache Software Foundation.  For more
+# information on the Apache Software Foundation, please see
+# <http://www.apache.org/>.
+#
+
+#
+# rules.mk: standard rules for APRICONV
+#
+
+#
+# Configuration variables
+#
+top_builddir=@top_builddir@
+APR_SOURCE_DIR=@APR_SOURCE_DIR@
+
+CC=@CC@
+AWK=@AWK@
+LIBTOOL=@LIBTOOL@
+
+CFLAGS=@CFLAGS@
+LIBS=@LIBS@
+LDFLAGS=@LDFLAGS@
+
+RM=@RM@
+SHELL=@SHELL@
+
+### make LTFLAGS somewhat variable?
+LTFLAGS = --silent
+
+#
+# Basic macro setup
+#
+COMPILE      = $(CC) $(CFLAGS)
+LT_COMPILE   = $(LIBTOOL) --mode=compile $(LTFLAGS) $(COMPILE) -c $< && touch $@
+
+LINK         = $(LIBTOOL) --mode=link $(LTFLAGS) $(COMPILE) $(LDFLAGS) -o $@
+
+SH_LIBTOOL = $(SHELL) $(top_builddir)/shlibtool --silent
+SH_COMPILE = $(SH_LIBTOOL) --mode=compile $(COMPILE) -c $< && touch $@
+SH_LINK  = $(SH_LIBTOOL) --mode=link $(COMPILE) $(LTFLAGS) $(LDFLAGS) $(NOTEST_LDFLAGS) -o $@
+# To be arranged...
+libexecdir = /usr/local/lib
+
+MKEXPORT     = $(AWK) -f $(APR_SOURCE_DIR)/build/make_export.awk
+SCANDOC      = $(APR_SOURCE_DIR)/build/scandoc.pl
+
+#
+# Standard build rules
+#
+all: all-recursive
+depend: depend-recursive
+clean: clean-recursive
+distclean: distclean-recursive
+extraclean: extraclean-recursive
+
+install: all-recursive
+
+
+all-recursive depend-recursive clean-recursive distclean-recursive \
+  extraclean-recursive:
+	@otarget=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; \
+	ttarget=`echo $otarget | sed s/.*clean.*/clean/`; \
+	if test x"$ttarget" = "xclean"; then \
+	    list='$(SUBDIRS) $(CLEAN_SUBDIRS)'; \
+	fi; \
+	for i in $$list; do \
+	    if test -d "$$i"; then \
+		target="$$otarget"; \
+		echo "Making $$target in $$i"; \
+		if test "$$i" = "."; then \
+		    made_local=yes; \
+		    target="local-$$target"; \
+		fi; \
+		(cd $$i && $(MAKE) $$target) || exit 1; \
+	    fi; \
+	done; \
+        if test "$$otarget" = "all" && test -z "$(TARGETS)"; then \
+	    made_local=n/a; \
+	fi; \
+	if test -z "$$made_local"; then \
+	    $(MAKE) "local-$$otarget" || exit 1; \
+	fi
+
+local-clean:
+	$(RM) -f *.o *.lo *.a *.la *.so *.slo $(CLEAN_TARGETS) $(PROGRAMS)
+	$(RM) -rf .libs
+
+local-distclean: local-clean
+	$(RM) -f Makefile $(DISTCLEAN_TARGETS)
+
+local-extraclean: local-distclean
+	@if test -n "$(EXTRACLEAN_TARGETS)"; then \
+	    echo $(RM) -f $(EXTRACLEAN_TARGETS) ; \
+	    $(RM) -f $(EXTRACLEAN_TARGETS) ; \
+	fi
+
+local-all: $(TARGETS)
+
+local-depend:
+### need something here
+
+
+#
+# Implicit rules for creating outputs from input files
+#
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .la .slo
+
+.c.o:
+	$(COMPILE) -c $<
+
+.c.lo:
+	$(LT_COMPILE)
+
+.c.slo:
+	$(SH_COMPILE)
+
+.c.la:
+	$(MAKE) $*.slo
+	$(SH_LINK) -rpath $(libexecdir) -module -avoid-version  $*.lo
+
+.PHONY: all depend clean distclean extraclean install \
+	all-recursive depend-recursive clean-recursive distclean-recursive \
+	extraclean-recursive
+	local-all local-depend local-clean local-distclean local-extraclean
diff --git a/buildconf.sh b/buildconf.sh
new file mode 100644
index 0000000..f646fef
--- /dev/null
+++ b/buildconf.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+#
+# Build aclocal.m4 from libtool's libtool.m4 and our own M4 files.
+#
+### we may need to get smarter with these two lines (e.g. PrintPath)
+ltpath=`../apr/build/PrintPath libtoolize`
+ltpath=`dirname $ltpath`
+ltfile=`cd $ltpath/../share/aclocal ; pwd`/libtool.m4
+echo "Incorporating $ltfile into aclocal.m4 ..."
+echo "dnl THIS FILE IS AUTOMATICALLY GENERATED BY buildconf.sh" > aclocal.m4
+echo "dnl edits here will be lost" >> aclocal.m4
+cat build/apr-iconv.m4 >> aclocal.m4
+cat $ltfile >> aclocal.m4
+
+#
+# Create the libtool helper files
+#
+# Note: we always replace the files, and we copy (rather than link) them.
+#
+echo "Copying libtool helper files ..."
+$ltpath/libtoolize --force --copy
+
+#
+# Generate the autoconf header (include/apu_config.h) and ./configure
+#
+echo "Creating include/private/apu_config.h ..."
+autoheader
+
+echo "Creating configure ..."
+### do some work to toss config.cache?
+autoconf
diff --git a/ccs/.cvsignore b/ccs/.cvsignore
new file mode 100644
index 0000000..2cbb2f1
--- /dev/null
+++ b/ccs/.cvsignore
@@ -0,0 +1,4 @@
+.libs
+*.la
+*.lo
+*.slo
diff --git a/ccs/Makefile b/ccs/Makefile
index 8c07c3e..6cb07d9 100644
--- a/ccs/Makefile
+++ b/ccs/Makefile
@@ -1,18 +1,76 @@
-MODULES = iso-8859-3.so iso-8859-6.so iso-8859-7.so iso-8859-8.so \
-          iso-8859-9.so iso-8859-10.so iso-8859-13.so iso-8859-14.so \
-	  koi8-ru.so gb12345.so johab.so \
-          adobe-stdenc.so adobe-symbol.so adobe-zdingbats.so \
-          mac-ce.so mac-croatian.so mac-cyrillic.so mac-dingbats.so \
-          mac-greek.so mac-iceland.so mac-japan.so mac-roman.so \
-          mac-romania.so mac-thai.so mac-turkish.so mac-ukraine.so \
-          cp424.so cp500.so cp856.so cp1006.so \
-          cp437.so cp737.so cp857.so cp860.so cp861.so cp862.so cp863.so \
-          cp864.so cp865.so cp869.so cp874.so \
-          cp932.so cp936.so cp949.so cp950.so \
-          windows-1250.so windows-1251.so windows-1252.so \
-          windows-1253.so windows-1254.so windows-1255.so \
-          windows-1256.so windows-1257.so windows-1258.so \
-          cp037.so cp875.so cp1026.so \
-          cp10000.so cp10006.so cp10007.so cp10029.so cp10079.so cp10081.so
-
 .include "../Makefile.inc"
+
+CHARSETS_ISO8859 = iso-8859-1.so iso-8859-2.so iso-8859-4.so iso-8859-5.so \
+                   iso-8859-15.so
+CHARSETS_PC =      cp775.so cp850.so cp852.so cp855.so cp866.so
+CHARSETS_KOI =     koi8-r.so koi8-u.so
+CHARSETS_SB =      $(CHARSETS_ISO8859) $(CHARSETS_PC) $(CHARSETS_CJK) \
+                   $(CHARSETS_KOI) us-ascii.so
+CHARSETS_CJK =     big5.so cns11643-plane1.so cns11643-plane2.so \
+                   cns11643-plane14.so gb_2312-80.so jis_x0201.so \
+                   jis_x0208-1983.so jis_x0212-1990.so ksx1001.so shift_jis.so
+CHARSETS_ALL =     ${CHARSETS_SB} ${CHARSETS_CJK}
+EXTRA_ISO8859 =    iso-8859-3.so iso-8859-6.so iso-8859-7.so iso-8859-8.so \
+                   iso-8859-9.so iso-8859-10.so iso-8859-13.so iso-8859-14.so
+EXTRA_KOI =        koi8-ru.so 
+EXTRA_MISC =       gb12345.so johab.so adobe-stdenc.so adobe-symbol.so \
+                   adobe-zdingbats.so mac-ce.so mac-croatian.so mac-cyrillic.so \
+                   mac-dingbats.so mac-greek.so mac-iceland.so mac-japan.so \
+                   mac-roman.so mac-romania.so mac-thai.so mac-turkish.so \
+                   mac-ukraine.so
+EXTRA_PC =         cp424.so cp500.so cp856.so cp1006.so cp437.so cp737.so cp857.so \
+                   cp860.so cp861.so cp862.so cp863.so cp864.so cp865.so cp869.so \
+                   cp874.so cp932.so cp936.so cp949.so cp950.so \
+                   windows-1250.so windows-1251.so windows-1252.so windows-1253.so \
+                   windows-1254.so windows-1255.so windows-1256.so windows-1257.so \
+                   windows-1258.so cp037.so cp875.so cp1026.so \
+                   cp10000.so cp10006.so cp10007.so cp10029.so cp10079.so cp10081.so
+EXTRA_ALL =        ${EXTRA_ISO8859} ${EXTRA_KOI} ${EXTRA_MISC} ${EXTRA_PC}
+RFC1345_PC =       cp851.so cp868.so cp038.so cp273.so cp274.so cp275.so cp277.so \
+                   cp278.so cp280.so cp281.so cp284.so cp285.so cp290.so cp297.so \
+                   cp420.so cp423.so cp870.so cp871.so cp880.so cp891.so \
+                   cp903.so cp904.so cp905.so cp918.so
+RFC1345_EBCDIC =   ebcdic-at-de.so ebcdic-at-de-a.so ebcdic-ca-fr.so \
+                   ebcdic-dk-no.so ebcdic-dk-no-a.so ebcdic-es.so ebcdic-es-a.so \
+                   ebcdic-es-s.so ebcdic-fi-se.so ebcdic-fi-se-a.so ebcdic-fr.so \
+                   ebcdic-it.so ebcdic-pt.so ebcdic-uk.so ebcdic-us.so
+RFC1345_IR =       iso-ir-2.so iso-ir-4.so iso-ir-8-1.so iso-ir-8-2.so \
+                   iso-ir-9-1.so iso-ir-9-2.so iso-ir-10.so iso-ir-11.so \
+                   iso-ir-13.so iso-ir-14.so iso-ir-15.so iso-ir-16.so \
+                   iso-ir-17.so iso-ir-18.so iso-ir-19.so iso-ir-21.so \
+                   iso-ir-25.so iso-ir-27.so iso-ir-37.so iso-ir-47.so \
+                   iso-ir-49.so iso-ir-50.so iso-ir-51.so iso-ir-54.so \
+                   iso-ir-55.so iso-ir-57.so iso-ir-60.so iso-ir-61.so \
+                   iso-ir-69.so iso-ir-70.so iso-ir-84.so iso-ir-85.so \
+                   iso-ir-86.so iso-ir-88.so iso-ir-89.so iso-ir-90.so \
+                   iso-ir-91.so iso-ir-92.so iso-ir-93.so iso-ir-94.so \
+                   iso-ir-95.so iso-ir-96.so iso-ir-98.so iso-ir-99.so \
+                   iso-ir-102.so iso-ir-103.so iso-ir-111.so iso-ir-121.so \
+                   iso-ir-122.so iso-ir-123.so iso-ir-128.so iso-ir-139.so \
+                   iso-ir-141.so iso-ir-142.so iso-ir-143.so iso-ir-146.so \
+                   iso-ir-147.so iso-ir-150.so iso-ir-151.so iso-ir-152.so \
+                   iso-ir-153.so iso-ir-154.so iso-ir-155.so iso-ir-158.so
+RFC1345_MISC =     dec-mcs.so hp-roman8.so iso646-dk.so iso646-kr.so macintosh.so
+RFC1345_ALL =      ${RFC1345_PC} ${RFC1345_EBCDIC} ${RFC1345_IR} ${RFC1345_MISC}
+
+MODULES =          ${CHARSETS_ALL} ${EXTRA_ALL} ${RFC1345_ALL}
+
+all:            ${MODULES}
+
+LDADD=          -L${.CURDIR}/../lib -liconv
+
+INTERNALLIB=
+SYMLINKS !=     ../cs-aliases -p ${MODULEDIR} charset.aliases
+
+NOMAN=
+
+beforeinstall:
+                @mkdir -p ${MODULEDIR}
+                ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+                ${INSTALLFLAGS} ${SHLINSTALLFLAGS} ${MODULES} \
+                ${DESTDIR}${MODULEDIR}
+
+CLEANFILES=     ${MODULES} *.So
+
+.include <bsd.lib.mk>
+.SUFFIXES:      .so .c
diff --git a/ccs/Makefile.in b/ccs/Makefile.in
new file mode 100644
index 0000000..6754e30
--- /dev/null
+++ b/ccs/Makefile.in
@@ -0,0 +1,59 @@
+CHARSETS_ISO8859 = iso-8859-1.la iso-8859-2.la iso-8859-4.la iso-8859-5.la \
+                   iso-8859-15.la
+CHARSETS_PC =      cp775.la cp850.la cp852.la cp855.la cp866.la
+CHARSETS_KOI =     koi8-r.la koi8-u.la
+CHARSETS_SB =      $(CHARSETS_ISO8859) $(CHARSETS_PC) $(CHARSETS_CJK) \
+                   $(CHARSETS_KOI) us-ascii.la
+CHARSETS_CJK =     big5.la cns11643-plane1.la cns11643-plane2.la \
+                   cns11643-plane14.la gb_2312-80.la jis_x0201.la \
+                   jis_x0208-1983.la jis_x0212-1990.la ksx1001.la shift_jis.la
+CHARSETS_ALL =     ${CHARSETS_SB} ${CHARSETS_CJK}
+EXTRA_ISO8859 =    iso-8859-3.la iso-8859-6.la iso-8859-7.la iso-8859-8.la \
+                   iso-8859-9.la iso-8859-10.la iso-8859-13.la iso-8859-14.la
+EXTRA_KOI =        koi8-ru.la 
+EXTRA_MISC =       gb12345.la johab.la adobe-stdenc.la adobe-symbol.la \
+                   adobe-zdingbats.la mac-ce.la mac-croatian.la mac-cyrillic.la \
+                   mac-dingbats.la mac-greek.la mac-iceland.la mac-japan.la \
+                   mac-roman.la mac-romania.la mac-thai.la mac-turkish.la \
+                   mac-ukraine.la
+EXTRA_PC =         cp424.la cp500.la cp856.la cp1006.la cp437.la cp737.la cp857.la \
+                   cp860.la cp861.la cp862.la cp863.la cp864.la cp865.la cp869.la \
+                   cp874.la cp932.la cp936.la cp949.la cp950.la \
+                   windows-1250.la windows-1251.la windows-1252.la windows-1253.la \
+                   windows-1254.la windows-1255.la windows-1256.la windows-1257.la \
+                   windows-1258.la cp037.la cp875.la cp1026.la \
+                   cp10000.la cp10006.la cp10007.la cp10029.la cp10079.la cp10081.la
+EXTRA_ALL =        ${EXTRA_ISO8859} ${EXTRA_KOI} ${EXTRA_MISC} ${EXTRA_PC}
+RFC1345_PC =       cp851.la cp868.la cp038.la cp273.la cp274.la cp275.la cp277.la \
+                   cp278.la cp280.la cp281.la cp284.la cp285.la cp290.la cp297.la \
+                   cp420.la cp423.la cp870.la cp871.la cp880.la cp891.la \
+                   cp903.la cp904.la cp905.la cp918.la
+RFC1345_EBCDIC =   ebcdic-at-de.la ebcdic-at-de-a.la ebcdic-ca-fr.la \
+                   ebcdic-dk-no.la ebcdic-dk-no-a.la ebcdic-es.la ebcdic-es-a.la \
+                   ebcdic-es-s.la ebcdic-fi-se.la ebcdic-fi-se-a.la ebcdic-fr.la \
+                   ebcdic-it.la ebcdic-pt.la ebcdic-uk.la ebcdic-us.la
+RFC1345_IR =       iso-ir-2.la iso-ir-4.la iso-ir-8-1.la iso-ir-8-2.la \
+                   iso-ir-9-1.la iso-ir-9-2.la iso-ir-10.la iso-ir-11.la \
+                   iso-ir-13.la iso-ir-14.la iso-ir-15.la iso-ir-16.la \
+                   iso-ir-17.la iso-ir-18.la iso-ir-19.la iso-ir-21.la \
+                   iso-ir-25.la iso-ir-27.la iso-ir-37.la iso-ir-47.la \
+                   iso-ir-49.la iso-ir-50.la iso-ir-51.la iso-ir-54.la \
+                   iso-ir-55.la iso-ir-57.la iso-ir-60.la iso-ir-61.la \
+                   iso-ir-69.la iso-ir-70.la iso-ir-84.la iso-ir-85.la \
+                   iso-ir-86.la iso-ir-88.la iso-ir-89.la iso-ir-90.la \
+                   iso-ir-91.la iso-ir-92.la iso-ir-93.la iso-ir-94.la \
+                   iso-ir-95.la iso-ir-96.la iso-ir-98.la iso-ir-99.la \
+                   iso-ir-102.la iso-ir-103.la iso-ir-111.la iso-ir-121.la \
+                   iso-ir-122.la iso-ir-123.la iso-ir-128.la iso-ir-139.la \
+                   iso-ir-141.la iso-ir-142.la iso-ir-143.la iso-ir-146.la \
+                   iso-ir-147.la iso-ir-150.la iso-ir-151.la iso-ir-152.la \
+                   iso-ir-153.la iso-ir-154.la iso-ir-155.la iso-ir-158.la
+RFC1345_MISC =     dec-mcs.la hp-roman8.la iso646-dk.la iso646-kr.la macintosh.la
+RFC1345_ALL =      ${RFC1345_PC} ${RFC1345_EBCDIC} ${RFC1345_IR} ${RFC1345_MISC}
+
+MODULES =          ${CHARSETS_ALL} ${EXTRA_ALL} ${RFC1345_ALL}
+
+all:            ${MODULES}
+
+# bring in rules.mk for standard functionality
+@INCLUDE_RULES@
diff --git a/ccs/Makefile.new b/ccs/Makefile.new
new file mode 100644
index 0000000..8c07c3e
--- /dev/null
+++ b/ccs/Makefile.new
@@ -0,0 +1,18 @@
+MODULES = iso-8859-3.so iso-8859-6.so iso-8859-7.so iso-8859-8.so \
+          iso-8859-9.so iso-8859-10.so iso-8859-13.so iso-8859-14.so \
+	  koi8-ru.so gb12345.so johab.so \
+          adobe-stdenc.so adobe-symbol.so adobe-zdingbats.so \
+          mac-ce.so mac-croatian.so mac-cyrillic.so mac-dingbats.so \
+          mac-greek.so mac-iceland.so mac-japan.so mac-roman.so \
+          mac-romania.so mac-thai.so mac-turkish.so mac-ukraine.so \
+          cp424.so cp500.so cp856.so cp1006.so \
+          cp437.so cp737.so cp857.so cp860.so cp861.so cp862.so cp863.so \
+          cp864.so cp865.so cp869.so cp874.so \
+          cp932.so cp936.so cp949.so cp950.so \
+          windows-1250.so windows-1251.so windows-1252.so \
+          windows-1253.so windows-1254.so windows-1255.so \
+          windows-1256.so windows-1257.so windows-1258.so \
+          cp037.so cp875.so cp1026.so \
+          cp10000.so cp10006.so cp10007.so cp10029.so cp10079.so cp10081.so
+
+.include "../Makefile.inc"
diff --git a/ccs/charset.aliases b/ccs/charset.aliases
index 1c61413..2eb4e33 100644
--- a/ccs/charset.aliases
+++ b/ccs/charset.aliases
@@ -1,18 +1,165 @@
-big5		csBig5
-cp775		IBM775 csPC775Baltic
-cp850		IBM850 850 csPC850Multilingual
-cp852		IBM852 852 csPCp852
-cp855		IBM855 855 csIBM855
-cp866		IBM866 866 csIBM866
-gb_2312-80	iso-ir-58 chinese
-iso-8859-1	ISO_8859-1:1987 iso-ir-100 ISO_8859-1 latin1 l1 IBM819 CP819 csISOLatin1
-iso-8859-2	ISO_8859-2:1987 iso-ir-101 ISO_8859-2 latin2 l2 csISOLatin2
-iso-8859-4	ISO_8859-4:1988 iso-ir-110 ISO_8859-4 latin4 l4 csISOLatin4
-iso-8859-5	ISO_8859-5:1988 iso-ir-144 ISO_8859-5 cyrillic csISOLatinCyrillic
-iso-8859-15	ISO_8859-15:1998 ISO_8859-15
-jis_x0201	X0201 csHalfWidthKatakana
-jis_x0208-1983	JIS_C6226-1983 iso-ir-87 x0208
-koi8-r		csKOI8R
-ksx1001		KS_X_1001
-shift_jis	MS_Kanji csShiftJIS
-us-ascii	ANSI_X3.4-1968 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII ISO646-US us IBM367 cp367 csASCII
+adobe-stdenc
+adobe-symbol
+adobe-zdingbats
+big5            csBig5
+cp037           IBM037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl cp037_IBMUSCanada
+cp038           IBM038 EBCDIC-INT
+cp10000         cp10000_MacRoman
+cp10006         cp10006_MacGreek
+cp10007         cp10007_MacCyrillic
+cp10029         cp10029_MacLatin2
+cp10079         cp10079_MacIcelandic
+cp10081         cp10081_MacTurkish
+cp1026          IBM1026 csIBM1026
+cp273           IBM273
+cp274           IBM274 EBCDIC-BE
+cp275           IBM275 EBCDIC-BR
+cp277           IBM277 EBCDIC-CP-DK EBCDIC-CP-NO
+cp278           IBM278 ebcdic-cp-fi ebcdic-cp-se
+cp280           IBM280 ebcdic-cp-it
+cp281           IBM281 EBCDIC-JP-E
+cp284           IBM284 ebcdic-cp-es
+cp285           IBM285 ebcdic-cp-gb
+cp290           IBM290 EBCDIC-JP-kana
+cp297           IBM297 ebcdic-cp-fr
+cp420           IBM420 ebcdic-cp-ar1
+cp423           IBM423 ebcdic-cp-gr
+cp424           IBM424 424 ebcdic-cp-he csIBM424
+cp437           IBM437 437 csPC8CodePage437
+cp500           IBM500 ebcdic-cp-be ebcdic-cp-ch csIBM500
+cp737           IBM737 cp737LatinGreek
+cp775           IBM775 csPC775Baltic
+cp850           IBM850 850 csPC850Multilingual
+cp851           IBM851 851
+cp852           IBM852 852 csPCp852
+cp855           IBM855 855 csIBM855
+cp856           cp856_Hebrew_PC
+cp857           IBM857 857 csIBM857
+cp860           IBM860 860 csIBM860
+cp861           IBM861 861 cp-is csIBM861
+cp862           IBM862 862 csPC862LatinHebrew
+cp863           IBM863 863 csIBM863
+cp864           IBM864 csIBM864
+cp865           IBM865 865 csIBM865
+cp866           IBM866 866 csIBM866
+cp868           IBM868 cp-ar
+cp869           IBM869 869 cp-gr csIBM869
+cp870           IBM870 ebcdic-cp-roece ebcdic-cp-yu
+cp871           IBM871 ebcdic-cp-is
+cp874           IBM874
+cp875           cp875_IBMGreek
+cp880           IBM880 EBCDIC-Cyrillic
+cp891           IBM891
+cp903           IBM903
+cp904           IBM904 904
+cp905           IBM905 ebcdic-cp-tr
+cp918           IBM918 ebcdic-cp-ar2
+dec-mcs         dec
+gb_2312-80      iso-ir-58 chinese
+hp-roman8       roman8 r8
+iso-8859-1      ISO_8859-1:1987 iso-ir-100 ISO_8859-1 latin1 l1 IBM819 CP819 csISOLatin1
+iso-8859-10     ISO_8859-10:1992 iso-ir-157 ISO_8859-10 latin6 l6 csISOLatin6
+iso-8859-13     ISO_8859-13:1998 ISO_8859-13
+iso-8859-14     ISO_8859-14:1998 ISO_8859-14
+iso-8859-15     ISO_8859-15:1998 ISO_8859-15
+iso-8859-2      ISO_8859-2:1987 iso-ir-101 ISO_8859-2 latin2 l2 csISOLatin2
+iso-8859-3      ISO_8859-3:1988 iso-ir-109 ISO_8859-3 latin3 l3 csISOLatin3
+iso-8859-4      ISO_8859-4:1988 iso-ir-110 ISO_8859-4 latin4 l4 csISOLatin4
+iso-8859-5      ISO_8859-5:1988 iso-ir-144 ISO_8859-5 cyrillic csISOLatinCyrillic
+iso-8859-6      ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ECMA-114 ASMO-708 arabic csISOLatinArabic
+iso-8859-7      ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ELOT_928 ECMA-118 greek greek8 csISOLatinGreek
+iso-8859-8      ISO_8859-8:1988 iso-ir-138 ISO_8859-8 hebrew csISOLatinHebrew
+iso-8859-9      ISO_8859-9:1989 iso-ir-148 ISO_8859-9 latin5 l5 csISOLatin5
+iso-ir-10       SEN_850200_B FI ISO646-FI ISO646-SE se
+iso-ir-102      T.61-7bit
+iso-ir-103      T.61-8bit T.61
+iso-ir-11       SEN_850200_C ISO646-SE2 se2
+iso-ir-111      ECMA-cyrillic
+iso-ir-121      CSA_Z243.4-1985-1 ISO646-CA csa7-1 ca
+iso-ir-122      CSA_Z243.4-1985-2 ISO646-CA2 csa7-2
+iso-ir-123      CSA_Z243.4-1985-gr
+iso-ir-128      T.101-G2
+iso-ir-13       JIS_C6220-1969-jp JIS_C6220-1969 katakana x0201-7
+iso-ir-139      CSN_369103
+iso-ir-14       JIS_C6220-1969-ro jp ISO646-JP
+iso-ir-141      JUS_I.B1.002 ISO646-YU js yu
+iso-ir-142      ISO_6937-2-add
+iso-ir-143      IEC_P27-1
+iso-ir-146      JUS_I.B1.003-serb serbian
+iso-ir-147      JUS_I.B1.003-mac macedonian
+iso-ir-15       IT ISO646-IT
+iso-ir-150      greek-ccitt
+iso-ir-151      NC_NC00-10:81 cuba ISO646-CU
+iso-ir-152      ISO_6937-2-25
+iso-ir-153      GOST_19768-74 ST_SEV_358-88
+iso-ir-154      ISO_8859-supp latin1-2-5
+iso-ir-155      ISO_10367-box
+iso-ir-158      latin-lap lap
+iso-ir-16       PT ISO646-PT
+iso-ir-17       ES ISO646-ES
+iso-ir-18       greek7-old
+iso-ir-19       latin-greek
+iso-ir-2        ISO_646.irv:1983 irv
+iso-ir-21       DIN_66003 de ISO646-DE
+iso-ir-25       NF_Z_62-010_\(1973\) ISO646-FR1
+iso-ir-27       Latin-greek-1
+iso-ir-37       ISO_5427
+iso-ir-4        BS_4730 ISO646-GB gb uk
+iso-ir-47       BS_viewdata
+iso-ir-49       INIS
+iso-ir-50       INIS-8
+iso-ir-51       INIS-cyrillic
+iso-ir-54       ISO_5427:1981
+iso-ir-55       ISO_5428:1980
+iso-ir-57       GB_1988-80
+iso-ir-60       NS_4551-1 ISO646-NO no
+iso-ir-61       NS_4551-2 ISO646-NO2 no2
+iso-ir-69       NF_Z_62-010 ISO646-FR fr
+iso-ir-70       videotex-suppl
+iso-ir-8-1      NATS-SEFI
+iso-ir-8-2      NATS-SEFI-ADD
+iso-ir-84       PT2 ISO646-PT2
+iso-ir-85       ES2 ISO646-ES2
+iso-ir-86       MSZ_7795.3 ISO646-HU hu
+iso-ir-88       greek7
+iso-ir-89       ASMO_449 ISO_9036 arabic7
+iso-ir-9-1      NATS-DANO
+iso-ir-9-2      NATS-DANO-ADD
+iso-ir-91       JIS_C6229-1984-a ISO646-JP-OCR-A jp-ocr-a
+iso-ir-92       JIS_C6229-1984-b ISO646-JP-OCR-B jp-ocr-b
+iso-ir-93       JIS_C6229-1984-b-add jp-ocr-b-add
+iso-ir-94       JIS_C6229-1984-hand jp-ocr-hand
+iso-ir-95       JIS_C6229-1984-hand-add jp-ocr-hand-add
+iso-ir-96       JIS_C6229-1984-kana
+iso-ir-98       ISO_2033-1983 e13b
+iso-ir-99       ANSI_X3.110-1983 CSA_T500-1983 NAPLPS
+iso646-dk       DS_2089 DS2089 dk
+iso646-kr       KSC5636
+jis_x0201       X0201 csHalfWidthKatakana
+jis_x0208-1983  JIS_C6226-1983 iso-ir-87 x0208
+koi8-r          csKOI8R
+koi8-ru
+ksx1001         KS_X_1001
+mac-ce          macCentEuro
+mac-croatian    macCroatian
+mac-cyrillic    macCyrillic
+mac-dingbats    macDingbats
+mac-greek       macGreek
+mac-iceland     macIceland
+mac-roman       macRoman
+mac-romania     macRomania
+mac-thai        macThai
+mac-turkish     macTurkish
+mac-ukraine     macUkraine
+macintosh       mac
+shift_jis       MS_Kanji csShiftJIS
+us-ascii        ANSI_X3.4-1968 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII ISO646-US us IBM367 cp367 csASCII
+windows-1250    cp1250
+windows-1251    cp1251
+windows-1252    cp1252
+windows-1253    cp1253
+windows-1254    cp1254
+windows-1255    cp1255
+windows-1256    cp1256
+windows-1257    cp1257
+windows-1258    cp1258
diff --git a/ccs/extra.aliases b/ccs/extra.aliases
deleted file mode 100644
index 2963e68..0000000
--- a/ccs/extra.aliases
+++ /dev/null
@@ -1,55 +0,0 @@
-adobe-stdenc
-adobe-symbol
-adobe-zdingbats
-cp037		IBM037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl cp037_IBMUSCanada
-cp424		IBM424 424 ebcdic-cp-he csIBM424
-cp437		IBM437 437 csPC8CodePage437
-cp500		IBM500 ebcdic-cp-be ebcdic-cp-ch csIBM500
-cp737		IBM737 cp737LatinGreek
-cp856		cp856_Hebrew_PC
-cp857		IBM857 857 csIBM857
-cp860		IBM860 860 csIBM860
-cp861		IBM861 861 cp-is csIBM861
-cp862		IBM862 862 csPC862LatinHebrew
-cp863		IBM863 863 csIBM863
-cp864		IBM864 csIBM864
-cp865		IBM865 865 csIBM865
-cp869		IBM869 869 cp-gr csIBM869
-cp874		IBM874
-cp875		cp875_IBMGreek
-cp1026		IBM1026 csIBM1026
-cp10000		cp10000_MacRoman
-cp10006		cp10006_MacGreek
-cp10007		cp10007_MacCyrillic
-cp10029		cp10029_MacLatin2
-cp10079		cp10079_MacIcelandic
-cp10081		cp10081_MacTurkish
-iso-8859-3	ISO_8859-3:1988 iso-ir-109 ISO_8859-3 latin3 l3 csISOLatin3
-iso-8859-6	ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ECMA-114 ASMO-708 arabic csISOLatinArabic
-iso-8859-7	ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ELOT_928 ECMA-118 greek greek8 csISOLatinGreek
-iso-8859-8	ISO_8859-8:1988 iso-ir-138 ISO_8859-8 hebrew csISOLatinHebrew
-iso-8859-9	ISO_8859-9:1989 iso-ir-148 ISO_8859-9 latin5 l5 csISOLatin5
-iso-8859-10	ISO_8859-10:1992 iso-ir-157 ISO_8859-10 latin6 l6 csISOLatin6
-iso-8859-13	ISO_8859-13:1998 ISO_8859-13
-iso-8859-14	ISO_8859-14:1998 ISO_8859-14
-koi8-ru
-mac-ce		macCentEuro
-mac-croatian	macCroatian
-mac-cyrillic	macCyrillic
-mac-dingbats	macDingbats
-mac-greek	macGreek
-mac-iceland	macIceland
-mac-roman	macRoman
-mac-romania	macRomania
-mac-thai	macThai
-mac-turkish	macTurkish
-mac-ukraine	macUkraine
-windows-1250	cp1250
-windows-1251	cp1251
-windows-1252	cp1252
-windows-1253	cp1253
-windows-1254	cp1254
-windows-1255	cp1255
-windows-1256	cp1256
-windows-1257	cp1257
-windows-1258	cp1258
diff --git a/ccs/rfc1345.aliases b/ccs/rfc1345.aliases
deleted file mode 100644
index e721e3b..0000000
--- a/ccs/rfc1345.aliases
+++ /dev/null
@@ -1,92 +0,0 @@
-cp038		IBM038 EBCDIC-INT
-cp273		IBM273
-cp274		IBM274 EBCDIC-BE
-cp275		IBM275 EBCDIC-BR
-cp277		IBM277 EBCDIC-CP-DK EBCDIC-CP-NO
-cp278		IBM278 ebcdic-cp-fi ebcdic-cp-se
-cp280		IBM280 ebcdic-cp-it
-cp281		IBM281 EBCDIC-JP-E
-cp284		IBM284 ebcdic-cp-es
-cp285		IBM285 ebcdic-cp-gb
-cp290		IBM290 EBCDIC-JP-kana
-cp297		IBM297 ebcdic-cp-fr
-cp420		IBM420 ebcdic-cp-ar1
-cp423		IBM423 ebcdic-cp-gr
-cp851		IBM851 851
-cp868		IBM868 cp-ar
-cp870		IBM870 ebcdic-cp-roece ebcdic-cp-yu
-cp871		IBM871 ebcdic-cp-is
-cp880		IBM880 EBCDIC-Cyrillic
-cp891		IBM891
-cp903		IBM903
-cp904		IBM904 904
-cp905		IBM905 ebcdic-cp-tr
-cp918		IBM918 ebcdic-cp-ar2
-dec-mcs		dec
-hp-roman8	roman8 r8
-iso646-dk	DS_2089 DS2089 dk
-iso646-kr	KSC5636
-iso-ir-2	ISO_646.irv:1983 irv
-iso-ir-4	BS_4730 ISO646-GB gb uk
-iso-ir-8-1	NATS-SEFI
-iso-ir-8-2	NATS-SEFI-ADD
-iso-ir-9-1	NATS-DANO
-iso-ir-9-2	NATS-DANO-ADD
-iso-ir-10	SEN_850200_B FI ISO646-FI ISO646-SE se
-iso-ir-11	SEN_850200_C ISO646-SE2 se2
-iso-ir-13	JIS_C6220-1969-jp JIS_C6220-1969 katakana x0201-7
-iso-ir-14	JIS_C6220-1969-ro jp ISO646-JP
-iso-ir-15	IT ISO646-IT
-iso-ir-16	PT ISO646-PT
-iso-ir-17	ES ISO646-ES
-iso-ir-18	greek7-old
-iso-ir-19	latin-greek
-iso-ir-21	DIN_66003 de ISO646-DE
-iso-ir-25	NF_Z_62-010_\(1973\) ISO646-FR1
-iso-ir-27	Latin-greek-1
-iso-ir-37	ISO_5427
-iso-ir-47	BS_viewdata
-iso-ir-49	INIS
-iso-ir-50	INIS-8
-iso-ir-51	INIS-cyrillic
-iso-ir-54	ISO_5427:1981
-iso-ir-55	ISO_5428:1980
-iso-ir-57	GB_1988-80
-iso-ir-60	NS_4551-1 ISO646-NO no
-iso-ir-61	NS_4551-2 ISO646-NO2 no2
-iso-ir-69	NF_Z_62-010 ISO646-FR fr
-iso-ir-70	videotex-suppl
-iso-ir-84	PT2 ISO646-PT2
-iso-ir-85	ES2 ISO646-ES2
-iso-ir-86	MSZ_7795.3 ISO646-HU hu
-iso-ir-88	greek7
-iso-ir-89	ASMO_449 ISO_9036 arabic7
-iso-ir-91	JIS_C6229-1984-a ISO646-JP-OCR-A jp-ocr-a
-iso-ir-92	JIS_C6229-1984-b ISO646-JP-OCR-B jp-ocr-b
-iso-ir-93	JIS_C6229-1984-b-add jp-ocr-b-add
-iso-ir-94	JIS_C6229-1984-hand jp-ocr-hand
-iso-ir-95	JIS_C6229-1984-hand-add jp-ocr-hand-add
-iso-ir-96	JIS_C6229-1984-kana
-iso-ir-98	ISO_2033-1983 e13b
-iso-ir-99	ANSI_X3.110-1983 CSA_T500-1983 NAPLPS
-iso-ir-102	T.61-7bit
-iso-ir-103	T.61-8bit T.61
-iso-ir-111	ECMA-cyrillic
-iso-ir-121	CSA_Z243.4-1985-1 ISO646-CA csa7-1 ca
-iso-ir-122	CSA_Z243.4-1985-2 ISO646-CA2 csa7-2
-iso-ir-123	CSA_Z243.4-1985-gr
-iso-ir-128	T.101-G2
-iso-ir-139	CSN_369103
-iso-ir-141	JUS_I.B1.002 ISO646-YU js yu
-iso-ir-142	ISO_6937-2-add
-iso-ir-143	IEC_P27-1
-iso-ir-146	JUS_I.B1.003-serb serbian
-iso-ir-147	JUS_I.B1.003-mac macedonian
-iso-ir-150	greek-ccitt
-iso-ir-151	NC_NC00-10:81 cuba ISO646-CU
-iso-ir-152	ISO_6937-2-25
-iso-ir-153	GOST_19768-74 ST_SEV_358-88
-iso-ir-154	ISO_8859-supp latin1-2-5
-iso-ir-155	ISO_10367-box
-iso-ir-158	latin-lap lap
-macintosh	mac
diff --git a/ces/.cvsignore b/ces/.cvsignore
new file mode 100644
index 0000000..2cbb2f1
--- /dev/null
+++ b/ces/.cvsignore
@@ -0,0 +1,4 @@
+.libs
+*.la
+*.lo
+*.slo
diff --git a/ces/Makefile b/ces/Makefile
index d9e499c..938ff74 100644
--- a/ces/Makefile
+++ b/ces/Makefile
@@ -1,4 +1,30 @@
-MODULES = unicode-1-1-utf-7.so iso-2022-cn.so iso-2022-jp.so \
-	  iso-2022-jp-2.so iso-2022-kr.so
-
 .include "../Makefile.inc"
+
+MODULES_CORE=   _tbl_simple.so euc-jp.so euc-kr.so euc-tw.so gb2312.so \
+                iso-10646-ucs-2.so iso-10646-ucs-4.so \
+                ucs2-internal.so ucs4-internal.so utf-8.so utf-16.so
+
+MODULES_EXTRA = unicode-1-1-utf-7.so iso-2022-cn.so iso-2022-jp.so \
+                iso-2022-jp-2.so iso-2022-kr.so
+
+MODULES =       ${MODULES_CORE} ${MODULES_EXTRA}
+
+all:    ${MODULES}
+
+LDADD=          -L${.CURDIR}/../lib -liconv
+
+INTERNALLIB=
+SYMLINKS !=     ../cs-aliases -p ${MODULEDIR} charset.aliases
+
+NOMAN=
+
+beforeinstall:
+                @mkdir -p ${MODULEDIR}
+                ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+                ${INSTALLFLAGS} ${SHLINSTALLFLAGS} ${MODULES} \
+                ${DESTDIR}${MODULEDIR}
+
+CLEANFILES=     ${MODULES} *.So
+
+.include <bsd.lib.mk>
+.SUFFIXES:      .so
diff --git a/ces/Makefile.in b/ces/Makefile.in
new file mode 100644
index 0000000..2d6fa81
--- /dev/null
+++ b/ces/Makefile.in
@@ -0,0 +1,13 @@
+MODULES_CORE=   _tbl_simple.la euc-jp.la euc-kr.la euc-tw.la gb2312.la \
+                iso-10646-ucs-2.la iso-10646-ucs-4.la \
+                ucs2-internal.la ucs4-internal.la utf-8.la utf-16.la
+
+MODULES_EXTRA = unicode-1-1-utf-7.la iso-2022-cn.la iso-2022-jp.la \
+                iso-2022-jp-2.la iso-2022-kr.la
+
+MODULES =       ${MODULES_CORE} ${MODULES_EXTRA}
+
+all:    ${MODULES}
+
+# bring in rules.mk for standard functionality
+@INCLUDE_RULES@
diff --git a/ces/Makefile.new b/ces/Makefile.new
new file mode 100644
index 0000000..d9e499c
--- /dev/null
+++ b/ces/Makefile.new
@@ -0,0 +1,4 @@
+MODULES = unicode-1-1-utf-7.so iso-2022-cn.so iso-2022-jp.so \
+	  iso-2022-jp-2.so iso-2022-kr.so
+
+.include "../Makefile.inc"
diff --git a/ces/_tbl_simple.c b/ces/_tbl_simple.c
index 3269952..d5e106e 100644
--- a/ces/_tbl_simple.c
+++ b/ces/_tbl_simple.c
@@ -30,12 +30,13 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
+#include "apr.h"
+
 #define ICONV_INTERNAL
-#include <iconv.h>
-#include <errno.h>
+#include "iconv.h"
 
 static int
-table_open(struct iconv_ces *ces)
+table_open(struct iconv_ces *ces, apr_pool_t *ctx)
 {
 	ces->data = (void *)(ces->mod->im_deplist->im_desc->imd_data);
 	return 0;
@@ -47,7 +48,7 @@
 	return ((struct iconv_ccs_desc *)(ces->data))->names;
 }
 
-static __inline int
+static APR_INLINE int
 table_nbits(struct iconv_ces *ces)
 {
 	return ((struct iconv_ccs_desc *)(ces->data))->nbits;
@@ -71,13 +72,13 @@
 	return res == 16 ? 0 : (res > 8 ? 2 : 1);
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	struct iconv_ccs_desc *ccsd = ces->data;
 	ucs_t res;
-	size_t bytes;
+	apr_size_t bytes;
 
 	if (in == UCS_CHAR_NONE)
 		return 1;	/* No state reinitialization for table charsets */
@@ -98,12 +99,12 @@
 
 static ucs_t
 convert_to_ucs(struct iconv_ces *ces, const unsigned char **inbuf,
-	size_t *inbytesleft)
+	apr_size_t *inbytesleft)
 {
 	struct iconv_ccs_desc *ccsd = ces->data;
 	unsigned char byte = *(*inbuf);
 	ucs_t res = ICONV_CCS_CONVERT_TO_UCS(ccsd, byte);
-	size_t bytes = (res == UCS_CHAR_INVALID && table_nbits(ces) > 8) ? 2 : 1;
+	apr_size_t bytes = (res == UCS_CHAR_INVALID && table_nbits(ces) > 8) ? 2 : 1;
 
 	if (*inbytesleft < bytes)
 		return UCS_CHAR_NONE;	/* Not enough bytes in the input buffer */
@@ -115,35 +116,35 @@
 	return res;
 }
 
-static int
-table_load_ccs(struct iconv_module *mod)
+static apr_status_t
+table_load_ccs(struct iconv_module *mod, apr_pool_t *ctx)
 {
 	struct iconv_module *ccsmod;
 	int error;
 
 	if (mod->im_args == NULL)
-		return EINVAL;
-	error = iconv_mod_load(mod->im_args, ICMOD_UC_CCS, NULL, &ccsmod);
+		return APR_EINVAL;
+	error = iconv_mod_load(mod->im_args, ICMOD_UC_CCS, NULL, &ccsmod, ctx);
 	if (error)
 		return error;
 	ccsmod->im_next = mod->im_deplist;
 	mod->im_deplist = ccsmod;
-	return 0;
+	return APR_SUCCESS;
 }
 
-static int
-table_event(struct iconv_module *mod, int event)
+static apr_status_t
+table_event(struct iconv_module *mod, int event, apr_pool_t *ctx)
 {
 	switch (event) {
 	    case ICMODEV_LOAD:
 	    case ICMODEV_UNLOAD:
 		break;
 	    case ICMODEV_DYNDEPS:
-		return table_load_ccs(mod);
+		return table_load_ccs(mod,ctx);
 	    default:
-		return EINVAL;
+		return APR_EINVAL;
 	}
-	return 0;
+	return APR_SUCCESS;
 }
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/euc-jp.c b/ces/euc-jp.c
index 0e7ba44..9032c4d 100644
--- a/ces/euc-jp.c
+++ b/ces/euc-jp.c
@@ -58,7 +58,7 @@
 	{ICMOD_UC_CCS, "jis_x0208-1983", ccsattr + 1},
 	{ICMOD_UC_CCS, "jis_x0201", ccsattr + 2},
 	{ICMOD_UC_CCS, "jis_x0212-1990", ccsattr + 3},
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/euc-kr.c b/ces/euc-kr.c
index e839b32..223ad90 100644
--- a/ces/euc-kr.c
+++ b/ces/euc-kr.c
@@ -51,7 +51,7 @@
 static const struct iconv_module_depend iconv_module_depend[] = {
 	{ICMOD_UC_CCS, "us-ascii", ccsattr + 0},
 	{ICMOD_UC_CCS, "ksx1001", ccsattr + 1},
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc =  {
diff --git a/ces/euc-tw.c b/ces/euc-tw.c
index fa89563..5c40c1d 100644
--- a/ces/euc-tw.c
+++ b/ces/euc-tw.c
@@ -55,7 +55,7 @@
 	{ICMOD_UC_CCS, "cns11643-plane1", ccsattr + 1},
 	{ICMOD_UC_CCS, "cns11643-plane2", ccsattr + 2},
 	{ICMOD_UC_CCS, "cns11643-plane14", ccsattr + 3},
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/gb2312.c b/ces/gb2312.c
index c1a5f79..4981abd 100644
--- a/ces/gb2312.c
+++ b/ces/gb2312.c
@@ -51,7 +51,7 @@
 static const struct iconv_module_depend iconv_module_depend[] = {
 	{ICMOD_UC_CCS, "us-ascii", ccsattr + 0},
 	{ICMOD_UC_CCS, "gb_2312-80", ccsattr + 1},
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/iso-10646-ucs-2.c b/ces/iso-10646-ucs-2.c
index f0100be..3dd9c0a 100644
--- a/ces/iso-10646-ucs-2.c
+++ b/ces/iso-10646-ucs-2.c
@@ -45,11 +45,11 @@
 	return names;
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
-	size_t bytes;
+	apr_size_t bytes;
 	int *state = ces->data;
 
 	if (in == UCS_CHAR_NONE)
@@ -70,7 +70,7 @@
 	return 1;
 }
 
-static __inline ucs_t
+static APR_INLINE ucs_t
 msb(const unsigned char *buf)
 {
 	return (buf[0] << 8) | buf[1];
@@ -78,7 +78,7 @@
 
 static ucs_t 
 convert_to_ucs(struct iconv_ces *ces, const unsigned char **inbuf,
-	size_t *inbytesleft)
+	apr_size_t *inbytesleft)
 {
 	ucs_t res;
 	int *state = ces->data;
diff --git a/ces/iso-10646-ucs-4.c b/ces/iso-10646-ucs-4.c
index 51c4608..608f4e5 100644
--- a/ces/iso-10646-ucs-4.c
+++ b/ces/iso-10646-ucs-4.c
@@ -45,9 +45,9 @@
 	return names;
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	int *state = (int*)ces->data;
 	int bytes;
@@ -72,7 +72,7 @@
 	return 1;
 }
 
-static __inline ucs_t
+static APR_INLINE ucs_t
 msb(const unsigned char *buf)
 {
 	return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
@@ -80,7 +80,7 @@
 
 static ucs_t
 convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	ucs_t res;
 	int *state = (int*)ces->data;
diff --git a/ces/iso-2022-cn.c b/ces/iso-2022-cn.c
index 9b5f6b4..1087107 100644
--- a/ces/iso-2022-cn.c
+++ b/ces/iso-2022-cn.c
@@ -57,7 +57,7 @@
 	{ICMOD_UC_CCS, "gb_2312-80", ccsattr + 1},
 	{ICMOD_UC_CCS, "cns11643-plane1", ccsattr + 2},
 	{ICMOD_UC_CCS, "cns11643-plane2", ccsattr + 3},
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/iso-2022-jp-2.c b/ces/iso-2022-jp-2.c
index 25238e1..1260209 100644
--- a/ces/iso-2022-jp-2.c
+++ b/ces/iso-2022-jp-2.c
@@ -69,7 +69,7 @@
 	{ICMOD_UC_CCS, "jis_x0212-1990", ccsattr + 6 },
 	{ICMOD_UC_CCS, "iso-8859-1",     ccsattr + 7 },
 	{ICMOD_UC_CCS, "iso-8859-7",     ccsattr + 8 },
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/iso-2022-jp.c b/ces/iso-2022-jp.c
index 7ccf020..73c9c62 100644
--- a/ces/iso-2022-jp.c
+++ b/ces/iso-2022-jp.c
@@ -59,7 +59,7 @@
 	{ICMOD_UC_CCS, "jis_x0201", ccsattr + 1},
 	{ICMOD_UC_CCS, "jis_x0208-1983", ccsattr + 2},
 	{ICMOD_UC_CCS, "jis_x0208-1983", ccsattr + 3},
-	{}
+	NULL
 };
 
 static const struct iconv_ces_desc iconv_ces_desc = {
diff --git a/ces/ucs2-internal.c b/ces/ucs2-internal.c
index 75f6896..666364d 100644
--- a/ces/ucs2-internal.c
+++ b/ces/ucs2-internal.c
@@ -43,15 +43,15 @@
 	return names;
 }
 
-static __inline int
+static APR_INLINE int
 ucs2_nbytes(struct iconv_ces *ces)
 {
 	return sizeof(ucs2_t);
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	if (in == UCS_CHAR_NONE)
 		return 1;	/* No state reinitialization for table charsets */
@@ -66,7 +66,7 @@
 
 static ucs_t
 convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	if (*inbytesleft < sizeof(ucs2_t))
 		return UCS_CHAR_NONE;	/* Not enough bytes in the input buffer */
diff --git a/ces/ucs4-internal.c b/ces/ucs4-internal.c
index f500d5f..6e3b432 100644
--- a/ces/ucs4-internal.c
+++ b/ces/ucs4-internal.c
@@ -43,15 +43,15 @@
 	return names;
 }
 
-static __inline int
+static APR_INLINE int
 ucs4_nbytes(struct iconv_ces *ces)
 {
 	return sizeof(ucs4_t);
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	if (in == UCS_CHAR_NONE)
 		return 1;	/* No state reinitialization for table charsets */
@@ -64,7 +64,7 @@
 
 static ucs_t
 convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	if (*inbytesleft < sizeof(ucs4_t))
 		return UCS_CHAR_NONE;	/* Not enough bytes in the input buffer */
diff --git a/ces/unicode-1-1-utf-7.c b/ces/unicode-1-1-utf-7.c
index 68067b3..cd52c62 100644
--- a/ces/unicode-1-1-utf-7.c
+++ b/ces/unicode-1-1-utf-7.c
@@ -47,8 +47,8 @@
 	return names;
 }
 
-static inline int
-lackofbytes(int bytes, size_t *bytesleft)
+static APR_INLINE int
+lackofbytes(int bytes, apr_size_t *bytesleft)
 {
 	if (bytes > *bytesleft)
 	    return 1;
@@ -62,7 +62,7 @@
 
 #define base64(ch) (base64_str[(ch) & 0x3F])
 
-static inline int output(char ch, unsigned char **outbuf)
+static APR_INLINE int output(char ch, unsigned char **outbuf)
 {
 	*(*outbuf)++ = ch;
 	return 1;
@@ -120,9 +120,9 @@
 			utf7_encoded;
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *module, ucs_t in,
-                 unsigned char **outbuf, size_t *outbytesleft)
+                 unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 #define utf7_state ((char *)(module->data))
     int ch = char_type(in), needbytes = 3;
@@ -229,7 +229,7 @@
 }
 
 static ucs_t convert_to_ucs(struct iconv_ces *module,
-                            const unsigned char **inbuf, size_t *inbytesleft)
+                            const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 #define utf7_state ((char *)(module->data))
     int ch = char_type(*(unsigned char *)*inbuf), needbytes = 0;
diff --git a/ces/utf-16.c b/ces/utf-16.c
index 6519e6d..85262ef 100644
--- a/ces/utf-16.c
+++ b/ces/utf-16.c
@@ -30,9 +30,6 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <errno.h>
-#include <stdlib.h>	/* free, malloc */
-
 #define ICONV_INTERNAL
 #include <iconv.h>
 
@@ -46,9 +43,9 @@
 	return names;
 }
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	    unsigned char **outbuf, size_t *outbytesleft)
+	    unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	unsigned char *cp;
 	int *state = (int *)ces->data;
@@ -81,7 +78,7 @@
 	return 1;
 }
 
-static __inline ucs_t
+static APR_INLINE ucs_t
 msb(const unsigned char *buf)
 {
 	return (buf[0] << 8) | buf[1];
@@ -89,7 +86,7 @@
 
 static ucs_t
 convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	ucs_t res, res2;
 	int *state = (int *)ces->data;
diff --git a/ces/utf-8.c b/ces/utf-8.c
index a190635..2eb0358 100644
--- a/ces/utf-8.c
+++ b/ces/utf-8.c
@@ -46,9 +46,9 @@
 
 #define cont_byte(b) (((b) & 0x3F) | 0x80)
 
-static ssize_t
+static apr_ssize_t
 convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	unsigned char *cp;
 	int n;
@@ -64,7 +64,6 @@
 		n = 4;
 	} else
 		return -1;
-iconv_warnx("ch=%08X, n=%d, left=%d", in, n, *outbytesleft);
 	if (*outbytesleft < n)
 		return 0;
 	cp = *outbuf;
@@ -95,7 +94,7 @@
 
 static ucs_t
 convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	const unsigned char *in = *inbuf;
 	unsigned char byte = *in++;
diff --git a/configure.in b/configure.in
new file mode 100644
index 0000000..b10dbd1
--- /dev/null
+++ b/configure.in
@@ -0,0 +1,90 @@
+dnl
+dnl Process this file with autoconf to produce a configure script
+dnl
+
+AC_PREREQ(2.13)
+AC_INIT(build/rules.mk.in)
+
+AC_CONFIG_AUX_DIR(../apr/build)
+AC_CONFIG_HEADER(lib/apr_iconv_private.h)
+AC_PREFIX_DEFAULT(/usr/local/apache2)
+#test "$prefix" = "NONE" && prefix='/usr/local/apache2'
+
+AC_PROG_CC
+AC_PROG_AWK
+AC_CHECK_PROG(RM, rm, rm)
+
+dnl
+dnl compute the top directory of the build
+dnl note: this is needed for LIBTOOL
+dnl
+top_builddir="`cd $srcdir ; pwd`"
+AC_SUBST(top_builddir)
+
+dnl check for APR
+APU_FIND_APR
+aprbuild=$APR_SOURCE_DIR/build
+
+dnl
+dnl set up the compilation flags and stuff
+dnl
+INCLUDES="$INCLUDES -I\$(top_builddir)/lib"
+
+INCLUDES="$INCLUDES -I$APR_INCLUDES"
+
+dnl
+dnl prep libtool
+dnl
+echo "performing libtool configuration..."
+AC_PROG_LIBTOOL
+
+$SHELL $aprbuild/ltconfig --output=shlibtool --disable-static --srcdir=$aprbuild --cache-file=./config.cache $aprbuild/ltmain.sh
+dnl
+dnl grab flags from APR.
+dnl ### APR doesn't have "nice" names for its exports (yet), but it isn't
+dnl ### a problem to deal with them right here
+dnl
+
+. "$APR_SOURCE_DIR/APRVARS"
+APR_EXPORT_CPPFLAGS="$EXTRA_CPPFLAGS"
+APR_EXPORT_CFLAGS="$EXTRA_CFLAGS"
+APR_EXPORT_LIBS="$EXTRA_LIBS"
+
+dnl
+dnl Prep all the flags and stuff for compilation and export to other builds
+dnl
+CFLAGS="$CFLAGS $INCLUDES $APR_EXPORT_CFLAGS $APR_EXPORT_CPPFLAGS"
+LIBS="$LIBS $APR_EXPORT_LIBS"
+
+AC_SUBST(APRUTIL_EXPORT_LIBS)
+
+#
+# Adds in config *.h file
+AC_DEFINE_UNQUOTED(ICONV_DEFAULT_PATH,"$prefix/lib/iconv",
+	[ Directory where the *.so tables are stored ] )
+iconv_libdir=$prefix/lib/iconv
+AC_SUBST(iconv_libdir)
+
+dnl
+dnl BSD/OS (BSDi) needs to use a different include syntax in the Makefiles
+dnl
+case "$host_alias" in
+*bsdi*)
+    INCLUDE_RULES=".include \"$top_builddir/build/rules.mk\""
+    ;;
+*)
+    INCLUDE_RULES="include $top_builddir/build/rules.mk"
+    ;;
+esac
+AC_SUBST(INCLUDE_RULES)
+
+dnl
+dnl everthing is done. 
+AC_OUTPUT([
+	Makefile
+	ccs/Makefile
+	ces/Makefile
+	lib/Makefile
+	util/Makefile
+	build/rules.mk
+	])
diff --git a/include/apr_iconv.h b/include/apr_iconv.h
new file mode 100644
index 0000000..35d8ad2
--- /dev/null
+++ b/include/apr_iconv.h
@@ -0,0 +1,396 @@
+/*-
+ * Copyright (c) 1999,2000
+ *	Konstantin Chuguev.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Konstantin Chuguev
+ *	and its contributors.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _ICONV_H_
+#define _ICONV_H_
+
+#include "apr.h"
+#include "apr_pools.h"
+#ifdef WIN32
+#define ICONV_DEFAULT_PATH "iconv"
+#else
+#include "apr_iconv_private.h" /* contains ICONV_DEFAULT_PATH */
+#endif
+
+#include <stddef.h>
+
+/* apr additions */
+#define issetugid() 0
+/* apr additions */
+
+/**
+ * APR_DECLARE_EXPORT is defined when building the APR dynamic library,
+ * so that all public symbols are exported.
+ *
+ * APR_DECLARE_STATIC is defined when including the APR public headers,
+ * to provide static linkage when the dynamic library may be unavailable.
+ *
+ * APR_DECLARE_STATIC and APR_DECLARE_EXPORT are left undefined when
+ * including the APR public headers, to import and link the symbols from the 
+ * dynamic APR library and assure appropriate indirection and calling 
+ * conventions at compile time.
+ */
+
+#if !defined(WIN32)
+/**
+ * The public APR functions are declared with APR_DECLARE(), so they may
+ * use the most appropriate calling convention.  Public APR functions with 
+ * variable arguments must use APR_DECLARE_NONSTD().
+ *
+ * @deffunc APR_DECLARE(rettype) apr_func(args);
+ */
+#define API_DECLARE(type)            type
+/**
+ * The public APR variables are declared with AP_MODULE_DECLARE_DATA.
+ * This assures the appropriate indirection is invoked at compile time.
+ *
+ * @deffunc APR_DECLARE_DATA type apr_variable;
+ * @tip extern APR_DECLARE_DATA type apr_variable; syntax is required for
+ * declarations within headers to properly import the variable.
+ */
+#define API_DECLARE_DATA
+#elif defined(API_DECLARE_STATIC)
+#define API_DECLARE(type)            type __stdcall
+#define API_DECLARE_DATA
+#elif defined(API_DECLARE_EXPORT)
+#define API_DECLARE(type)            __declspec(dllexport) type __stdcall
+#define API_DECLARE_DATA             __declspec(dllexport)
+#else
+#define API_DECLARE(type)            __declspec(dllimport) type __stdcall
+#define API_DECLARE_DATA             __declspec(dllimport)
+#endif
+
+/*
+ * iconv_t:	charset conversion descriptor type
+ */
+typedef void *iconv_t;
+
+/* __BEGIN_DECLS */
+
+API_DECLARE(apr_status_t) apr_iconv_open(const char *, const char *, apr_pool_t *, iconv_t *);
+API_DECLARE(apr_status_t) apr_iconv(iconv_t, const char **, apr_size_t *, char **, apr_size_t *, apr_size_t *);
+API_DECLARE(apr_status_t) apr_iconv_close(iconv_t, apr_pool_t *);
+
+/* __END_DECLS */
+
+
+#ifdef ICONV_INTERNAL
+
+/*
+ * iconv module types
+ */
+#define	ICMOD_ANY	0
+#define	ICMOD_LIB	1
+#define	ICMOD_UC_CCS	0x100	/* UC - CCS for CES */
+#define	ICMOD_UC_CES	0x101	/* UC - CES */
+
+/*
+ * iconv module flags
+ */
+#define	ICMODF_LOADED	0x8000
+
+/*
+ * iconv module handler events
+ */
+#define	ICMODEV_LOAD	1	/* module load. after dependencies resolved */
+#define	ICMODEV_UNLOAD	2	/* module unload */
+#define	ICMODEV_DYNDEPS	3	/* load dynamic dependencies */
+
+struct iconv_module_depend {
+	int		md_type;
+	const char *	md_name;
+	const void *	md_data;
+};
+
+struct iconv_module;
+
+/* _tbl_simple.c table_load_ccs() calls iconv_mod_load(...ctx) */
+
+typedef int iconv_mod_event_t(struct iconv_module *, int, apr_pool_t *ctx);
+
+struct iconv_module_desc {
+	int		imd_type;
+	iconv_mod_event_t *imd_event;
+	const struct iconv_module_depend *imd_depend;
+	const void *	imd_data;
+};
+
+#define	ICONV_MODULE(type,data)	struct iconv_module_desc iconv_module \
+				    {(type), (data)}
+
+struct iconv_module {
+	int		im_flags;
+	void *		im_handle;
+	struct iconv_module_desc *im_desc;
+	struct iconv_module *im_next;
+	struct iconv_module *im_deplist;
+	int		im_depcnt;
+	const void *	im_methods;
+	void *		im_data;
+	const void *	im_depdata;	/* data if module loaded from dependency */
+	const void *	im_args;
+};
+
+#define	ICONV_MOD_LOAD(mod,ctx)	(mod)->im_desc->imd_event(mod, ICMODEV_LOAD,ctx)
+#define	ICONV_MOD_UNLOAD(mod,ctx)	(mod)->im_desc->imd_event(mod, ICMODEV_UNLOAD,ctx)
+#define	ICONV_MOD_DYNDEPS(mod,ctx)	(mod)->im_desc->imd_event(mod, ICMODEV_DYNDEPS,ctx)
+
+/*
+ * iconv converter definitions.
+ */
+typedef int iconv_open_t(const char *, const char *, void **, apr_pool_t *);
+typedef int iconv_close_t(void *, apr_pool_t *);
+typedef apr_status_t iconv_conv_t(void *, const unsigned char **, apr_size_t *,
+	unsigned char **, apr_size_t *, apr_size_t *);
+
+struct iconv_converter_desc {
+	iconv_open_t *	icd_open;
+	iconv_close_t *	icd_close;
+	iconv_conv_t *	icd_conv;
+};
+
+struct iconv_converter {
+	struct iconv_converter_desc *ic_desc;
+	void *		ic_data;
+};
+
+/*
+ * internal data types and functions used by charset conversion modules
+ */
+
+#define UCS_CHAR_ZERO_WIDTH_NBSP 0xFEFF
+#define UCS_CHAR_INVALID	 0xFFFE
+#define UCS_CHAR_NONE		 0xFFFF
+
+typedef apr_uint16_t ucs2_t;	/* Unicode character [D5] */
+typedef apr_uint32_t ucs4_t;	/* Unicode scalar character [D28] */
+#define ucs_t    ucs4_t
+
+/*
+ * one-level coded character set conversion tables
+ */
+typedef struct {
+	apr_uint16_t	data[128];
+} iconv_ccs_convtable_7bit;	/* 7-bit charset to Unicode */
+
+typedef struct {
+	apr_uint16_t	data[256];
+} iconv_ccs_convtable_8bit;	/* 8-bit charset to Unicode */
+
+/*
+ * two-level coded character set conversion tables
+ */
+typedef struct {
+	const iconv_ccs_convtable_7bit	*data[128];
+} iconv_ccs_convtable_14bit;	/* 14-bit charset to Unicode */
+
+typedef struct {
+	const iconv_ccs_convtable_8bit	*data[256];
+} iconv_ccs_convtable_16bit;	/* 16-bit charset to Unicode;
+				 * Unicode to any charset */
+
+/*
+ * abstract coded character set conversion table
+ */
+typedef union {
+	iconv_ccs_convtable_7bit	_7bit;
+	iconv_ccs_convtable_8bit	_8bit;
+	iconv_ccs_convtable_14bit	_14bit;
+	iconv_ccs_convtable_16bit	_16bit;
+} iconv_ccs_convtable;
+
+/*
+ * function for table-driven conversion
+ */
+typedef ucs2_t iconv_ccs_converter_t (ucs2_t ch);
+
+/*
+ * charset conversion module descriptor
+ */
+struct iconv_ccs_desc {
+	const char * const *		names;
+	int				nbits;
+	const iconv_ccs_convtable *	from_ucs;
+	const iconv_ccs_convtable *	to_ucs;
+	iconv_ccs_converter_t *		convert_from_ucs;
+	iconv_ccs_converter_t *		convert_to_ucs;
+};
+
+/*
+ * inline functions for use in charset conversion modules
+ */
+static APR_INLINE ucs2_t
+iconv_ccs_convert_7bit(const iconv_ccs_convtable *table, ucs2_t ch)
+{
+	return ch & 0x80 ? UCS_CHAR_INVALID : table->_7bit.data[ch];
+}
+
+static APR_INLINE ucs2_t
+iconv_ccs_convert_8bit(const iconv_ccs_convtable *table, ucs2_t ch)
+{
+	return table->_8bit.data[ch];
+}
+
+static APR_INLINE ucs2_t
+iconv_ccs_convert_14bit(const iconv_ccs_convtable *table, ucs2_t ch)
+{
+	const iconv_ccs_convtable_7bit *sub_table;
+
+	sub_table =  ch & 0x8080 ? NULL : table->_14bit.data[ch >> 8];
+	return sub_table ? sub_table->data[ch & 0x7F] : UCS_CHAR_INVALID;
+}
+
+static APR_INLINE ucs2_t
+iconv_ccs_convert_16bit(const iconv_ccs_convtable *table, ucs2_t ch)
+{
+	const iconv_ccs_convtable_8bit *sub_table;
+
+	sub_table = table->_16bit.data[ch >> 8];
+	return sub_table ? sub_table->data[ch & 0xFF] : UCS_CHAR_INVALID;
+}
+
+#define ICONV_CCS_CONVERT_FROM_UCS(ccsd, ch) \
+        ((ccsd)->convert_from_ucs(ch))
+#define ICONV_CCS_CONVERT_TO_UCS(ccsd, ch) \
+        ((ccsd)->convert_to_ucs(ch))
+
+/*
+ * generic character encoding schemes and functions
+ */
+struct iconv_ces;
+
+typedef int  iconv_ces_open_t(struct iconv_ces *, apr_pool_t *);
+typedef	int  iconv_ces_close_t(struct iconv_ces *);
+typedef	void iconv_ces_reset_t(struct iconv_ces *);
+typedef	const char * const *iconv_ces_names_t(struct iconv_ces *);
+typedef	int  iconv_ces_nbits_t(struct iconv_ces *);
+typedef	int  iconv_ces_nbytes_t(struct iconv_ces *);
+
+typedef apr_ssize_t iconv_ces_convert_from_ucs_t
+    (struct iconv_ces *data, ucs_t in,
+    unsigned char **outbuf, apr_size_t *outbytesleft);
+
+typedef ucs_t iconv_ces_convert_to_ucs_t
+    (struct iconv_ces *data,
+    const unsigned char **inbuf, apr_size_t *inbytesleft);
+
+struct iconv_ces_desc {
+	iconv_ces_open_t *	open;
+	iconv_ces_close_t *	close;
+	iconv_ces_reset_t *	reset;
+	iconv_ces_names_t *	names;
+	iconv_ces_nbits_t *	nbits;
+	iconv_ces_nbytes_t *	nbytes;
+	iconv_ces_convert_from_ucs_t * convert_from_ucs;
+	iconv_ces_convert_to_ucs_t * convert_to_ucs;
+	const void *data;
+};
+
+struct iconv_ces {
+	struct iconv_ces_desc *	desc;
+	void *			data;
+	struct iconv_module *	mod;
+};
+
+int  iconv_ces_open(const char *ces_name, struct iconv_ces **cespp, apr_pool_t *ctx);
+int  iconv_ces_close(struct iconv_ces *ces, apr_pool_t *ctx);
+int  iconv_ces_open_func(struct iconv_ces *ces);
+int  iconv_ces_close_func(struct iconv_ces *ces);
+void iconv_ces_reset_func(struct iconv_ces *ces);
+void iconv_ces_no_func(struct iconv_ces *ces);
+int  iconv_ces_nbits7(struct iconv_ces *ces);
+int  iconv_ces_nbits8(struct iconv_ces *ces);
+int  iconv_ces_zero(struct iconv_ces *ces);
+
+#define iconv_char32bit(ch)	((ch) & 0xFFFF0000)
+
+#define	ICONV_CES_OPEN(ces,ctx)	(ces)->desc->open(ces,ctx)
+#define	ICONV_CES_CLOSE(ces)	(ces)->desc->close(ces)
+#define ICONV_CES_RESET(ces)	(ces)->desc->reset(ces)
+#define ICONV_CES_CONVERT_FROM_UCS(cesd, in, outbuf, outbytes) \
+	    ((cesd)->desc->convert_from_ucs((cesd), (in), (outbuf), (outbytes)))
+#define ICONV_CES_CONVERT_TO_UCS(cesd, inbuf, inbytes) \
+	    ((cesd)->desc->convert_to_ucs((cesd), (inbuf), (inbytes)))
+
+#define ICONV_CES_DRIVER_DECL(name) \
+		iconv_ces_open_t iconv_##name##_open; \
+		iconv_ces_close_t iconv_##name##_close; \
+		iconv_ces_reset_t iconv_##name##_reset; \
+		iconv_ces_nbits_t iconv_##name##_nbits; \
+		iconv_ces_convert_from_ucs_t iconv_##name##_convert_from_ucs; \
+		iconv_ces_convert_to_ucs_t iconv_##name##_convert_to_ucs
+
+/*
+ ************************************************
+ * EUC character encoding schemes and functions *
+ ************************************************
+ */
+
+typedef struct iconv_ces_euc_ccs {
+	const char	*prefix;
+	apr_size_t		prefixlen;
+} iconv_ces_euc_ccs_t;
+
+ICONV_CES_DRIVER_DECL(euc);
+
+/*
+ * ISO-2022 character encoding schemes and functions
+ */
+enum { ICONV_SHIFT_SI = 0, ICONV_SHIFT_SO, ICONV_SHIFT_SS2, ICONV_SHIFT_SS3 };
+
+typedef struct iconv_ces_iso2022_ccs {
+	int		shift;
+	const char *	designator;
+	apr_size_t		designatorlen;
+} iconv_ces_iso2022_ccs_t;
+
+typedef struct {
+	const int *	shift_tab;
+	int		nccs;
+	const struct iconv_ces_iso2022_ccs *ccs;
+} iconv_ces_iso2022_data;
+
+ICONV_CES_DRIVER_DECL(iso2022);
+
+
+int  iconv_mod_load(const char *, int, const void *, struct iconv_module **, apr_pool_t *);
+int  iconv_mod_unload(struct iconv_module *,apr_pool_t *ctx);
+iconv_mod_event_t iconv_mod_noevent;
+
+iconv_mod_event_t iconv_ccs_event;
+
+int  iconv_malloc(apr_size_t size, void **pp);
+
+extern struct iconv_converter_desc iconv_uc_desc;
+
+#endif /* ICONV_INTERNAL */
+
+#endif /* _ICONV_H_ */
diff --git a/lib/.cvsignore b/lib/.cvsignore
new file mode 100644
index 0000000..e4614ad
--- /dev/null
+++ b/lib/.cvsignore
@@ -0,0 +1,7 @@
+.libs
+*.la
+*.lo
+*.slo
+apriconv.exports
+apr_iconv_private.h.in
+apr_iconv_private.h
diff --git a/lib/Makefile.in b/lib/Makefile.in
new file mode 100644
index 0000000..75f8700
--- /dev/null
+++ b/lib/Makefile.in
@@ -0,0 +1,14 @@
+# Generated automatically from Makefile.in by configure.
+libdir = /usr/local/lib
+TARGET_LIB = libapriconv.la
+TARGET_EXPORTS = apriconv.exports
+OBJECTS=        iconv_module.lo iconv.lo iconv_int.lo iconv_uc.lo \
+                iconv_ces.lo iconv_ces_euc.lo iconv_ces_iso2022.lo
+
+$(TARGET_LIB):	$(OBJECTS)
+	$(LINK) -rpath $(libdir) $(OBJECTS)                                     
+
+all:		$(TARGET_LIB)
+ 
+# bring in rules.mk for standard functionality                                  
+@INCLUDE_RULES@
diff --git a/lib/Makefile.new b/lib/Makefile.new
new file mode 100644
index 0000000..b999b47
--- /dev/null
+++ b/lib/Makefile.new
@@ -0,0 +1,24 @@
+LIB=		iconv
+SHLIB_MAJOR=	1
+SHLIB_MINOR=	0
+SRCS=		iconv_module.c iconv.c iconv_int.c iconv_uc.c \
+		iconv_ces.c iconv_ces_euc.c iconv_ces_iso2022.c
+
+LIBDIR=		${PREFIX}/lib
+
+INCDIR=		${PREFIX}/include
+INCS=		iconv.h
+
+CFLAGS+=	-DICONV_DEFAULT_PATH=\"${MODULEDIR}\"
+MAN3=		iconv.3 iconv_open.3 iconv_close.3
+
+iconv.3:	iconv.3.in
+		sed "s|@@MODULE_DIR@@|${MODULEDIR}|" ${.ALLSRC} > ${.TARGET}
+
+iconv_open.3:	iconv_open.3.in
+		sed "s|@@MODULE_DIR@@|${MODULEDIR}|" ${.ALLSRC} > ${.TARGET}
+
+CLEANFILES=	lib${LIB}.a ${SHLIB_NAME} ${SHLIB_LINK} ${SOBJS} ${OBJS} \
+		iconv.3 iconv_open.3
+
+.include <bsd.lib.mk>
diff --git a/lib/iconv.c b/lib/iconv.c
index d703f18..839bce0 100644
--- a/lib/iconv.c
+++ b/lib/iconv.c
@@ -30,13 +30,13 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>	/* warnx */
-#include <errno.h>	/* errno */
+#ifndef HAVE_ICONV
+
 #include <stdlib.h>	/* free, malloc */
 #include <string.h>
 
 #define ICONV_INTERNAL
-#include <iconv.h>
+#include "iconv.h"
 
 static struct iconv_converter_desc *converters[] = {
 	&iconv_uc_desc,		/* CS1-UNICODE-CS2 converter */
@@ -44,71 +44,105 @@
 	NULL
 };
 
-size_t
-iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
-	char **outbuf, size_t *outbytesleft)
+/* 
+ * apr_size_t *result is what the iconv() returns but it is cleaner to return
+ * a status.
+ * APR_EBADF:   cd is not valid.
+ * APR_BADARG: The ouput arguments are not valid.
+ */
+
+API_DECLARE(apr_status_t)
+apr_iconv(iconv_t cd, const char **inbuf, apr_size_t *inbytesleft,
+	char **outbuf, apr_size_t *outbytesleft, apr_size_t *result)
 {
 	struct iconv_converter *icp = (struct iconv_converter *)cd;
-	ssize_t res = -1;
 
 	if (icp == NULL) {
-		iconv_warnx("iconv: invalid open conversion descriptor");
-		errno = EBADF;
-		return (size_t)(-1);
+		*result = (apr_size_t) -1;
+		return(APR_EBADF);
 	}
 	if (outbytesleft == NULL || *outbytesleft == 0 ||
 	    outbuf == NULL || *outbuf == 0) {
-		iconv_warnx("iconv: lack of space in the output buffer");
-		errno = E2BIG;
-		return (size_t)(-1);
+		*result = (apr_size_t) -1;
+		return(APR_BADARG);
 	}
-	res = icp->ic_desc->icd_conv(icp->ic_data,
+	return ( icp->ic_desc->icd_conv(icp->ic_data,
 	    (const unsigned char**)inbuf, inbytesleft,
-	    (unsigned char**)outbuf, outbytesleft);
-	return (size_t)res;
+	    (unsigned char**)outbuf, outbytesleft, result));
 }
 
-iconv_t
-iconv_open(const char *to, const char *from)
+API_DECLARE(apr_status_t)
+apr_iconv_open(const char *to, const char *from, apr_pool_t *ctx, iconv_t *res)
 {
 	struct iconv_converter_desc **idesc;
 	struct iconv_converter *icp;
 	void *data;
-	int error;
+	apr_status_t error;
 
+	*res = (iconv_t)-1;
 	icp = malloc(sizeof(*icp));
 	if (icp == NULL)
-		return (iconv_t)(-1);
-	error = EINVAL;
+		return (APR_ENOMEM);
+	error = APR_EINVAL;
 	for (idesc = converters; *idesc; idesc++) {
-		error = (*idesc)->icd_open(to, from, &data);
-		if (error == 0)
+		error = (*idesc)->icd_open(to, from, &data, ctx);
+		if (error == APR_SUCCESS)
 			break;
 	}
 	if (error) {
 		free(icp);
-		errno = error;
-		return (iconv_t)(-1);
+		return (error);
 	}
 	icp->ic_desc = *idesc;
 	icp->ic_data = data;
-	return (iconv_t)icp;
+	*res = icp;
+	return(APR_SUCCESS);
 }
 
-int
-iconv_close(iconv_t cd)
+API_DECLARE(apr_status_t)
+apr_iconv_close(iconv_t cd, apr_pool_t *ctx)
 {
 	struct iconv_converter *icp = (struct iconv_converter *)cd;
 	int error = 0;
 
-	if (icp == NULL) {
-		iconv_warnx("iconv_close: invalid handle");
-		errno = EBADF;
-		return -1;
-	}
+	if (icp == NULL)
+		return(APR_EBADF);
+
 	if (icp->ic_desc)
-		error = icp->ic_desc->icd_close(icp->ic_data);
+		error = icp->ic_desc->icd_close(icp->ic_data, ctx);
 		
 	free(icp);
 	return error;
 }
+
+#else
+
+#include <iconv.h>
+
+apr_status_t apr_iconv_open(const char *to_charset,
+            const char *from_charset, apr_pool_t *ctx, iconv_t **res)
+{
+	*res = iconv_open(to_charset, from_charset);
+	if (*res == (apr_size_t) -1)
+		return apr_get_os_error();
+	return APR_SUCCESS;
+}
+
+apr_status_t apr_iconv(iconv_t cd, const char **inbuf,
+            apr_size_t *inbytesleft, char **outbuf,
+            apr_size_t *outbytesleft, apr_size_t *result)
+{
+	*result = iconv(cd , inbuf, inbytesleft, outbuf, outbytesleft);
+	if (*result == (apr_size_t) -1)
+		return apr_get_os_error();
+	return APR_SUCCESS;
+}
+apr_status_t apr_iconv_close(iconv_t cd)
+{
+	int status;
+	if (iconv_close(cd))
+		return apr_get_os_error();
+	return APR_SUCCESS;
+}
+
+#endif /* !defined(HAVE_ICONV) */
diff --git a/lib/iconv.h b/lib/iconv.h
index ae963d2..35d8ad2 100644
--- a/lib/iconv.h
+++ b/lib/iconv.h
@@ -32,21 +32,74 @@
 #ifndef _ICONV_H_
 #define _ICONV_H_
 
-#include <sys/types.h>	/* size_t */
-#include <stddef.h>	/* NULL */
+#include "apr.h"
+#include "apr_pools.h"
+#ifdef WIN32
+#define ICONV_DEFAULT_PATH "iconv"
+#else
+#include "apr_iconv_private.h" /* contains ICONV_DEFAULT_PATH */
+#endif
+
+#include <stddef.h>
+
+/* apr additions */
+#define issetugid() 0
+/* apr additions */
+
+/**
+ * APR_DECLARE_EXPORT is defined when building the APR dynamic library,
+ * so that all public symbols are exported.
+ *
+ * APR_DECLARE_STATIC is defined when including the APR public headers,
+ * to provide static linkage when the dynamic library may be unavailable.
+ *
+ * APR_DECLARE_STATIC and APR_DECLARE_EXPORT are left undefined when
+ * including the APR public headers, to import and link the symbols from the 
+ * dynamic APR library and assure appropriate indirection and calling 
+ * conventions at compile time.
+ */
+
+#if !defined(WIN32)
+/**
+ * The public APR functions are declared with APR_DECLARE(), so they may
+ * use the most appropriate calling convention.  Public APR functions with 
+ * variable arguments must use APR_DECLARE_NONSTD().
+ *
+ * @deffunc APR_DECLARE(rettype) apr_func(args);
+ */
+#define API_DECLARE(type)            type
+/**
+ * The public APR variables are declared with AP_MODULE_DECLARE_DATA.
+ * This assures the appropriate indirection is invoked at compile time.
+ *
+ * @deffunc APR_DECLARE_DATA type apr_variable;
+ * @tip extern APR_DECLARE_DATA type apr_variable; syntax is required for
+ * declarations within headers to properly import the variable.
+ */
+#define API_DECLARE_DATA
+#elif defined(API_DECLARE_STATIC)
+#define API_DECLARE(type)            type __stdcall
+#define API_DECLARE_DATA
+#elif defined(API_DECLARE_EXPORT)
+#define API_DECLARE(type)            __declspec(dllexport) type __stdcall
+#define API_DECLARE_DATA             __declspec(dllexport)
+#else
+#define API_DECLARE(type)            __declspec(dllimport) type __stdcall
+#define API_DECLARE_DATA             __declspec(dllimport)
+#endif
 
 /*
  * iconv_t:	charset conversion descriptor type
  */
 typedef void *iconv_t;
 
-__BEGIN_DECLS
+/* __BEGIN_DECLS */
 
-iconv_t	iconv_open(const char *, const char *);
-size_t	iconv(iconv_t, const char **, size_t *, char **, size_t *);
-int	iconv_close(iconv_t);
+API_DECLARE(apr_status_t) apr_iconv_open(const char *, const char *, apr_pool_t *, iconv_t *);
+API_DECLARE(apr_status_t) apr_iconv(iconv_t, const char **, apr_size_t *, char **, apr_size_t *, apr_size_t *);
+API_DECLARE(apr_status_t) apr_iconv_close(iconv_t, apr_pool_t *);
 
-__END_DECLS
+/* __END_DECLS */
 
 
 #ifdef ICONV_INTERNAL
@@ -79,7 +132,9 @@
 
 struct iconv_module;
 
-typedef int iconv_mod_event_t(struct iconv_module *, int);
+/* _tbl_simple.c table_load_ccs() calls iconv_mod_load(...ctx) */
+
+typedef int iconv_mod_event_t(struct iconv_module *, int, apr_pool_t *ctx);
 
 struct iconv_module_desc {
 	int		imd_type;
@@ -104,17 +159,17 @@
 	const void *	im_args;
 };
 
-#define	ICONV_MOD_LOAD(mod)	(mod)->im_desc->imd_event(mod, ICMODEV_LOAD)
-#define	ICONV_MOD_UNLOAD(mod)	(mod)->im_desc->imd_event(mod, ICMODEV_UNLOAD)
-#define	ICONV_MOD_DYNDEPS(mod)	(mod)->im_desc->imd_event(mod, ICMODEV_DYNDEPS)
+#define	ICONV_MOD_LOAD(mod,ctx)	(mod)->im_desc->imd_event(mod, ICMODEV_LOAD,ctx)
+#define	ICONV_MOD_UNLOAD(mod,ctx)	(mod)->im_desc->imd_event(mod, ICMODEV_UNLOAD,ctx)
+#define	ICONV_MOD_DYNDEPS(mod,ctx)	(mod)->im_desc->imd_event(mod, ICMODEV_DYNDEPS,ctx)
 
 /*
  * iconv converter definitions.
  */
-typedef int iconv_open_t(const char *, const char *, void **);
-typedef int iconv_close_t(void *);
-typedef size_t iconv_conv_t(void *, const unsigned char **, size_t *,
-	unsigned char **, size_t *);
+typedef int iconv_open_t(const char *, const char *, void **, apr_pool_t *);
+typedef int iconv_close_t(void *, apr_pool_t *);
+typedef apr_status_t iconv_conv_t(void *, const unsigned char **, apr_size_t *,
+	unsigned char **, apr_size_t *, apr_size_t *);
 
 struct iconv_converter_desc {
 	iconv_open_t *	icd_open;
@@ -135,19 +190,19 @@
 #define UCS_CHAR_INVALID	 0xFFFE
 #define UCS_CHAR_NONE		 0xFFFF
 
-typedef uint16_t ucs2_t;	/* Unicode character [D5] */
-typedef uint32_t ucs4_t;	/* Unicode scalar character [D28] */
+typedef apr_uint16_t ucs2_t;	/* Unicode character [D5] */
+typedef apr_uint32_t ucs4_t;	/* Unicode scalar character [D28] */
 #define ucs_t    ucs4_t
 
 /*
  * one-level coded character set conversion tables
  */
 typedef struct {
-	uint16_t	data[128];
+	apr_uint16_t	data[128];
 } iconv_ccs_convtable_7bit;	/* 7-bit charset to Unicode */
 
 typedef struct {
-	uint16_t	data[256];
+	apr_uint16_t	data[256];
 } iconv_ccs_convtable_8bit;	/* 8-bit charset to Unicode */
 
 /*
@@ -192,19 +247,19 @@
 /*
  * inline functions for use in charset conversion modules
  */
-static __inline ucs2_t
+static APR_INLINE ucs2_t
 iconv_ccs_convert_7bit(const iconv_ccs_convtable *table, ucs2_t ch)
 {
 	return ch & 0x80 ? UCS_CHAR_INVALID : table->_7bit.data[ch];
 }
 
-static __inline ucs2_t
+static APR_INLINE ucs2_t
 iconv_ccs_convert_8bit(const iconv_ccs_convtable *table, ucs2_t ch)
 {
 	return table->_8bit.data[ch];
 }
 
-static __inline ucs2_t
+static APR_INLINE ucs2_t
 iconv_ccs_convert_14bit(const iconv_ccs_convtable *table, ucs2_t ch)
 {
 	const iconv_ccs_convtable_7bit *sub_table;
@@ -213,7 +268,7 @@
 	return sub_table ? sub_table->data[ch & 0x7F] : UCS_CHAR_INVALID;
 }
 
-static __inline ucs2_t
+static APR_INLINE ucs2_t
 iconv_ccs_convert_16bit(const iconv_ccs_convtable *table, ucs2_t ch)
 {
 	const iconv_ccs_convtable_8bit *sub_table;
@@ -232,20 +287,20 @@
  */
 struct iconv_ces;
 
-typedef int  iconv_ces_open_t(struct iconv_ces *);
+typedef int  iconv_ces_open_t(struct iconv_ces *, apr_pool_t *);
 typedef	int  iconv_ces_close_t(struct iconv_ces *);
 typedef	void iconv_ces_reset_t(struct iconv_ces *);
 typedef	const char * const *iconv_ces_names_t(struct iconv_ces *);
 typedef	int  iconv_ces_nbits_t(struct iconv_ces *);
 typedef	int  iconv_ces_nbytes_t(struct iconv_ces *);
 
-typedef ssize_t iconv_ces_convert_from_ucs_t
+typedef apr_ssize_t iconv_ces_convert_from_ucs_t
     (struct iconv_ces *data, ucs_t in,
-    unsigned char **outbuf, size_t *outbytesleft);
+    unsigned char **outbuf, apr_size_t *outbytesleft);
 
 typedef ucs_t iconv_ces_convert_to_ucs_t
     (struct iconv_ces *data,
-    const unsigned char **inbuf, size_t *inbytesleft);
+    const unsigned char **inbuf, apr_size_t *inbytesleft);
 
 struct iconv_ces_desc {
 	iconv_ces_open_t *	open;
@@ -265,8 +320,8 @@
 	struct iconv_module *	mod;
 };
 
-int  iconv_ces_open(const char *ces_name, struct iconv_ces **cespp);
-int  iconv_ces_close(struct iconv_ces *ces);
+int  iconv_ces_open(const char *ces_name, struct iconv_ces **cespp, apr_pool_t *ctx);
+int  iconv_ces_close(struct iconv_ces *ces, apr_pool_t *ctx);
 int  iconv_ces_open_func(struct iconv_ces *ces);
 int  iconv_ces_close_func(struct iconv_ces *ces);
 void iconv_ces_reset_func(struct iconv_ces *ces);
@@ -277,7 +332,7 @@
 
 #define iconv_char32bit(ch)	((ch) & 0xFFFF0000)
 
-#define	ICONV_CES_OPEN(ces)	(ces)->desc->open(ces)
+#define	ICONV_CES_OPEN(ces,ctx)	(ces)->desc->open(ces,ctx)
 #define	ICONV_CES_CLOSE(ces)	(ces)->desc->close(ces)
 #define ICONV_CES_RESET(ces)	(ces)->desc->reset(ces)
 #define ICONV_CES_CONVERT_FROM_UCS(cesd, in, outbuf, outbytes) \
@@ -301,7 +356,7 @@
 
 typedef struct iconv_ces_euc_ccs {
 	const char	*prefix;
-	size_t		prefixlen;
+	apr_size_t		prefixlen;
 } iconv_ces_euc_ccs_t;
 
 ICONV_CES_DRIVER_DECL(euc);
@@ -314,7 +369,7 @@
 typedef struct iconv_ces_iso2022_ccs {
 	int		shift;
 	const char *	designator;
-	size_t		designatorlen;
+	apr_size_t		designatorlen;
 } iconv_ces_iso2022_ccs_t;
 
 typedef struct {
@@ -326,26 +381,13 @@
 ICONV_CES_DRIVER_DECL(iso2022);
 
 
-#ifdef ICONV_DEBUG
-void iconv_debug(const char *file, int line, const char *function,
-	const char *format, ...);
-#define idebug(format, args...) \
-		iconv_debug(__FILE__, __LINE__, __FUNCTION__, format , ## args)
-#include <err.h>
-#define iconv_warnx(format, args...) \
-		warnx(__FUNCTION__ # format , ## args)
-#else
-#define idebug(format, args...)
-#define iconv_warnx(format, args...)
-#endif
-
-int  iconv_mod_load(const char *, int, const void *, struct iconv_module **);
-int  iconv_mod_unload(struct iconv_module *);
+int  iconv_mod_load(const char *, int, const void *, struct iconv_module **, apr_pool_t *);
+int  iconv_mod_unload(struct iconv_module *,apr_pool_t *ctx);
 iconv_mod_event_t iconv_mod_noevent;
 
 iconv_mod_event_t iconv_ccs_event;
 
-int  iconv_malloc(size_t size, void **pp);
+int  iconv_malloc(apr_size_t size, void **pp);
 
 extern struct iconv_converter_desc iconv_uc_desc;
 
diff --git a/lib/iconv_ccs.c b/lib/iconv_ccs.c
index 3cbcdf5..cebb13b 100644
--- a/lib/iconv_ccs.c
+++ b/lib/iconv_ccs.c
@@ -30,16 +30,11 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>	/* warnx */
-#include <errno.h>	/* errno */
-#include <stdlib.h>	/* free, malloc */
-#include <string.h>
-
 #define ICONV_INTERNAL
-#include <iconv.h>	/* iconv_ccs_desc, iconv_ccs_module */
+#include "iconv.h"	/* iconv_ccs_desc, iconv_ccs_module */
 
-int
-iconv_ccs_event(struct iconv_module *mod, int event)
+apr_status_t
+iconv_ccs_event(struct iconv_module *mod, int event, apr_pool_t *ctx)
 {
 /*	struct iconv_ccs_desc *desc =
 	    (struct iconv_ccs_desc *)mod->im_desc->imd_data;*/
@@ -47,14 +42,14 @@
 	switch (event) {
 	    case ICMODEV_LOAD:
 		if (mod->im_deplist == NULL)
-			return EINVAL;
+			return APR_EINVAL;
 		mod->im_methods = mod->im_deplist->im_desc->imd_data;
 		mod->im_data = mod->im_desc->imd_data;
 		break;
 	    case ICMODEV_UNLOAD:
 		break;
 	    default:
-		return EINVAL;
+		return APR_EINVAL;
 	}
-	return 0;
+	return APR_SUCCESS;
 }
diff --git a/lib/iconv_ces.c b/lib/iconv_ces.c
index 590249f..cac600a 100644
--- a/lib/iconv_ces.c
+++ b/lib/iconv_ces.c
@@ -30,48 +30,46 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>	/* warnx */
-#include <errno.h>	/* errno */
 #include <limits.h>	/* PATH_MAX */
 #include <stdlib.h>	/* free, malloc */
 #include <string.h>
 
 #define ICONV_INTERNAL
-#include <iconv.h>	/* iconv_ccs_desc, iconv_ccs */
+#include "iconv.h"	/* iconv_ccs_desc, iconv_ccs */
 
-int
-iconv_ces_open(const char *cesname, struct iconv_ces **cespp)
+apr_status_t
+iconv_ces_open(const char *cesname, struct iconv_ces **cespp, apr_pool_t *ctx)
 {
 	struct iconv_module *mod;
 	struct iconv_ces *ces;
-	int error;
+	apr_status_t error;
 
-	error = iconv_mod_load(cesname, ICMOD_UC_CES, NULL, &mod);
-	if (error == EFTYPE)
-		error = iconv_mod_load("_tbl_simple", ICMOD_UC_CES, cesname, &mod);
-	if (error)
-		return (error == EFTYPE) ? EINVAL : error;
+	error = iconv_mod_load(cesname, ICMOD_UC_CES, NULL, &mod, ctx);
+	if (APR_STATUS_IS_EFTYPE(error))
+		error = iconv_mod_load("_tbl_simple", ICMOD_UC_CES, cesname, &mod, ctx);
+	if (error != APR_SUCCESS)
+		return (APR_STATUS_IS_EFTYPE(error)) ? APR_EINVAL : error;
 	ces = malloc(sizeof(*ces));
 	if (ces == NULL) {
-		iconv_mod_unload(mod);
-		return ENOMEM;
+		iconv_mod_unload(mod, ctx);
+		return APR_ENOMEM;
 	}
-	bzero(ces, sizeof(*ces));
+	memset(ces,0, sizeof(*ces));
 	ces->desc = (struct iconv_ces_desc*)mod->im_desc->imd_data;
 	ces->data = mod->im_data;
 	ces->mod = mod;
-	error = ICONV_CES_OPEN(ces);
-	if (error) {
+	error = ICONV_CES_OPEN(ces,ctx);
+	if (error != APR_SUCCESS) {
 		free(ces);
-		iconv_mod_unload(mod);
+		iconv_mod_unload(mod, ctx);
 		return error;
 	}
 	*cespp = ces;
-	return 0;
+	return APR_SUCCESS;
 }
 
 int
-iconv_ces_close(struct iconv_ces *ces)
+iconv_ces_close(struct iconv_ces *ces, apr_pool_t *ctx)
 {
 	int res;
 
@@ -79,7 +77,7 @@
 		return -1;
 	res = ICONV_CES_CLOSE(ces);
 	if (ces->mod != NULL)
-		iconv_mod_unload(ces->mod);
+		iconv_mod_unload(ces->mod, ctx);
 	free(ces);
 	return res;
 }
@@ -100,7 +98,7 @@
 void
 iconv_ces_reset_func(struct iconv_ces *ces)
 {
-	bzero(ces->data, sizeof(int));
+	memset(ces->data, 0, sizeof(int));
 }
 
 /*ARGSUSED*/
diff --git a/lib/iconv_ces_euc.c b/lib/iconv_ces_euc.c
index 1a137b1..3d29944 100644
--- a/lib/iconv_ces_euc.c
+++ b/lib/iconv_ces_euc.c
@@ -30,12 +30,11 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <errno.h>
 #include <stdlib.h>	/* free, malloc */
 #include <string.h>
 
 #define ICONV_INTERNAL
-#include <iconv.h>
+#include "iconv.h"
 
 #define	CESTOSTATE(ces)		((iconv_ces_euc_state_t *)(ces)->data)
 #define	MODTOCCS(mod)		((struct iconv_ccs_desc *)(mod)->im_desc->imd_data)
@@ -46,46 +45,46 @@
 	const struct iconv_module *ccs[1];
 } iconv_ces_euc_state_t;
 
-int
-iconv_euc_open(struct iconv_ces *ces)
+apr_status_t
+iconv_euc_open(struct iconv_ces *ces, apr_pool_t *ctx)
 {
 	struct iconv_module *depmod = ces->mod->im_deplist;
 	iconv_ces_euc_state_t *state;
-	size_t stsz;
+	apr_size_t stsz;
 	int i;
 
 	stsz = sizeof(iconv_ces_euc_state_t) +
 	    sizeof(struct iconv_module *) * (ces->mod->im_depcnt - 1);
 	state = (iconv_ces_euc_state_t *)malloc(stsz);
 	if (state == NULL)
-		return errno;
-	bzero(state, stsz);
+		return APR_ENOMEM;
+	memset(state, 0, stsz);
 	state->nccs = ces->mod->im_depcnt;
 	for (i = ces->mod->im_depcnt; i; i--, depmod = depmod->im_next)
 		state->ccs[i - 1] = depmod;
 	CESTOSTATE(ces) = state;
-	return 0;
+	return APR_SUCCESS;
 }
 
-int
+apr_status_t
 iconv_euc_close(struct iconv_ces *ces)
 {
 	free(CESTOSTATE(ces));
-	return 0;
+	return APR_SUCCESS;
 }
 
 #define is_7_14bit(data) ((data)->nbits & 7)
 #define is_7bit(data) ((data)->nbits & 1)
 
-ssize_t
+apr_ssize_t
 iconv_euc_convert_from_ucs(struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft)
+	unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	iconv_ces_euc_state_t *euc_state = CESTOSTATE(ces);
 	const iconv_ces_euc_ccs_t *ccsattr;
 	const struct iconv_ccs_desc *ccs;
 	ucs_t res;
-	size_t bytes;
+	apr_size_t bytes;
 	int i;
 
 	if (in == UCS_CHAR_NONE)
@@ -124,9 +123,9 @@
 
 static ucs_t
 cvt2ucs(const struct iconv_ccs_desc *ccs, const unsigned char *inbuf,
-	size_t inbytesleft, int hi_plane, const unsigned char **bufptr)
+	apr_size_t inbytesleft, int hi_plane, const unsigned char **bufptr)
 {
-	size_t bytes = ccs->nbits > 8 ? 2 : 1;
+	apr_size_t bytes = ccs->nbits > 8 ? 2 : 1;
 	ucs_t ch = *(const unsigned char *)inbuf++;
 
 	if (inbytesleft < bytes)
@@ -146,7 +145,7 @@
 
 ucs_t
 iconv_euc_convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	iconv_ces_euc_state_t *euc_state = CESTOSTATE(ces);
 	const iconv_ces_euc_ccs_t *ccsattr;
diff --git a/lib/iconv_ces_iso2022.c b/lib/iconv_ces_iso2022.c
index 9b70519..e085374 100644
--- a/lib/iconv_ces_iso2022.c
+++ b/lib/iconv_ces_iso2022.c
@@ -30,16 +30,15 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <errno.h>
 #include <stdlib.h>	/* free, malloc */
-#include <string.h>	/* bzero, memcmp, memcpy */
+#include <string.h>	/* memset, memcmp, memcpy */
 
 #define ICONV_INTERNAL
-#include <iconv.h>
+#include "iconv.h"
 
 typedef struct {
 	const char	*sequence;
-	size_t		length;
+	apr_size_t	length;
 	int		prefix_type;
 } iconv_ces_iso2022_shift;
 
@@ -67,14 +66,14 @@
 	const struct iconv_module *ccsmod[1];
 } iconv_ces_iso2022_state_t;
 
-int
-iconv_iso2022_open(struct iconv_ces *ces)
+apr_status_t
+iconv_iso2022_open(struct iconv_ces *ces, apr_pool_t *ctx)
 {
 	const iconv_ces_iso2022_ccs_t *ccsattr;
 	const struct iconv_ccs_desc *ccs;
 	iconv_ces_iso2022_state_t *state;
 	struct iconv_module *depmod;
-	size_t stsz, shiftsz;
+	apr_size_t stsz, shiftsz;
 	int i;
 
 	shiftsz = SHIFT_LEN;
@@ -82,8 +81,8 @@
 	    sizeof(struct iconv_module *) * (ces->mod->im_depcnt - 1);
 	state = (iconv_ces_iso2022_state_t *)malloc(stsz + shiftsz);
 	if (state == NULL)
-		return errno;
-	bzero(state, stsz + shiftsz);
+		return APR_ENOMEM;
+	memset(state, 0, stsz + shiftsz);
 	ces->data = state;
 	state->shift_tab = (int*)((char*)state + stsz);
 	state->org_shift_tab = ces->desc->data;
@@ -99,7 +98,7 @@
 		if (ccsattr->shift >= 0)
 			state->prefix[(int)(iso_shift[ccsattr->shift].sequence[0])] = 1;
 	}
-	return 0;
+	return APR_SUCCESS;
 }
 
 int
@@ -129,7 +128,7 @@
 update_shift_state(const struct iconv_ces *ces, ucs_t ch)
 {
 	struct iconv_ces_iso2022_state *iso_state = CESTOSTATE(ces);
-	size_t i;
+	apr_size_t i;
 
 	if (ch == '\n' && iso_state->previous_char == '\r') {
 		for (i = 0; i < shift_num; i ++) {
@@ -142,15 +141,15 @@
 
 #define is_7_14bit(ccs) ((ccs)->nbits & 7)
 
-static ssize_t
+static apr_ssize_t
 cvt_ucs2iso(const struct iconv_ces *ces, ucs_t in,
-	unsigned char **outbuf, size_t *outbytesleft, int cs)
+	unsigned char **outbuf, apr_size_t *outbytesleft, int cs)
 {
 	struct iconv_ces_iso2022_state *iso_state = CESTOSTATE(ces);
 	const struct iconv_ces_iso2022_ccs *ccsattr;
 	const struct iconv_ccs_desc *ccs;
 	ucs_t res;
-	size_t len = 0;
+	apr_size_t len = 0;
 	int need_designator, need_shift;
 
 	ccs = MODTOCCS(iso_state->ccsmod[cs]);
@@ -199,12 +198,12 @@
 	return 1;
 }
 
-ssize_t
+apr_ssize_t
 iconv_iso2022_convert_from_ucs(struct iconv_ces *ces,
-	ucs_t in, unsigned char **outbuf, size_t *outbytesleft)
+	ucs_t in, unsigned char **outbuf, apr_size_t *outbytesleft)
 {
 	struct iconv_ces_iso2022_state *iso_state = CESTOSTATE(ces);
-	ssize_t res;
+	apr_ssize_t res;
 	int cs, i;
 
 	if (in == UCS_CHAR_NONE)
@@ -227,9 +226,9 @@
 
 static ucs_t
 cvt_iso2ucs(const struct iconv_ccs_desc *ccs, const unsigned char **inbuf,
-	size_t *inbytesleft, int prefix_type)
+	apr_size_t *inbytesleft, int prefix_type)
 {
-	size_t bytes = ccs->nbits > 8 ? 2 : 1;
+	apr_size_t bytes = ccs->nbits > 8 ? 2 : 1;
 	ucs_t ch = **inbuf;
 
 	if (*inbytesleft < bytes)
@@ -247,14 +246,14 @@
 
 ucs_t
 iconv_iso2022_convert_to_ucs(struct iconv_ces *ces,
-	const unsigned char **inbuf, size_t *inbytesleft)
+	const unsigned char **inbuf, apr_size_t *inbytesleft)
 {
 	struct iconv_ces_iso2022_state *iso_state = CESTOSTATE(ces);
 	const struct iconv_ces_iso2022_ccs *ccsattr;
 	ucs_t res;
 	const unsigned char *ptr = *inbuf;
 	unsigned char byte;
-	size_t len, left = *inbytesleft;
+	apr_size_t len, left = *inbytesleft;
 	int i;
 
 	while (left) {
diff --git a/lib/iconv_int.c b/lib/iconv_int.c
index 417d356..ad8373d 100644
--- a/lib/iconv_int.c
+++ b/lib/iconv_int.c
@@ -31,24 +31,23 @@
  */
 
 #include <ctype.h>	/* tolower */
-#include <errno.h>	/* errno */
 #include <stdio.h>	/* snprintf */
 #include <stdlib.h>
 #include <string.h>	/* strdup, strlen */
 
 #define ICONV_INTERNAL
-#include <iconv.h>
+#include "iconv.h"
 
-int
-iconv_malloc(size_t size, void **pp)
+apr_status_t
+iconv_malloc(apr_size_t size, void **pp)
 {
 	void *p = malloc(size);
 
 	if (p == NULL)
-		return errno;
-	bzero(p, size);
+		return APR_ENOMEM;
+	memset(p, 0, size);
 	*pp = p;
-	return 0;
+	return APR_SUCCESS;
 }
 
 #ifdef ICONV_DEBUG
diff --git a/lib/iconv_module.c b/lib/iconv_module.c
index f06faee..657ae25 100644
--- a/lib/iconv_module.c
+++ b/lib/iconv_module.c
@@ -28,40 +28,40 @@
  *
  */
 
-#include <sys/types.h>	/* sys/stat.h */
-#include <sys/stat.h>	/* struct stat */
-
-#include <ctype.h>	/* tolower */
-#include <dlfcn.h>
-#include <err.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>	/* snprintf */
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>	/* issetugid */
-
 #define ICONV_INTERNAL
-#include <iconv.h>
 
-static int
-iconv_getpathname(char *buffer, const char *dir, const char *name)
+#include "iconv.h"
+#include "apr_file_io.h"
+#include "apr_pools.h"
+#include "apr_dso.h"
+#include "apr_strings.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+static apr_status_t
+iconv_getpathname(char *buffer, const char *dir, const char *name, apr_pool_t *ctx)
 {
-	struct stat sb;
+        apr_status_t rv;
+	apr_finfo_t sb;
 
-	snprintf(buffer, PATH_MAX, "%s/%s", dir, name);
-	return (stat(buffer, &sb) || ! S_ISREG(sb.st_mode)) ? EINVAL : 0;
+	apr_snprintf(buffer, APR_PATH_MAX, "%s/%s", dir, name);
+        if (rv = apr_stat(&sb, buffer, APR_FINFO_TYPE, ctx))
+            return rv;
+	return ((sb.filetype != APR_REG) ? APR_EINVAL : 0);
 }
 
-static int
-iconv_getpath(char *buf, const char *name)
+static apr_status_t
+iconv_getpath(char *buf, const char *name, apr_pool_t *ctx)
 {
-	char buffer[PATH_MAX];
+	char buffer[APR_PATH_MAX];
 	char *ptr;
 
 	if (tolower(name[0]) == 'x' && name[1] == '-')
 		name += 2;
-	snprintf(buffer, sizeof(buffer), "%s.so", name);
+	apr_snprintf(buffer, sizeof(buffer), "%s.so", name);
 	ptr = buffer + strlen(buffer) - 4 - strlen(name);
 	while (* ++ptr)
 		*ptr = tolower(*ptr);
@@ -73,63 +73,64 @@
 			if (p == NULL)
 				return ENOMEM;
 			for (ptr = p; (dir = strtok(p, ":")); p = NULL) {
-				if (iconv_getpathname(buf, dir, buffer) == 0) {
+				if (iconv_getpathname(buf, dir, buffer, ctx) == 0) {
 					free(ptr);
 					return 0;
 				}
 			}
+			free(ptr); /* otherwise memory leak */
 		}
 	}
-	return iconv_getpathname(buf, ICONV_DEFAULT_PATH, buffer);
+	return iconv_getpathname(buf, ICONV_DEFAULT_PATH, buffer, ctx);
 }
 
 static int
-iconv_dlopen(const char *name, const char *symbol, void **hpp, void **dpp)
+iconv_dlopen(const char *name, const char *symbol, void **hpp, void **dpp, apr_pool_t *ctx)
 {
-	void *handle, *data;
+	apr_dso_handle_t *handle;
+	void *data;
 
-	handle = dlopen(name, RTLD_LAZY);
-	if (handle == NULL) {
-		warnx("cannot dlopen file %s: %s", name, dlerror());
+	/* dlopen */
+	if (apr_dso_load(&handle, name, ctx) != APR_SUCCESS) {
 		return EINVAL;
 	}
-	data = dlsym(handle, symbol);
-	if (data != NULL) {
+	/* dlsym */
+	if ( apr_dso_sym(&data, handle, symbol) == APR_SUCCESS) {
 		*hpp = handle;
 		*dpp = data;
 		return 0;
 	}
-	dlclose(handle);
-	iconv_warnx("invalid file %s: no external symbol %s", name, symbol);
+	apr_dso_unload(handle);
 	return EINVAL;
 }
 
 int
 iconv_mod_load(const char *modname, int modtype, const void *args,
-	struct iconv_module **modpp)
+	struct iconv_module **modpp, apr_pool_t *ctx)
 {
 	struct iconv_module_desc *mdesc;
 	struct iconv_module *mod, *depmod;
 	const struct iconv_module_depend *depend;
-	char buffer[PATH_MAX];
+	char buffer[APR_PATH_MAX];
 	void *handle;
 	int error;
 
-	if (iconv_getpath(buffer, modname) != 0)
+	if (iconv_getpath(buffer, modname, ctx) != 0)
 		return EINVAL;
-	error = iconv_dlopen(buffer, "iconv_module", &handle, (void**)&mdesc);
+
+	error = iconv_dlopen(buffer, "iconv_module", &handle, (void**)&mdesc, ctx);
 	if (error)
 		return error;
 	if (modtype != ICMOD_ANY && mdesc->imd_type != modtype) {
-		dlclose(handle);
-		return EFTYPE;
+		apr_dso_unload(handle);
+		return APR_EFTYPE;
 	}
 	mod = malloc(sizeof(*mod));
 	if (mod == NULL) {
-		dlclose(handle);
+		apr_dso_unload(handle);
 		return ENOMEM;
 	}
-	bzero(mod, sizeof(*mod));
+	memset(mod, 0, sizeof(*mod));
 	mod->im_handle = handle;
 	mod->im_desc = mdesc;
 	mod->im_args = args;
@@ -137,7 +138,7 @@
 	if (depend) {
 		while (depend->md_name) {
 			error = iconv_mod_load(depend->md_name, 
-			    depend->md_type, NULL, &depmod);
+			    depend->md_type, NULL, &depmod, ctx);
 			if (error)
 				goto bad;
 			depmod->im_depdata = depend->md_data;
@@ -146,7 +147,7 @@
 			depend++;
 		}
 	}
-	error = ICONV_MOD_DYNDEPS(mod);
+	error = ICONV_MOD_DYNDEPS(mod,ctx);
 	if (error)
 		goto bad;
 	depmod = mod->im_deplist;
@@ -154,19 +155,19 @@
 		mod->im_depcnt++;
 		depmod = depmod->im_next;
 	}
-	error = ICONV_MOD_LOAD(mod);
+	error = ICONV_MOD_LOAD(mod,ctx);
 	if (error)
 		goto bad;
 	mod->im_flags |= ICMODF_LOADED;
 	*modpp = mod;
 	return 0;
 bad:
-	iconv_mod_unload(mod);
+	iconv_mod_unload(mod,ctx);
 	return error;
 }
 
 int
-iconv_mod_unload(struct iconv_module *mod)
+iconv_mod_unload(struct iconv_module *mod, apr_pool_t *ctx)
 {
 	struct iconv_module *deplist, *tmp;
 	int error = 0;
@@ -174,22 +175,22 @@
 	if (mod == NULL)
 		return -1;
 	if (mod->im_flags & ICMODF_LOADED)
-		error = ICONV_MOD_UNLOAD(mod);
+		error = ICONV_MOD_UNLOAD(mod,ctx);
 	deplist = mod->im_deplist;
 	while (deplist) {
 		tmp = deplist->im_next;
-		iconv_mod_unload(deplist);
+		iconv_mod_unload(deplist,ctx);
 		deplist = tmp;
 	}
 	if (mod->im_handle != NULL)
-		if (dlclose(mod->im_handle) != 0)
+		if (apr_dso_unload(mod->im_handle) != APR_SUCCESS)
 			error = EINVAL;
 	free(mod);
 	return error;
 }
 
 int
-iconv_mod_noevent(struct iconv_module *mod, int event)
+iconv_mod_noevent(struct iconv_module *mod, int event, apr_pool_t *ctx)
 {
 	switch (event) {
 	    case ICMODEV_LOAD:
diff --git a/lib/iconv_uc.c b/lib/iconv_uc.c
index 818844a..5309013 100644
--- a/lib/iconv_uc.c
+++ b/lib/iconv_uc.c
@@ -1,11 +1,9 @@
-#include <err.h>
-#include <errno.h>
+#define ICONV_INTERNAL
+#include "iconv.h"
+
 #include <stdlib.h>
 #include <string.h>
 
-#define ICONV_INTERNAL
-#include <iconv.h>
-
 struct iconv_uc {
 	struct iconv_ces *	from;
 	struct iconv_ces *	to;
@@ -23,86 +21,89 @@
 	iconv_uc_conv
 };
 
-int
-iconv_uc_open(const char *to, const char *from, void **data)
+/*
+ * It is call by apr_iconv_open: (*idesc)->icd_open()
+ */
+apr_status_t
+iconv_uc_open(const char *to, const char *from, void **data, apr_pool_t *ctx)
 {
 	struct iconv_uc *ic;
 	int error;
 
 	ic = malloc(sizeof(*ic));
 	if (ic == NULL)
-		return ENOMEM;
-	bzero(ic, sizeof(*ic));
-	error = iconv_ces_open(from, &ic->from);
-	if (error)
+		return APR_ENOMEM;
+	memset(ic, 0, sizeof(*ic));
+	error = iconv_ces_open(from, &ic->from, ctx);
+	if (error!=APR_SUCCESS) {
 		goto bad;
-	error = iconv_ces_open(to, &ic->to);
-	if (error)
+	}
+	error = iconv_ces_open(to, &ic->to, ctx);
+	if (error!=APR_SUCCESS) {
 		goto bad;
+	}
 	ic->ignore_ilseq = 0;
 	ic->missing = '_';
 	*data = (void*)ic;
-	return 0;
+	return APR_SUCCESS;
 bad:
-	iconv_uc_close(ic);
+	iconv_uc_close(ic,ctx);
 	return error;
 }
 
-int
-iconv_uc_close(void *data)
+apr_status_t
+iconv_uc_close(void *data, apr_pool_t *ctx)
 {
 	struct iconv_uc *ic = (struct iconv_uc *)data;
 
 	if (ic == NULL)
-		return EBADF;
+		return APR_EBADF;
 	if (ic->from)
-		iconv_ces_close(ic->from);
+		iconv_ces_close(ic->from, ctx);
 	if (ic->to)
-		iconv_ces_close(ic->to);
+		iconv_ces_close(ic->to, ctx);
 	free(ic);
-	return 0;
+	return APR_SUCCESS;
 }
 
-size_t
-iconv_uc_conv(void *data, const unsigned char **inbuf, size_t *inbytesleft,
-	unsigned char **outbuf, size_t *outbytesleft)
+apr_status_t
+iconv_uc_conv(void *data, const unsigned char **inbuf, apr_size_t *inbytesleft,
+	unsigned char **outbuf, apr_size_t *outbytesleft, apr_size_t *res)
 {
 	struct iconv_uc *ic = (struct iconv_uc *)data;
 	const unsigned char *ptr;
 	ucs_t ch;
-        ssize_t size;
-	size_t res = 0;
+        apr_ssize_t size;
 
+	*res = (apr_size_t)(0);
 	if (data == NULL) {
-		errno = EBADF;
-		return (size_t)(-1);
+		*res = (apr_size_t) -1;
+		return APR_EBADF;
 	}
+
 	if (inbuf == NULL || *inbuf == NULL) {
 		if (ICONV_CES_CONVERT_FROM_UCS(ic->to, UCS_CHAR_NONE,
 		    outbuf, outbytesleft) <= 0) {
-			errno = E2BIG;
-			return (size_t)(-1);
+			*res = (apr_size_t) -1;
+			return APR_BADARG; /* too big */
 		}
 		ICONV_CES_RESET(ic->from);
 		ICONV_CES_RESET(ic->to);
-		return res;
+		return APR_SUCCESS;
 	}
 	if (inbytesleft == NULL || *inbytesleft == 0)
-		return 0;
+		return APR_SUCCESS;
 	while (*inbytesleft > 0 && *outbytesleft > 0) {
 		ptr = *inbuf;
 		ch = ICONV_CES_CONVERT_TO_UCS(ic->from, inbuf, inbytesleft);
-		if (ch == UCS_CHAR_NONE) {
-			errno = EINVAL;
-			return res;
-		}
+		if (ch == UCS_CHAR_NONE)
+			return APR_EINVAL;
 		if (ch == UCS_CHAR_INVALID) { /* Invalid character in source buffer */
 			if (ic->ignore_ilseq)
 				continue;
 			*inbytesleft += *inbuf - ptr;
 			*inbuf = ptr;
-			errno = EILSEQ;
-			return res;
+			return APR_BADCH; /* eilseq invalid */
 		}
 		size = ICONV_CES_CONVERT_FROM_UCS(ic->to, ch,
 		    outbuf, outbytesleft);
@@ -110,16 +111,15 @@
 			size = ICONV_CES_CONVERT_FROM_UCS(ic->to, ic->missing,
 			    outbuf, outbytesleft);
 			if (size)
-				res ++;
+				*res ++;
 		}
 		if (!size) {		 /* No space to write to */
 			*inbytesleft += *inbuf - ptr;
 			*inbuf = ptr; 
-			errno = E2BIG;
-			return res;
+			return APR_BADARG; /* too big */
 		}
 	}
-	return res;
+	return APR_SUCCESS;
 }
 
 #if 0
diff --git a/libapriconv.dsp b/libapriconv.dsp
new file mode 100644
index 0000000..e6de017
--- /dev/null
+++ b/libapriconv.dsp
@@ -0,0 +1,169 @@
+# Microsoft Developer Studio Project File - Name="libapriconv" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=libapriconv - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "libapriconv.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "libapriconv.mak" CFG="libapriconv - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "libapriconv - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "libapriconv - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "libapriconv - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MD /W3 /O2 /I "../apr/include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "API_DECLARE_EXPORT" /Fd"Release\apriconv" /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD BASE RSC /l 0x409
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib advapi32.lib /nologo /base:"0x6EC0000" /subsystem:windows /dll /map /machine:I386
+# ADD LINK32 kernel32.lib advapi32.lib /nologo /base:"0x6EC0000" /subsystem:windows /dll /map /machine:I386
+
+!ELSEIF  "$(CFG)" == "libapriconv - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /Zi /Od /I "../apr/include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "API_DECLARE_EXPORT" /Fd"Debug\apriconv" /FD /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib advapi32.lib /nologo /base:"0x6EC0000" /subsystem:windows /dll /incremental:no /map /debug /machine:I386
+# ADD LINK32 kernel32.lib advapi32.lib /nologo /base:"0x6EC00000" /subsystem:windows /dll /incremental:no /map /debug /machine:I386
+
+!ENDIF 
+
+# Begin Target
+
+# Name "libapriconv - Win32 Release"
+# Name "libapriconv - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter ".c"
+# Begin Group "lib"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\lib\iconv.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_ces.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_ces_euc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_ces_iso2022.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_int.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_module.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lib\iconv_uc.c
+# End Source File
+# End Group
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter ".h"
+# Begin Source File
+
+SOURCE=.\lib\iconv.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\libapriconv.rc
+# End Source File
+# Begin Source File
+
+SOURCE=..\apr\build\win32ver.awk
+
+!IF  "$(CFG)" == "libapriconv - Win32 Release"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Creating Version Resource
+InputPath=..\apr\build\win32ver.awk
+
+".\libapriconv.rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+	awk -f ../apr/build/win32ver.awk libapriconv "Apache APR I18N Conversion Library"  ../../include/ap_release.h > .\libapriconv.rc
+
+# End Custom Build
+
+!ELSEIF  "$(CFG)" == "libapriconv - Win32 Debug"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Creating Version Resource
+InputPath=..\apr\build\win32ver.awk
+
+".\libapriconv.rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+	awk -f ../apr/build/win32ver.awk libapriconv "Apache APR I18N Conversion Library"  ../../include/ap_release.h > .\libapriconv.rc
+
+# End Custom Build
+
+!ENDIF 
+
+# End Source File
+# End Target
+# End Project
diff --git a/util/.cvsignore b/util/.cvsignore
new file mode 100644
index 0000000..97ec5c8
--- /dev/null
+++ b/util/.cvsignore
@@ -0,0 +1,3 @@
+.libs
+*.lo
+iconv                                                                    
diff --git a/util/Makefile.in b/util/Makefile.in
new file mode 100644
index 0000000..fd6a9ed
--- /dev/null
+++ b/util/Makefile.in
@@ -0,0 +1,13 @@
+TARGETS  =
+PROGRAMS = iconv
+
+# bring in rules.mk for standard functionality                                  
+@INCLUDE_RULES@
+
+all: $(PROGRAMS)
+
+iconv_OBJECTS = iconv.lo iconv_stream.lo
+iconv_LDADD   = ../lib/libapriconv.la ../../apr/libapr.la
+
+iconv:	$(iconv_OBJECTS) $(iconv_LDADD)
+	$(LINK) $(iconv_OBJECTS) $(iconv_LDADD) $(LIBS)
diff --git a/util/Makefile.new b/util/Makefile.new
new file mode 100644
index 0000000..2dc3e26
--- /dev/null
+++ b/util/Makefile.new
@@ -0,0 +1,11 @@
+PROG=		iconv
+SRCS=		iconv.c iconv_stream.c
+
+LDADD=		-L../lib -liconv
+DPADD+=		../lib/libiconv.a
+
+BINDIR=		${PREFIX}/bin
+
+MAN1=		iconv.1
+
+.include <bsd.prog.mk>
diff --git a/util/iconv.c b/util/iconv.c
index 6f401fe..bfc68f1 100644
--- a/util/iconv.c
+++ b/util/iconv.c
@@ -30,7 +30,8 @@
  *	iconv (Charset Conversion Library) v0.3
  */
 
-#include <err.h>	/* err, errx, warn */
+#include "apr.h"
+
 #include <stdarg.h>	/* va_end, va_list, va_start */
 #include <stdio.h>	/* FILE, fclose, ferror, fopen, fread, stdin,
                            vfprintf */
@@ -43,14 +44,18 @@
 convert_stream(FILE *in, iconv_stream *out)
 {
 	static char buffer[4096];
-	size_t size;
+	apr_size_t size;
 
 	while ((size = fread(buffer, 1, sizeof(buffer), in))) {
-    		if (iconv_bwrite(out, buffer, size) <= 0)
-			errx(2, "convert_stream: conversion stream writing error");
+    		if (iconv_bwrite(out, buffer, size) <= 0) {
+			fprintf(stderr, "convert_stream: conversion stream writing error\n");
+			exit(2);
+		}
 	}
-	if (ferror(in))
-		err(1, "convert_stream: input file reading error");
+	if (ferror(in)) {
+		fprintf(stderr, "convert_stream: input file reading error\n");
+		exit(1);
+	}
 }
 
 static void
@@ -60,7 +65,7 @@
 	FILE *fp = std ? stdin : fopen(name, "r");
 
 	if (fp == NULL) {
-		warn("cannot open file %s", name);
+		fprintf(stderr, "cannot open file %s\n", name);
 		return;
 	}
 	convert_stream(fp, is);
@@ -68,6 +73,11 @@
     		fclose(fp);
 }
 
+static void closeapr(void)
+{
+    apr_terminate();
+}
+
 int
 main(int argc, char * const *argv)
 {
@@ -75,6 +85,8 @@
 	iconv_stream *is;
 	char *from = NULL, *to = NULL, *input = NULL;
 	int opt;
+	apr_pool_t *ctx; 
+	apr_status_t status;
 
 	while ((opt = getopt(argc, argv, "f:s:t:")) > 0) {
 		switch (opt) {
@@ -88,15 +100,31 @@
 			input = optarg;
 		}
 	}
-	if (from == NULL)
-		errx(4, "missing source charset (-f <name>)");
-	if (to == NULL)
-		errx(5, "missing destination charset (-t <name>)");
-	cd = iconv_open(to, from);
-	if ((int)cd < 0)
-		err(6, "unable to open specified convertor");
+	if (from == NULL) {
+		fprintf(stderr, "missing source charset (-f <name>)\n");
+		exit(4);
+	}
+	if (to == NULL) {
+		fprintf(stderr, "missing destination charset (-t <name>)\n");
+		exit(5);
+	}
+
+	/* Initialize APR */
+	apr_initialize();
+	atexit(closeapr);
+	if (apr_pool_create(&ctx, NULL) != APR_SUCCESS) {
+		fprintf(stderr, "Couldn't allocate context.\n");
+		exit(-1);
+	}
+
+	/* Use it */
+	status = apr_iconv_open(to, from,ctx, &cd);
+	if (status) {
+		fprintf(stderr, "unable to open specified convertor\n");
+		exit(6);
+		}
 	if (!(is = iconv_ostream_fopen(cd, stdout))) {
-		iconv_close(cd);
+		apr_iconv_close(cd,ctx);
 		exit(7);
 	}
 	if (input) {
@@ -110,6 +138,6 @@
 	if (iconv_write(is, NULL, 0) < 0)
 		exit(9);
 	iconv_stream_close(is);
-	iconv_close(cd);
+	apr_iconv_close(cd,ctx);
 	return 0;
 }
diff --git a/util/iconv_stream.c b/util/iconv_stream.c
index 2c21345..239ee9e 100644
--- a/util/iconv_stream.c
+++ b/util/iconv_stream.c
@@ -30,7 +30,6 @@
  *	iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>	/* warnx */
 #include <errno.h>	/* E2BIG, EINVAL, errno */
 #include <stdio.h>	/* FILE, ferror, fwrite */
 #include <stdlib.h>	/* free, malloc */
@@ -63,23 +62,25 @@
     free(stream);
 }
 
-ssize_t iconv_write(void *handle, const void *buf, size_t insize)
+apr_ssize_t iconv_write(void *handle, const void *buf, apr_size_t insize)
 {
 #define stream ((iconv_stream *)handle)
     char buffer[4096];
-    size_t outsize = sizeof(buffer), size;
+    apr_size_t outsize = sizeof(buffer), size;
     char *outbuf = buffer;
     const char *inbuf = buf;
-    size_t chars;
+    apr_size_t chars;
+    apr_status_t status;
+
     if (!buf)
         insize = 0;
-    chars = iconv(stream->cd, (const char **)&buf, &insize, &outbuf, &outsize);
+    status = apr_iconv(stream->cd, (const char **)&buf, &insize, &outbuf, &outsize, &chars);
     if ((int)chars < 0)
         return -1;
     stream->chars += chars;
     size = outbuf - buffer;
     if (size) {
-        ssize_t r;
+        apr_ssize_t r;
         outbuf = buffer;
         while ((r = stream->method(stream->handle, outbuf, size)) < size) {
             if (r < 0)
@@ -96,18 +97,17 @@
 #undef stream
 }
 
-ssize_t iconv_bwrite(void *handle, const void *buf, size_t insize)
+apr_ssize_t iconv_bwrite(void *handle, const void *buf, apr_size_t insize)
 {
 #define stream ((iconv_stream *)handle)
-    ssize_t res = 0;
-    size_t left, size = insize;
+    apr_ssize_t res = 0;
+    apr_size_t left, size = insize;
     if (!buf)
         return iconv_write(handle, NULL, 0);
     if (stream->buffer && stream->buf_ptr > stream->buffer) {
         do {
             left = stream->buffer + buf_size - stream->buf_ptr;
             if (!left) {
-        	warnx("iconv_bwrite: lack of space in the output buffer");
         	errno = E2BIG;
                 return -1;
             }
@@ -158,9 +158,9 @@
 #undef stream
 }
 
-static ssize_t fwrite_wrapper(void *handle, void *buf, size_t size)
+static apr_ssize_t fwrite_wrapper(void *handle, void *buf, apr_size_t size)
 {
-    size_t res = fwrite(buf, 1, size, (FILE *)handle);
+    apr_size_t res = fwrite(buf, 1, size, (FILE *)handle);
     return (res && !ferror((FILE *)handle)) ? res : -1;
 }
 
diff --git a/util/iconv_stream.h b/util/iconv_stream.h
index 2e61156..7c8f05a 100644
--- a/util/iconv_stream.h
+++ b/util/iconv_stream.h
@@ -1,17 +1,16 @@
 #ifndef _ICONV_STREAM_H_
 #define _ICONV_STREAM_H_
 
-#include <sys/types.h>	/* size_t, ssize_t */
 #include <stdio.h>	/* FILE */
-#include <iconv.h>	/* iconv_t */
+#include "iconv.h"	/* iconv_t */
 
-typedef ssize_t (*iconv_stream_func)(void *d, void *buf, size_t nbytes);
+typedef apr_ssize_t (*iconv_stream_func)(void *d, void *buf, apr_size_t nbytes);
 
 typedef struct {
 	iconv_t		cd;
-	size_t		chars;
-	size_t		in_bytes;
-	size_t		out_bytes;
+	apr_size_t	chars;
+	apr_size_t	in_bytes;
+	apr_size_t	out_bytes;
 	char *		buffer;
 	char *		buf_ptr;
 	void *		handle;
@@ -24,7 +23,7 @@
 
 iconv_stream *iconv_ostream_fopen(iconv_t cd, FILE *handle);
 
-ssize_t iconv_write(void *stream, const void *buf, size_t nbytes);
-ssize_t iconv_bwrite(void *stream, const void *buf, size_t nbytes);
+apr_ssize_t iconv_write(void *stream, const void *buf, apr_size_t nbytes);
+apr_ssize_t iconv_bwrite(void *stream, const void *buf, apr_size_t nbytes);
 
 #endif /*_ICONV_STREAM_H_*/