35279c7ed6b9eb3ffc4a3714d35f2508e1e6de59
[yaz-moved-to-github.git] / odr / odr_null.c
1 /*
2  * Copyright (c) 1995, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_null.c,v $
7  * Revision 1.5  1995-05-16 08:50:56  quinn
8  * License, documentation, and memory fixes
9  *
10  * Revision 1.4  1995/03/08  12:12:26  quinn
11  * Added better error checking.
12  *
13  * Revision 1.3  1995/02/10  18:57:25  quinn
14  * More in the way of error-checking.
15  *
16  * Revision 1.2  1995/02/09  15:51:49  quinn
17  * Works better now.
18  *
19  * Revision 1.1  1995/02/02  16:21:54  quinn
20  * First kick.
21  *
22  */
23
24 #include <odr.h>
25
26 /*
27  * Top level null en/decoder.
28  * Returns 1 on success, 0 on error.
29  */
30 int odr_null(ODR o, int **p, int opt)
31 {
32     int res, cons = 0;
33     static int nullval = 0;
34
35     if (o->error)
36         return 0;
37     if (o->t_class < 0)
38     {
39         o->t_class = ODR_UNIVERSAL;
40         o->t_tag = ODR_NULL;
41     }
42     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
43         return 0;
44     if (!res)
45         return opt;
46     if (o->direction == ODR_PRINT)
47     {
48         fprintf(o->print, "%sNULL\n", odr_indent(o));
49         return 1;
50     }
51     if (cons)
52     {
53         o->error = OPROTO;
54         return 0;
55     }
56     if (o->direction == ODR_DECODE)
57         *p = &nullval;
58     return ber_null(o, *p);
59 }