apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfcl...@apache.org
Subject cvs commit: apr-iconv/util iconv.c iconv_stream.h
Date Wed, 04 Apr 2001 17:29:03 GMT
jfclere     01/04/04 10:29:03

  Modified:    ces      _tbl_simple.c
               lib      iconv.c iconv.h iconv_ccs.c iconv_ces.c
                        iconv_ces_euc.c iconv_ces_iso2022.c iconv_int.c
                        iconv_module.c iconv_uc.c
               util     iconv.c iconv_stream.h
  Log:
  Replace the dl routines by apr_dso.
  Arrange  some #include
  Remove warn/err and replace the iconv utility ones by fprintf().
  Now the iconv utility runs on Linux and ReliantUnix.
  
  Revision  Changes    Path
  1.3       +9 -6      apr-iconv/ces/_tbl_simple.c
  
  Index: _tbl_simple.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/ces/_tbl_simple.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- _tbl_simple.c	2001/03/24 04:06:22	1.2
  +++ _tbl_simple.c	2001/04/04 17:28:54	1.3
  @@ -30,12 +30,15 @@
    *	iconv (Charset Conversion Library) v1.0
    */
   
  +#include "apr.h"
  +
   #define ICONV_INTERNAL
  -#include <iconv.h>
  +#include "iconv.h"
  +
   #include <errno.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;
  @@ -116,14 +119,14 @@
   }
   
   static int
  -table_load_ccs(struct iconv_module *mod)
  +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);
  +	error = iconv_mod_load(mod->im_args, ICMOD_UC_CCS, NULL, &ccsmod, ctx);
   	if (error)
   		return error;
   	ccsmod->im_next = mod->im_deplist;
  @@ -132,14 +135,14 @@
   }
   
   static int
  -table_event(struct iconv_module *mod, int event)
  +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;
   	}
  
  
  
  1.3       +6 -6      apr-iconv/lib/iconv.c
  
  Index: iconv.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv.c	2001/03/30 17:20:53	1.2
  +++ iconv.c	2001/04/04 17:28:56	1.3
  @@ -37,7 +37,7 @@
   #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 */
  @@ -68,7 +68,7 @@
   }
   
   iconv_t
  -apr_iconv_open(const char *to, const char *from)
  +apr_iconv_open(const char *to, const char *from, apr_pool_t *ctx)
   {
   	struct iconv_converter_desc **idesc;
   	struct iconv_converter *icp;
  @@ -80,7 +80,7 @@
   		return (iconv_t)(-1);
   	error = EINVAL;
   	for (idesc = converters; *idesc; idesc++) {
  -		error = (*idesc)->icd_open(to, from, &data);
  +		error = (*idesc)->icd_open(to, from, &data, ctx);
   		if (error == 0)
   			break;
   	}
  @@ -95,7 +95,7 @@
   }
   
   int
  -apr_iconv_close(iconv_t cd)
  +apr_iconv_close(iconv_t cd, apr_pool_t *ctx)
   {
   	struct iconv_converter *icp = (struct iconv_converter *)cd;
   	int error = 0;
  @@ -105,7 +105,7 @@
   		return -1;
   	}
   	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;
  @@ -116,7 +116,7 @@
   #include <iconv.h>
   
   iconv_t apr_iconv_open(const char *to_charset,
  -            const char *from_charset)
  +            const char *from_charset, apr_pool_t *ctx)
   {
   	return (iconv_open(to_charset, from_charset));
   }
  
  
  
  1.4       +25 -25    apr-iconv/lib/iconv.h
  
  Index: iconv.h
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- iconv.h	2001/03/30 17:20:53	1.3
  +++ iconv.h	2001/04/04 17:28:56	1.4
  @@ -32,10 +32,8 @@
   #ifndef _ICONV_H_
   #define _ICONV_H_
   
  -#include <sys/types.h>	/* size_t */
  -#include <stddef.h>	/* NULL */
  -
   #include "apr.h"
  +#include "apr_pools.h"
   
   /* To be processed by configure */
   #define ICONV_DEFAULT_PATH "/usr/local/lib/iconv"
  @@ -53,9 +51,9 @@
   
   /* __BEGIN_DECLS */
   
  -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);
  +iconv_t	apr_iconv_open(const char *, const char *, apr_pool_t *);
  +apr_size_t	apr_iconv(iconv_t, const char **, apr_size_t *, char **, apr_size_t *);
  +int	apr_iconv_close(iconv_t, apr_pool_t *);
   
   /* __END_DECLS */
   
  @@ -89,8 +87,10 @@
   };
   
   struct iconv_module;
  +
  +/* _tbl_simple.c table_load_ccs() calls iconv_mod_load(...ctx) */
   
  -typedef int iconv_mod_event_t(struct iconv_module *, int);
  +typedef int iconv_mod_event_t(struct iconv_module *, int, apr_pool_t *ctx );
   
   struct iconv_module_desc {
   	int		imd_type;
  @@ -115,17 +115,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_size_t iconv_conv_t(void *, const unsigned char **, apr_size_t *,
  +	unsigned char **, apr_size_t *);
   
   struct iconv_converter_desc {
   	iconv_open_t *	icd_open;
  @@ -244,7 +244,7 @@
    */
   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 *);
  @@ -253,11 +253,11 @@
   
   typedef 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;
  @@ -277,8 +277,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);
  @@ -289,7 +289,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) \
  @@ -313,7 +313,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);
  @@ -326,7 +326,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 {
  @@ -338,13 +338,13 @@
   ICONV_CES_DRIVER_DECL(iso2022);
   
   
  -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;
   
  
  
  
  1.3       +1 -1      apr-iconv/lib/iconv_ccs.c
  
  Index: iconv_ccs.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_ccs.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_ccs.c	2001/03/30 17:20:54	1.2
  +++ iconv_ccs.c	2001/04/04 17:28:57	1.3
  @@ -35,7 +35,7 @@
   #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)
  
  
  
  1.3       +9 -9      apr-iconv/lib/iconv_ces.c
  
  Index: iconv_ces.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_ces.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_ces.c	2001/03/30 17:20:54	1.2
  +++ iconv_ces.c	2001/04/04 17:28:57	1.3
  @@ -36,33 +36,33 @@
   #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)
  +iconv_ces_open(const char *cesname, struct iconv_ces **cespp, apr_pool_t *ctx)
   {
   	struct iconv_module *mod;
   	struct iconv_ces *ces;
   	int error;
   
  -	error = iconv_mod_load(cesname, ICMOD_UC_CES, NULL, &mod);
  +	error = iconv_mod_load(cesname, ICMOD_UC_CES, NULL, &mod, ctx);
   	if (error == EFTYPE)
  -		error = iconv_mod_load("_tbl_simple", ICMOD_UC_CES, cesname, &mod);
  +		error = iconv_mod_load("_tbl_simple", ICMOD_UC_CES, cesname, &mod, ctx);
   	if (error)
   		return (error == EFTYPE) ? EINVAL : error;
   	ces = malloc(sizeof(*ces));
   	if (ces == NULL) {
  -		iconv_mod_unload(mod);
  +		iconv_mod_unload(mod, ctx);
   		return ENOMEM;
   	}
   	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);
  +	error = ICONV_CES_OPEN(ces,ctx);
   	if (error) {
   		free(ces);
  -		iconv_mod_unload(mod);
  +		iconv_mod_unload(mod, ctx);
   		return error;
   	}
   	*cespp = ces;
  @@ -70,7 +70,7 @@
   }
   
   int
  -iconv_ces_close(struct iconv_ces *ces)
  +iconv_ces_close(struct iconv_ces *ces, apr_pool_t *ctx)
   {
   	int res;
   
  @@ -78,7 +78,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;
   }
  
  
  
  1.3       +2 -2      apr-iconv/lib/iconv_ces_euc.c
  
  Index: iconv_ces_euc.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_ces_euc.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_ces_euc.c	2001/03/30 17:20:55	1.2
  +++ iconv_ces_euc.c	2001/04/04 17:28:57	1.3
  @@ -35,7 +35,7 @@
   #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)
  @@ -47,7 +47,7 @@
   } iconv_ces_euc_state_t;
   
   int
  -iconv_euc_open(struct iconv_ces *ces)
  +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;
  
  
  
  1.3       +2 -2      apr-iconv/lib/iconv_ces_iso2022.c
  
  Index: iconv_ces_iso2022.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_ces_iso2022.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_ces_iso2022.c	2001/03/30 17:20:56	1.2
  +++ iconv_ces_iso2022.c	2001/04/04 17:28:58	1.3
  @@ -35,7 +35,7 @@
   #include <string.h>	/* memset, memcmp, memcpy */
   
   #define ICONV_INTERNAL
  -#include <iconv.h>
  +#include "iconv.h"
   
   typedef struct {
   	const char	*sequence;
  @@ -68,7 +68,7 @@
   } iconv_ces_iso2022_state_t;
   
   int
  -iconv_iso2022_open(struct iconv_ces *ces)
  +iconv_iso2022_open(struct iconv_ces *ces, apr_pool_t *ctx)
   {
   	const iconv_ces_iso2022_ccs_t *ccsattr;
   	const struct iconv_ccs_desc *ccs;
  
  
  
  1.3       +1 -1      apr-iconv/lib/iconv_int.c
  
  Index: iconv_int.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_int.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_int.c	2001/03/30 17:20:56	1.2
  +++ iconv_int.c	2001/04/04 17:28:58	1.3
  @@ -37,7 +37,7 @@
   #include <string.h>	/* strdup, strlen */
   
   #define ICONV_INTERNAL
  -#include <iconv.h>
  +#include "iconv.h"
   
   int
   iconv_malloc(size_t size, void **pp)
  
  
  
  1.3       +33 -36    apr-iconv/lib/iconv_module.c
  
  Index: iconv_module.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_module.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_module.c	2001/03/30 17:20:56	1.2
  +++ iconv_module.c	2001/04/04 17:28:58	1.3
  @@ -28,35 +28,30 @@
    *
    */
   
  -#include <sys/types.h>	/* sys/stat.h */
  -#include <sys/stat.h>	/* struct stat */
  +#define ICONV_INTERNAL
  +#include "iconv.h"
  +#include "apr_file_io.h"
  +#include "apr_pools.h"
  +#include "apr_dso.h"
   
  -#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>
  +#include <stdlib.h>
  +#include <sys/types.h>
  +#include <sys/stat.h>
   
   static int
   iconv_getpathname(char *buffer, const char *dir, const char *name)
   {
   	struct stat sb;
   
  -	snprintf(buffer, PATH_MAX, "%s/%s", dir, name);
  +	snprintf(buffer, APR_PATH_MAX, "%s/%s", dir, name);
   	return (stat(buffer, &sb) || ! S_ISREG(sb.st_mode)) ? EINVAL : 0;
   }
   
   static int
   iconv_getpath(char *buf, const char *name)
   {
  -	char buffer[PATH_MAX];
  +	char buffer[APR_PATH_MAX];
   	char *ptr;
   
   	if (tolower(name[0]) == 'x' && name[1] == '-')
  @@ -85,47 +80,49 @@
   }
   
   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) {
  +	/* 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);
  +	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)
   		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);
  +		apr_dso_unload(handle);
   		return EFTYPE;
   	}
   	mod = malloc(sizeof(*mod));
   	if (mod == NULL) {
  -		dlclose(handle);
  +		apr_dso_unload(handle);
   		return ENOMEM;
   	}
   	memset(mod, 0, sizeof(*mod));
  @@ -136,7 +133,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;
  @@ -145,7 +142,7 @@
   			depend++;
   		}
   	}
  -	error = ICONV_MOD_DYNDEPS(mod);
  +	error = ICONV_MOD_DYNDEPS(mod,ctx);
   	if (error)
   		goto bad;
   	depmod = mod->im_deplist;
  @@ -153,19 +150,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;
  @@ -173,22 +170,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:
  
  
  
  1.3       +10 -11    apr-iconv/lib/iconv_uc.c
  
  Index: iconv_uc.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/lib/iconv_uc.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv_uc.c	2001/03/30 17:20:57	1.2
  +++ iconv_uc.c	2001/04/04 17:28:59	1.3
  @@ -1,11 +1,10 @@
  -#include <err.h>
  +#define ICONV_INTERNAL
  +#include "iconv.h"
  +
   #include <errno.h>
   #include <stdlib.h>
   #include <string.h>
   
  -#define ICONV_INTERNAL
  -#include <iconv.h>
  -
   struct iconv_uc {
   	struct iconv_ces *	from;
   	struct iconv_ces *	to;
  @@ -24,7 +23,7 @@
   };
   
   int
  -iconv_uc_open(const char *to, const char *from, void **data)
  +iconv_uc_open(const char *to, const char *from, void **data, apr_pool_t *ctx)
   {
   	struct iconv_uc *ic;
   	int error;
  @@ -33,10 +32,10 @@
   	if (ic == NULL)
   		return ENOMEM;
   	memset(ic, 0, sizeof(*ic));
  -	error = iconv_ces_open(from, &ic->from);
  +	error = iconv_ces_open(from, &ic->from, ctx);
   	if (error)
   		goto bad;
  -	error = iconv_ces_open(to, &ic->to);
  +	error = iconv_ces_open(to, &ic->to, ctx);
   	if (error)
   		goto bad;
   	ic->ignore_ilseq = 0;
  @@ -44,21 +43,21 @@
   	*data = (void*)ic;
   	return 0;
   bad:
  -	iconv_uc_close(ic);
  +	iconv_uc_close(ic,ctx);
   	return error;
   }
   
   int
  -iconv_uc_close(void *data)
  +iconv_uc_close(void *data, apr_pool_t *ctx)
   {
   	struct iconv_uc *ic = (struct iconv_uc *)data;
   
   	if (ic == NULL)
   		return 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;
   }
  
  
  
  1.3       +42 -15    apr-iconv/util/iconv.c
  
  Index: iconv.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/util/iconv.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iconv.c	2001/03/30 17:21:05	1.2
  +++ iconv.c	2001/04/04 17:29:02	1.3
  @@ -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 */
  @@ -46,11 +47,15 @@
   	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)) {
  +		fprintf(stderr, "convert_stream: input file reading error\n");
  +		exit(1);
   	}
  -	if (ferror(in))
  -		err(1, "convert_stream: input file reading error");
   }
   
   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,7 @@
   	iconv_stream *is;
   	char *from = NULL, *to = NULL, *input = NULL;
   	int opt;
  +	apr_pool_t *ctx; 
   
   	while ((opt = getopt(argc, argv, "f:s:t:")) > 0) {
   		switch (opt) {
  @@ -88,15 +99,31 @@
   			input = optarg;
   		}
   	}
  -	if (from == NULL)
  -		errx(4, "missing source charset (-f <name>)");
  -	if (to == NULL)
  -		errx(5, "missing destination charset (-t <name>)");
  -	cd = apr_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 */
  +	cd = apr_iconv_open(to, from,ctx);
  +	if ((int)cd < 0) {
  +		fprintf(stderr, "unable to open specified convertor\n");
  +		exit(6);
  +		}
   	if (!(is = iconv_ostream_fopen(cd, stdout))) {
  -		apr_iconv_close(cd);
  +		apr_iconv_close(cd,ctx);
   		exit(7);
   	}
   	if (input) {
  @@ -110,6 +137,6 @@
   	if (iconv_write(is, NULL, 0) < 0)
   		exit(9);
   	iconv_stream_close(is);
  -	apr_iconv_close(cd);
  +	apr_iconv_close(cd,ctx);
   	return 0;
   }
  
  
  
  1.2       +1 -1      apr-iconv/util/iconv_stream.h
  
  Index: iconv_stream.h
  ===================================================================
  RCS file: /home/cvs/apr-iconv/util/iconv_stream.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- iconv_stream.h	2000/11/20 19:00:21	1.1
  +++ iconv_stream.h	2001/04/04 17:29:02	1.2
  @@ -3,7 +3,7 @@
   
   #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);
   
  
  
  

Mime
View raw message