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