blob: 6d426673c5184a2bddbee1bc164fd4053d070589 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5/*
6 * Miscellaneous system-dependent types.
7 */
8#ifndef _ASN_TYPES_H_
9#define _ASN_TYPES_H_
10
11#include <stdio.h> /* For fprintf() */
12#include <stdlib.h> /* For *alloc(3) */
13#include <string.h> /* For memcpy(3) */
14#include <sys/types.h> /* For size_t */
15#include <stdarg.h> /* For va_start */
16#include <inttypes.h> /* C99 Standard specifies this file, for uintXX_t */
17#include <stddef.h> /* for offsetof and ptrdiff_t */
18
19#ifndef offsetof
20#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
21#endif /* offsetof */
22
23#define CALLOC(nmemb, size) calloc(nmemb, size)
24#define MALLOC(size) malloc(size)
25#define REALLOC(oldptr, size) realloc(oldptr, size)
26#define FREEMEM(ptr) free(ptr)
27
28#ifndef MIN /* Suitable for comparing primitive types (integers) */
29#if defined(__GNUC__)
30#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
31 ((_a)<(_b)?(_a):(_b)); })
32#else /* !__GNUC__ */
33#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
34#endif /* __GNUC__ */
35#endif /* MIN */
36
37/*
38 * A macro for debugging the ASN.1 internals.
39 * You may enable or override it.
40 */
41#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
42#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
43#define ASN_DEBUG(fmt, args...) do { \
44 fprintf(stderr, fmt, ##args); \
45 fprintf(stderr, "\n"); \
46 } while(0)
47#else /* EMIT_ASN_DEBUG */
48#define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */
49#endif /* EMIT_ASN_DEBUG */
50#endif /* ASN_DEBUG */
51
52
53/*
54 * Generic type of an application-defined callback to return various
55 * types of data to the application.
56 * EXPECTED RETURN VALUES:
57 * -1: Failed to consume bytes. Abort the mission.
58 * Other return values indicate success, and ignored.
59 */
60typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size,
61 void *application_specific_key);
62
63#endif /* _ASN_TYPES_H_ */