X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fodr_mem.c;h=4309d3da5a0b445f6d5c8f21e16612b9d4568baa;hp=6a2ef688288c99a8c3c0ec67fc8d4407c1eaa75f;hb=cf0d647d4a642af04013d09f412e8629897187c5;hpb=fe507b6b15788a3a8e58063d9dae52532a5229a5 diff --git a/src/odr_mem.c b/src/odr_mem.c index 6a2ef68..4309d3d 100644 --- a/src/odr_mem.c +++ b/src/odr_mem.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. - * - * $Id: odr_mem.c,v 1.11 2007-05-06 20:12:20 adam Exp $ */ /** * \file odr_mem.c @@ -29,7 +27,7 @@ NMEM odr_extract_mem(ODR o) return r; } -void *odr_malloc(ODR o, int size) +void *odr_malloc(ODR o, size_t size) { return nmem_malloc(o->mem, size); } @@ -39,17 +37,27 @@ char *odr_strdup(ODR o, const char *str) return nmem_strdup(o->mem, str); } +char *odr_strdup_null(ODR o, const char *str) +{ + return nmem_strdup_null(o->mem, str); +} + char *odr_strdupn(ODR o, const char *str, size_t n) { return nmem_strdupn(o->mem, str, n); } -int *odr_intdup(ODR o, int v) +Odr_int *odr_intdup(ODR o, Odr_int v) { return nmem_intdup(o->mem, v); } -int odr_total(ODR o) +Odr_bool *odr_booldup(ODR o, Odr_bool v) +{ + return nmem_booldup(o->mem, v); +} + +size_t odr_total(ODR o) { return nmem_total(o->mem); } @@ -88,7 +96,7 @@ int odr_grow_block(ODR b, int min_bytes) return 0; } -int odr_write(ODR o, unsigned char *buf, int bytes) +int odr_write2(ODR o, const char *buf, int bytes) { if (o->pos + bytes >= o->size && odr_grow_block(o, bytes)) { @@ -102,6 +110,11 @@ int odr_write(ODR o, unsigned char *buf, int bytes) return 0; } +int odr_write(ODR o, unsigned char *buf, int bytes) +{ + return odr_write2(o, (char *) buf, bytes); +} + int odr_seek(ODR o, int whence, int offset) { if (whence == ODR_S_CUR) @@ -116,9 +129,31 @@ int odr_seek(ODR o, int whence, int offset) o->pos = offset; return 0; } + +Odr_int odr_strtol(const char *nptr, char **endptr, int base) +{ +#if NMEM_64 +#if WIN32 + return _strtoui64(nptr, endptr, base); +#else + return strtoll(nptr, endptr, base); +#endif + +#else + return strtol(nptr, endptr, base); +#endif +} + +Odr_int odr_atoi(const char *s) +{ + char *endptr; + return odr_strtol(s, &endptr, 10); +} + /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab