2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: odr.c,v 1.35 2002-07-25 12:51:08 adam Exp $
15 #include <yaz/xmalloc.h>
18 Odr_null *ODR_NULLVAL = (Odr_null *) "NULL"; /* the presence of a null value */
20 Odr_null *odr_nullval (void)
28 "Memory allocation failed",
31 "Required data element missing",
37 "Length of constructed type different from sum of members",
38 "Overflow writing definite length of constructed type"
41 char *odr_errmsg(int n)
43 return odr_errlist[n];
46 void odr_perror(ODR o, char *message)
48 fprintf(stderr, "%s: %s\n", message, odr_errlist[o->error]);
51 int odr_geterror(ODR o)
56 void odr_setprint(ODR o, FILE *file)
61 int odr_set_charset(ODR o, const char *to, const char *from)
64 if (o->op->iconv_handle != (iconv_t)(-1))
65 iconv_close (o->op->iconv_handle);
67 o->op->iconv_handle = iconv_open (to, from);
68 if (o->op->iconv_handle == (iconv_t)(-1))
78 ODR odr_createmem(int direction)
82 if (!(r = (ODR)xmalloc(sizeof(*r))))
84 r->direction = direction;
87 r->size = r->pos = r->top = 0;
89 r->mem = nmem_create();
91 r->op = xmalloc (sizeof(*r->op));
92 r->op->odr_ber_tag.lclass = -1;
94 r->op->iconv_handle = (iconv_t)(-1);
97 yaz_log (LOG_DEBUG, "odr_createmem dir=%d o=%p", direction, r);
101 void odr_reset(ODR o)
105 odr_seek(o, ODR_S_SET, 0);
115 if (o->op->iconv_handle != (iconv_t)(-1))
116 iconv(o->op->iconv_handle, 0, 0, 0, 0);
118 yaz_log (LOG_DEBUG, "odr_reset o=%p", o);
121 void odr_destroy(ODR o)
123 nmem_destroy(o->mem);
124 if (o->buf && o->can_grow)
126 if (o->print && o->print != stderr)
129 if (o->op->iconv_handle != (iconv_t)(-1))
130 iconv_close (o->op->iconv_handle);
134 yaz_log (LOG_DEBUG, "odr_destroy o=%p", o);
137 void odr_setbuf(ODR o, char *buf, int len, int can_grow)
139 o->bp = (unsigned char *) buf;
141 o->buf = (unsigned char *) buf;
142 o->can_grow = can_grow;
147 char *odr_getbuf(ODR o, int *len, int *size)
152 return (char*) o->buf;