Towards 2.1.40.
[yaz-moved-to-github.git] / src / ber_bool.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: ber_bool.c,v 1.5 2005-08-11 14:21:55 adam Exp $
6  */
7
8 /** 
9  * \file ber_bool.c
10  * \brief Implements BER BOOLEAN encoding and decoding
11  *
12  * This source file implements BER encoding and decoding of
13  * the BOOLEAN type.
14  */
15
16 #if HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19
20 #include <stdio.h>
21 #include "odr-priv.h"
22
23 int ber_boolean(ODR o, int *val)
24 {
25     int res, len;
26
27     switch (o->direction)
28     {
29     case ODR_ENCODE:
30         if (ber_enclen(o, 1, 1, 1) != 1)
31             return 0;
32         if (odr_putc(o, *val) < 0)
33             return 0;
34         return 1;
35     case ODR_DECODE:
36         if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
37         {
38             odr_seterror(o, OPROTO, 9);
39             return 0;
40         }
41         o->bp+= res;
42         if (len != 1 || odr_max(o) < len)
43         {
44             odr_seterror(o, OPROTO, 10);
45             return 0;
46         }
47         *val = *o->bp;
48         o->bp++;
49         return 1;
50     case ODR_PRINT:
51         return 1;
52     default: odr_seterror(o, OOTHER, 11); return 0;
53     }
54 }
55 /*
56  * Local variables:
57  * c-basic-offset: 4
58  * indent-tabs-mode: nil
59  * End:
60  * vim: shiftwidth=4 tabstop=8 expandtab
61  */
62