YAZ 5.35.1
ber_bool.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
5
14#if HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include <stdio.h>
19#include "odr-priv.h"
20
21int 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
int ber_boolean(ODR o, int *val)
Definition ber_bool.c:21
int ber_declen(const char *buf, int *len, int max)
Definition ber_len.c:93
int ber_enclen(ODR o, int len, int lenlen, int exact)
Definition ber_len.c:30
Internal ODR definitions.
#define odr_putc(o, c)
Definition odr-priv.h:129
#define odr_max(o)
Definition odr-priv.h:47
void odr_seterror(ODR o, int error, int id)
Definition odr.c:118
#define ODR_DECODE
Definition odr.h:95
#define ODR_PRINT
Definition odr.h:97
#define OOTHER
Definition odr.h:156
#define ODR_ENCODE
Definition odr.h:96
#define OPROTO
Definition odr.h:157
const char * bp
Definition odr-priv.h:85
Definition odr.h:125
struct Odr_private * op
Definition odr.h:132
int direction
Definition odr.h:126