Fix licensing issues
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / e2ap_engine / constr_TYPE.c
1
2 /*-
3  * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #include <asn_internal.h>
7 #include <constr_TYPE.h>
8 #include <errno.h>
9
10 /*
11  * Version of the ASN.1 infrastructure shipped with compiler.
12  */
13 int get_asn1c_environment_version() { return ASN1C_ENVIRONMENT_VERSION; }
14
15 static asn_app_consume_bytes_f _print2fp;
16
17 /*
18  * Return the outmost tag of the type.
19  */
20 ber_tlv_tag_t
21 asn_TYPE_outmost_tag(const asn_TYPE_descriptor_t *type_descriptor,
22                 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) {
23
24         if(tag_mode)
25                 return tag;
26
27         if(type_descriptor->tags_count)
28                 return type_descriptor->tags[0];
29
30         return type_descriptor->op->outmost_tag(type_descriptor, struct_ptr, 0, 0);
31 }
32
33 /*
34  * Print the target language's structure in human readable form.
35  */
36 int
37 asn_fprint(FILE *stream, const asn_TYPE_descriptor_t *td,
38            const void *struct_ptr) {
39     if(!stream) stream = stdout;
40     if(!td || !struct_ptr) {
41         errno = EINVAL;
42         return -1;
43         }
44
45         /* Invoke type-specific printer */
46     if(td->op->print_struct(td, struct_ptr, 1, _print2fp, stream)) {
47         return -1;
48     }
49
50     /* Terminate the output */
51     if(_print2fp("\n", 1, stream)) {
52         return -1;
53     }
54
55     return fflush(stream);
56 }
57
58 /* Dump the data into the specified stdio stream */
59 static int
60 _print2fp(const void *buffer, size_t size, void *app_key) {
61         FILE *stream = (FILE *)app_key;
62
63         if(fwrite(buffer, 1, size, stream) != size)
64                 return -1;
65
66         return 0;
67 }
68
69
70 /*
71  * Some compilers do not support variable args macros.
72  * This function is a replacement of ASN_DEBUG() macro.
73  */
74 void ASN_DEBUG_f(const char *fmt, ...);
75 void ASN_DEBUG_f(const char *fmt, ...) {
76         va_list ap;
77         va_start(ap, fmt);
78         vfprintf(stderr, fmt, ap);
79         fprintf(stderr, "\n");
80         va_end(ap);
81 }