X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fber_int.c;h=ef185aa6b4ac7197e016b61f3ff9bd001027c15f;hp=ef1a0e03591248d1c44791a2af2f091117ada8e0;hb=dd6da3de6292dd8d087eac67c0c9a7eced8b88de;hpb=05c274ef315384faafcc5900c17468f0ea2474e6 diff --git a/src/ber_int.c b/src/ber_int.c index ef1a0e0..ef185aa 100644 --- a/src/ber_int.c +++ b/src/ber_int.c @@ -1,8 +1,6 @@ -/* - * Copyright (c) 1995-2004, Index Data +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: ber_int.c,v 1.2 2004-10-15 00:18:59 adam Exp $ */ /** @@ -19,45 +17,51 @@ #include +#if HAVE_SYS_TYPES_H +#include +#endif + #ifdef WIN32 #include -#else -#include +#endif +#if HAVE_NETINET_IN_H #include #endif #include "odr-priv.h" -static int ber_encinteger(ODR o, int val); -static int ber_decinteger(const unsigned char *buf, int *val, int max); +static int ber_encinteger(ODR o, Odr_int val); +static int ber_decinteger(const unsigned char *buf, Odr_int *val, int max); -int ber_integer(ODR o, int *val) +int ber_integer(ODR o, Odr_int *val) { int res; switch (o->direction) { - case ODR_DECODE: - if ((res = ber_decinteger(o->bp, val, odr_max(o))) <= 0) - { - odr_seterror(o, OPROTO, 50); - return 0; - } - o->bp += res; - return 1; - case ODR_ENCODE: - if ((res = ber_encinteger(o, *val)) < 0) - return 0; - return 1; - case ODR_PRINT: return 1; - default: odr_seterror(o, OOTHER, 51); return 0; + case ODR_DECODE: + if ((res = ber_decinteger(o->bp, val, odr_max(o))) <= 0) + { + odr_seterror(o, OPROTO, 50); + return 0; + } + o->bp += res; + return 1; + case ODR_ENCODE: + if ((res = ber_encinteger(o, *val)) < 0) + return 0; + return 1; + case ODR_PRINT: + return 1; + default: + odr_seterror(o, OOTHER, 51); return 0; } } /* * Returns: number of bytes written or -1 for error (out of bounds). */ -int ber_encinteger(ODR o, int val) +int ber_encinteger(ODR o, Odr_int val) { int a, len; union { int i; unsigned char c[sizeof(int)]; } tmp; @@ -72,16 +76,13 @@ int ber_encinteger(ODR o, int val) return -1; if (odr_write(o, (unsigned char*) tmp.c + a, len) < 0) return -1; -#ifdef ODR_DEBUG - fprintf(stderr, "[val=%d]", val); -#endif return 0; } /* * Returns: Number of bytes read or 0 if no match, -1 if error. */ -int ber_decinteger(const unsigned char *buf, int *val, int max) +int ber_decinteger(const unsigned char *buf, Odr_int *val, int max) { const unsigned char *b = buf; unsigned char fill; @@ -106,8 +107,14 @@ int ber_decinteger(const unsigned char *buf, int *val, int max) *val = ntohl(tmp.i); b += len; -#ifdef ODR_DEBUG - fprintf(stderr, "[val=%d]", *val); -#endif return b - buf; } +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +