Comment.
[yaz-moved-to-github.git] / src / ber_bool.c
1 /*
2  * Copyright (c) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: ber_bool.c,v 1.1 2003-10-27 12:21:30 adam Exp $
7  */
8
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <stdio.h>
14 #include "odr-priv.h"
15
16 int ber_boolean(ODR o, int *val)
17 {
18     int res, len;
19
20     switch (o->direction)
21     {
22     case ODR_ENCODE:
23         if (ber_enclen(o, 1, 1, 1) != 1)
24             return 0;
25         if (odr_putc(o, *val) < 0)
26             return 0;
27 #ifdef ODR_DEBUG
28         fprintf(stderr, "[val=%d]\n", *val);
29 #endif
30         return 1;
31     case ODR_DECODE:
32         if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
33         {
34             odr_seterror(o, OPROTO, 9);
35             return 0;
36         }
37         o->bp+= res;
38         if (len != 1 || odr_max(o) < len)
39         {
40             odr_seterror(o, OPROTO, 10);
41             return 0;
42         }
43         *val = *o->bp;
44         o->bp++;
45 #ifdef ODR_DEBUG
46         fprintf(stderr, "[val=%d]\n", *val);
47 #endif
48         return 1;
49     case ODR_PRINT:
50         return 1;
51     default: odr_seterror(o, OOTHER, 11); return 0;
52     }
53 }