Hi Bill,

I have made some process with apr-iconv (Now it builds and util/iconv runs on
Linux)
It is still not finished (dlopen for example).
Find enclosed the patch to get it running.

I have some questions:

I am not very happy about the following code, any hints to improve it:
+++
+/* To be processed by configure */                                           
+#define ICONV_DEFAULT_PATH "/usr/local/lib/iconv"                              
+#define EFTYPE -1234                                                           
+/* To be processed by configure */                                             
+                                                                               
+/* apr additions */                                                            
+#define issetugid() 0                                                          
+/* apr additions */                                                            
+++

The default ICONV_DEFAULT_PATH should be a subdirectory of the APR install
directory.
What will be the default install directory of APR?

What to do with issetugid()?

I have removed the iconv_warnx(), there is no logging possible in APR, so only
the "errno" and return code are usefull, is this Ok?

In iconv.c I have put a #ifndef HAVE_ICONV, in case this code gets more
integrated in APR, should this be extented to all other C source files to
prevent names collisions?

Cheers

Jean-frederic
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apache/apr-iconv/Makefile.in,v
retrieving revision 1.1
diff -u -r1.1 Makefile.in
--- Makefile.in 2001/03/24 04:15:44     1.1
+++ Makefile.in 2001/03/30 15:59:43
@@ -2,8 +2,8 @@
 # Top-level Makefile for APRICONV
 #
 
-TARGET_LIB = libapriconv.la
-TARGET_EXPORTS = apriconv.exports
+TARGET_LIB = lib/libapriconv.la
+TARGET_EXPORTS = lib/apriconv.exports
 
 TARGETS = delete-lib $(TARGET_LIB) delete-exports $(TARGET_EXPORTS)
 
@@ -32,13 +32,11 @@
        fi
 
 $(TARGET_LIB):
-       @objects="`find $(SUBDIRS) -name '*.lo'`" ; \
-           echo $(LINK) $$objects ; \
-           $(LINK) -rpath $(libdir) $$objects
+       (cd lib; make)
 
 delete-exports:
        @if test -f $(TARGET_EXPORTS); then \
-           headers="`find include/*.h -newer $(TARGET_EXPORTS)`" ; \
+           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) ; \
@@ -47,11 +45,11 @@
        fi
 
 $(TARGET_EXPORTS):
-       $(AWK) -f @APR_SOURCE_DIR@/build/make_export.awk include/*.h > $@ ;
+       $(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/ 
./include/*.h
+       perl @APR_SOURCE_DIR@/build/scandoc.pl -i./build/default.pl -p./docs/ 
./lib/*.h
 
 
 .PHONY: delete-lib delete-exports
Index: build/rules.mk.in
===================================================================
RCS file: /home/cvs/apache/apr-iconv/build/rules.mk.in,v
retrieving revision 1.1
diff -u -r1.1 rules.mk.in
--- build/rules.mk.in   2001/03/24 04:15:45     1.1
+++ build/rules.mk.in   2001/03/30 15:59:43
@@ -132,7 +132,7 @@
        fi
 
 local-clean:
-       $(RM) -f *.o *.lo *.a *.la *.so $(CLEAN_TARGETS) $(PROGRAMS)
+       $(RM) -f *.o *.lo *.a *.la *.so *.slo $(CLEAN_TARGETS) $(PROGRAMS)
        $(RM) -rf .libs
 
 local-distclean: local-clean
Index: ces/utf-8.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/ces/utf-8.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 utf-8.c
--- ces/utf-8.c 2000/11/20 19:00:20     1.1.1.1
+++ ces/utf-8.c 2001/03/30 15:59:44
@@ -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;
Index: lib/Makefile.in
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/Makefile.in,v
retrieving revision 1.1
diff -u -r1.1 Makefile.in
--- lib/Makefile.in     2001/03/24 04:15:45     1.1
+++ lib/Makefile.in     2001/03/30 15:59:44
@@ -1,25 +1,14 @@
-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
+# 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
 
-LIBDIR=                ${PREFIX}/lib
+$(TARGET_LIB): $(OBJECTS)
+       $(LINK) -rpath $(libdir) $(OBJECTS)                                     
 
-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
-
+all:           $(TARGET_LIB)
+ 
 # bring in rules.mk for standard functionality                                 
 
 @INCLUDE_RULES@
Index: lib/iconv.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv.c
--- lib/iconv.c 2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv.c 2001/03/30 15:59:45
@@ -30,7 +30,8 @@
  *     iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>       /* warnx */
+#ifndef HAVE_ICONV
+
 #include <errno.h>     /* errno */
 #include <stdlib.h>    /* free, malloc */
 #include <string.h>
@@ -45,20 +46,18 @@
 };
 
 size_t
-iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
+apr_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
        char **outbuf, size_t *outbytesleft)
 {
        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);
        }
        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);
        }
@@ -69,7 +68,7 @@
 }
 
 iconv_t
-iconv_open(const char *to, const char *from)
+apr_iconv_open(const char *to, const char *from)
 {
        struct iconv_converter_desc **idesc;
        struct iconv_converter *icp;
@@ -96,13 +95,12 @@
 }
 
 int
-iconv_close(iconv_t cd)
+apr_iconv_close(iconv_t cd)
 {
        struct iconv_converter *icp = (struct iconv_converter *)cd;
        int error = 0;
 
        if (icp == NULL) {
-               iconv_warnx("iconv_close: invalid handle");
                errno = EBADF;
                return -1;
        }
@@ -112,3 +110,26 @@
        free(icp);
        return error;
 }
+
+#else
+
+#include <iconv.h>
+
+iconv_t apr_iconv_open(const char *to_charset,
+            const char *from_charset)
+{
+       return (iconv_open(to_charset, from_charset));
+}
+
+size_t apr_iconv(iconv_t cd, const char **inbuf,
+            size_t *inbytesleft, char **outbuf,
+            size_t *outbytesleft)
+{
+       return (iconv(cd , inbuf, inbytesleft, outbuf, outbytesleft));
+}
+int apr_iconv_close(iconv_t cd)
+{
+       return (iconv_close(cd));
+}
+
+#endif /* !defined(HAVE_ICONV) */
Index: lib/iconv.h
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv.h,v
retrieving revision 1.2
diff -u -r1.2 iconv.h
--- lib/iconv.h 2001/03/24 04:06:23     1.2
+++ lib/iconv.h 2001/03/30 15:59:45
@@ -34,10 +34,18 @@
 
 #include <sys/types.h> /* size_t */
 #include <stddef.h>    /* NULL */
-#include <inttypes.h>
 
 #include "apr.h"
 
+/* To be processed by configure */
+#define ICONV_DEFAULT_PATH "/usr/local/lib/iconv"
+#define EFTYPE -1234
+/* To be processed by configure */
+
+/* apr additions */
+#define issetugid() 0
+/* apr additions */
+
 /*
  * iconv_t:    charset conversion descriptor type
  */
@@ -45,9 +53,9 @@
 
 /* __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);
+iconv_t        apr_iconv_open(const char *, const char *);
+size_t apr_iconv(iconv_t, const char **, size_t *, char **, size_t *);
+int    apr_iconv_close(iconv_t);
 
 /* __END_DECLS */
 
@@ -138,8 +146,9 @@
 #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] */
+typedef apr_uint16_t uint16_t;
 #define ucs_t    ucs4_t
 
 /*
Index: lib/iconv_ccs.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_ccs.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_ccs.c
--- lib/iconv_ccs.c     2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_ccs.c     2001/03/30 15:59:46
@@ -30,7 +30,6 @@
  *     iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>       /* warnx */
 #include <errno.h>     /* errno */
 #include <stdlib.h>    /* free, malloc */
 #include <string.h>
Index: lib/iconv_ces.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_ces.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_ces.c
--- lib/iconv_ces.c     2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_ces.c     2001/03/30 15:59:46
@@ -30,7 +30,6 @@
  *     iconv (Charset Conversion Library) v1.0
  */
 
-#include <err.h>       /* warnx */
 #include <errno.h>     /* errno */
 #include <limits.h>    /* PATH_MAX */
 #include <stdlib.h>    /* free, malloc */
@@ -56,7 +55,7 @@
                iconv_mod_unload(mod);
                return 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;
@@ -100,7 +99,7 @@
 void
 iconv_ces_reset_func(struct iconv_ces *ces)
 {
-       bzero(ces->data, sizeof(int));
+       memset(ces->data, 0, sizeof(int));
 }
 
 /*ARGSUSED*/
Index: lib/iconv_ces_euc.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_ces_euc.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_ces_euc.c
--- lib/iconv_ces_euc.c 2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_ces_euc.c 2001/03/30 15:59:46
@@ -59,7 +59,7 @@
        state = (iconv_ces_euc_state_t *)malloc(stsz);
        if (state == NULL)
                return errno;
-       bzero(state, stsz);
+       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;
Index: lib/iconv_ces_iso2022.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_ces_iso2022.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_ces_iso2022.c
--- lib/iconv_ces_iso2022.c     2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_ces_iso2022.c     2001/03/30 15:59:47
@@ -32,7 +32,7 @@
 
 #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>
@@ -83,7 +83,7 @@
        state = (iconv_ces_iso2022_state_t *)malloc(stsz + shiftsz);
        if (state == NULL)
                return errno;
-       bzero(state, stsz + shiftsz);
+       memset(state, 0, stsz + shiftsz);
        ces->data = state;
        state->shift_tab = (int*)((char*)state + stsz);
        state->org_shift_tab = ces->desc->data;
Index: lib/iconv_int.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_int.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_int.c
--- lib/iconv_int.c     2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_int.c     2001/03/30 15:59:47
@@ -46,7 +46,7 @@
 
        if (p == NULL)
                return errno;
-       bzero(p, size);
+       memset(p, 0, size);
        *pp = p;
        return 0;
 }
Index: lib/iconv_module.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_module.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_module.c
--- lib/iconv_module.c  2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_module.c  2001/03/30 15:59:47
@@ -78,6 +78,7 @@
                                        return 0;
                                }
                        }
+                       free(ptr); /* otherwise memory leak */
                }
        }
        return iconv_getpathname(buf, ICONV_DEFAULT_PATH, buffer);
@@ -90,7 +91,6 @@
 
        handle = dlopen(name, RTLD_LAZY);
        if (handle == NULL) {
-               warnx("cannot dlopen file %s: %s", name, dlerror());
                return EINVAL;
        }
        data = dlsym(handle, symbol);
@@ -100,7 +100,6 @@
                return 0;
        }
        dlclose(handle);
-       iconv_warnx("invalid file %s: no external symbol %s", name, symbol);
        return EINVAL;
 }
 
@@ -129,7 +128,7 @@
                dlclose(handle);
                return ENOMEM;
        }
-       bzero(mod, sizeof(*mod));
+       memset(mod, 0, sizeof(*mod));
        mod->im_handle = handle;
        mod->im_desc = mdesc;
        mod->im_args = args;
Index: lib/iconv_uc.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/lib/iconv_uc.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_uc.c
--- lib/iconv_uc.c      2000/11/20 19:00:20     1.1.1.1
+++ lib/iconv_uc.c      2001/03/30 15:59:47
@@ -32,7 +32,7 @@
        ic = malloc(sizeof(*ic));
        if (ic == NULL)
                return ENOMEM;
-       bzero(ic, sizeof(*ic));
+       memset(ic, 0, sizeof(*ic));
        error = iconv_ces_open(from, &ic->from);
        if (error)
                goto bad;
Index: util/Makefile.in
===================================================================
RCS file: /home/cvs/apache/apr-iconv/util/Makefile.in,v
retrieving revision 1.1
diff -u -r1.1 Makefile.in
--- util/Makefile.in    2001/03/24 04:15:45     1.1
+++ util/Makefile.in    2001/03/30 15:59:47
@@ -7,6 +7,7 @@
 all: $(PROGRAMS)
 
 iconv_OBJECTS = iconv.lo iconv_stream.lo
-iconv_LDADD   = ../liblibiconv.la
+# The -ldl is not OK...
+iconv_LDADD   = ../lib/libapriconv.la -ldl
 iconv: $(iconv_OBJECTS) $(iconv_LDADD)
        $(LINK) $(iconv_OBJECTS) $(iconv_LDADD)
Index: util/iconv.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/util/iconv.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv.c
--- util/iconv.c        2000/11/20 19:00:21     1.1.1.1
+++ util/iconv.c        2001/03/30 15:59:48
@@ -92,11 +92,11 @@
                errx(4, "missing source charset (-f <name>)");
        if (to == NULL)
                errx(5, "missing destination charset (-t <name>)");
-       cd = iconv_open(to, from);
+       cd = apr_iconv_open(to, from);
        if ((int)cd < 0)
                err(6, "unable to open specified convertor");
        if (!(is = iconv_ostream_fopen(cd, stdout))) {
-               iconv_close(cd);
+               apr_iconv_close(cd);
                exit(7);
        }
        if (input) {
@@ -110,6 +110,6 @@
        if (iconv_write(is, NULL, 0) < 0)
                exit(9);
        iconv_stream_close(is);
-       iconv_close(cd);
+       apr_iconv_close(cd);
        return 0;
 }
Index: util/iconv_stream.c
===================================================================
RCS file: /home/cvs/apache/apr-iconv/util/iconv_stream.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 iconv_stream.c
--- util/iconv_stream.c 2000/11/20 19:00:21     1.1.1.1
+++ util/iconv_stream.c 2001/03/30 15:59:48
@@ -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 */
@@ -73,7 +72,7 @@
     size_t chars;
     if (!buf)
         insize = 0;
-    chars = iconv(stream->cd, (const char **)&buf, &insize, &outbuf, &outsize);
+    chars = apr_iconv(stream->cd, (const char **)&buf, &insize, &outbuf, 
&outsize);
     if ((int)chars < 0)
         return -1;
     stream->chars += chars;
@@ -107,7 +106,6 @@
         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;
             }

Reply via email to