blob: d2633f6f24c91b54822ad5d73a7711d6cda69bff [file] [log] [blame]
vlmfa67ddc2004-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 */
vlmfa67ddc2004-06-03 03:38:44 +000016#include <stddef.h> /* for offsetof and ptrdiff_t */
vlm6e73a042004-08-11 07:17:22 +000017#if __STDC_VERSION__ < 199901L
18#include <inttypes.h> /* C99 Standard specifies this file, for uintXX_t */
19#else
20typedef unsigned char uint8_t;
21typedef unsigned short int uint16_t;
22typedef unsigned int uint32_t;
23typedef int ssize_t;
24#endif
vlmfa67ddc2004-06-03 03:38:44 +000025
vlm6e73a042004-08-11 07:17:22 +000026#ifdef WIN32
27#define snprintf(str, size, format, args...) \
28 _snprintf(str, size, format, ##args)
29#define vsnprintf(str, size, format, ap) \
30 _vsnprintf(str, size, format, ap)
31#define alloca(size) _alloca(size)
32#endif
33
34#ifndef __GNUC__
35#define __attribute__(ignore)
36#endif
37
38#ifndef offsetof /* If not defined by <stddef.h> */
vlmfa67ddc2004-06-03 03:38:44 +000039#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
40#endif /* offsetof */
41
42#define CALLOC(nmemb, size) calloc(nmemb, size)
43#define MALLOC(size) malloc(size)
44#define REALLOC(oldptr, size) realloc(oldptr, size)
45#define FREEMEM(ptr) free(ptr)
46
47#ifndef MIN /* Suitable for comparing primitive types (integers) */
48#if defined(__GNUC__)
49#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
50 ((_a)<(_b)?(_a):(_b)); })
51#else /* !__GNUC__ */
52#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
53#endif /* __GNUC__ */
54#endif /* MIN */
55
56/*
57 * A macro for debugging the ASN.1 internals.
58 * You may enable or override it.
59 */
60#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
61#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
62#define ASN_DEBUG(fmt, args...) do { \
63 fprintf(stderr, fmt, ##args); \
64 fprintf(stderr, "\n"); \
65 } while(0)
66#else /* EMIT_ASN_DEBUG */
67#define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */
68#endif /* EMIT_ASN_DEBUG */
69#endif /* ASN_DEBUG */
70
71
72/*
73 * Generic type of an application-defined callback to return various
74 * types of data to the application.
75 * EXPECTED RETURN VALUES:
76 * -1: Failed to consume bytes. Abort the mission.
77 * Other return values indicate success, and ignored.
78 */
79typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size,
80 void *application_specific_key);
81
82#endif /* _ASN_TYPES_H_ */