2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: odr_util.c,v 1.12 2007-04-12 20:47:28 adam Exp $
9 * \brief Implements various ODR utilities
19 #include <yaz/oid_util.h>
21 void odr_prname(ODR o, const char *name)
24 odr_printf(o, "%*s%s ", o->op->indent*4, "", name);
26 odr_printf(o, "%*s", o->op->indent*4, "");
29 int odp_more_chunks(ODR o, const unsigned char *base, int len)
33 if (len < 0) /* indefinite length */
35 if (*o->bp == 0 && *(o->bp + 1) == 0)
44 return o->bp - base < len;
47 Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o)
53 if (!(r = (int *)nmem_malloc(nmem, (oid_oidlen(o) + 1) * sizeof(int))))
59 Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o)
61 return odr_oiddup_nmem(odr_getmem(odr), o);
64 Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str)
69 if (oid_dotstring_to_oid(str, oid))
71 ret = (int *)nmem_malloc(nmem, sizeof(*ret)*(oid_oidlen(oid) + 1));
76 Odr_oid *odr_getoidbystr(ODR o, const char *str)
78 return odr_getoidbystr_nmem(odr_getmem(o), str);
81 int odr_missing(ODR o, int opt, const char *name)
87 odr_seterror(o, OREQUIRED, 53);
88 odr_setelement(o, name);
94 * Reallocate the buffer `old', using the ODR memory pool `o' to be
95 * big enough to hold its existing value (if any) plus `prefix' (if
96 * any) and a separator character. Copy `prefix', a forward slash and
97 * the old value into the new area and return its address. Can be
99 * initRequest->implementationName = odr_prepend(o,
100 * initRequest->implementationName, "ZOOM-C");
102 char *odr_prepend(ODR o, const char *prefix, const char *old)
104 int plen = (prefix == 0) ? 0 : strlen(prefix);
105 int olen = (old == 0) ? 0 : strlen(old);
106 char *res = (char*) odr_malloc (o, olen + plen + 2);
110 strcpy (res, prefix);
111 if (prefix != 0 && old != 0)
121 * indent-tabs-mode: nil
123 * vim: shiftwidth=4 tabstop=8 expandtab