blob: a8bfb6d49a8c871190894a5924c04623007a35bf [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 */
vlme55716a2004-08-11 09:10:59 +000017#ifndef WIN32
vlm6e73a042004-08-11 07:17:22 +000018#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
vlmf5202a52004-08-11 08:32:04 +000027#define snprintf _snprintf
28#define vsnprintf _vsnprintf
vlm6e73a042004-08-11 07:17:22 +000029#define alloca(size) _alloca(size)
30#endif
31
32#ifndef __GNUC__
33#define __attribute__(ignore)
34#endif
35
36#ifndef offsetof /* If not defined by <stddef.h> */
vlmfa67ddc2004-06-03 03:38:44 +000037#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
38#endif /* offsetof */
39
40#define CALLOC(nmemb, size) calloc(nmemb, size)
41#define MALLOC(size) malloc(size)
42#define REALLOC(oldptr, size) realloc(oldptr, size)
43#define FREEMEM(ptr) free(ptr)
44
45#ifndef MIN /* Suitable for comparing primitive types (integers) */
46#if defined(__GNUC__)
47#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
48 ((_a)<(_b)?(_a):(_b)); })
49#else /* !__GNUC__ */
50#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
51#endif /* __GNUC__ */
52#endif /* MIN */
53
54/*
55 * A macro for debugging the ASN.1 internals.
56 * You may enable or override it.
57 */
58#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
59#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
vlmf5202a52004-08-11 08:32:04 +000060#ifdef __GNUC__
vlmfa67ddc2004-06-03 03:38:44 +000061#define ASN_DEBUG(fmt, args...) do { \
62 fprintf(stderr, fmt, ##args); \
63 fprintf(stderr, "\n"); \
64 } while(0)
vlmf5202a52004-08-11 08:32:04 +000065#else /* !__GNUC__ */
66extern void ASN_DEBUG_f(const char *fmt, ...);
67#define ASN_DEBUG ASN_DEBUG_f
68#endif /* __GNUC__ */
vlm7d8db862004-08-11 10:09:03 +000069#else /* EMIT_ASN_DEBUG != 1 */
vlme5174082004-08-11 09:34:42 +000070#ifdef __GNUC__
vlmfa67ddc2004-06-03 03:38:44 +000071#define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */
vlme5174082004-08-11 09:34:42 +000072#else /* __GNUC__ */
73static void ASN_DEBUG(const char *fmt, ...) { (void)fmt; };
74#endif /* __GNUC__ */
vlmfa67ddc2004-06-03 03:38:44 +000075#endif /* EMIT_ASN_DEBUG */
76#endif /* ASN_DEBUG */
77
78
79/*
80 * Generic type of an application-defined callback to return various
81 * types of data to the application.
82 * EXPECTED RETURN VALUES:
83 * -1: Failed to consume bytes. Abort the mission.
84 * Other return values indicate success, and ignored.
85 */
86typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size,
87 void *application_specific_key);
88
89#endif /* _ASN_TYPES_H_ */