vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 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 | |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 11 | #ifdef HAVE_CONFIG_H |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | #include <stdio.h> /* For fprintf() */ |
| 16 | #include <stdlib.h> /* For *alloc(3) */ |
| 17 | #include <string.h> /* For memcpy(3) */ |
| 18 | #include <sys/types.h> /* For size_t */ |
| 19 | #include <stdarg.h> /* For va_start */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | #include <stddef.h> /* for offsetof and ptrdiff_t */ |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 21 | |
| 22 | #include <inttypes.h> /* C99 specifies this file */ |
| 23 | |
| 24 | /* |
| 25 | * Earlier FreeBSD version didn't have <stdint.h>, |
| 26 | * but <inttypes.h> was present. |
| 27 | */ |
| 28 | #if !defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_) /* Workaround */ |
vlm | a4294b7 | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 29 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 30 | #endif |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | |
vlm | a4294b7 | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 32 | #ifdef WIN32 |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 33 | #define snprintf _snprintf |
| 34 | #define vsnprintf _vsnprintf |
vlm | 6e73a04 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 35 | #define alloca(size) _alloca(size) |
vlm | a4294b7 | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 36 | #endif /* WIN32 */ |
vlm | 6e73a04 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 37 | |
| 38 | #ifndef __GNUC__ |
| 39 | #define __attribute__(ignore) |
| 40 | #endif |
| 41 | |
| 42 | #ifndef offsetof /* If not defined by <stddef.h> */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 43 | #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) |
| 44 | #endif /* offsetof */ |
| 45 | |
| 46 | #define CALLOC(nmemb, size) calloc(nmemb, size) |
| 47 | #define MALLOC(size) malloc(size) |
| 48 | #define REALLOC(oldptr, size) realloc(oldptr, size) |
| 49 | #define FREEMEM(ptr) free(ptr) |
| 50 | |
| 51 | #ifndef MIN /* Suitable for comparing primitive types (integers) */ |
| 52 | #if defined(__GNUC__) |
| 53 | #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ |
| 54 | ((_a)<(_b)?(_a):(_b)); }) |
| 55 | #else /* !__GNUC__ */ |
| 56 | #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ |
| 57 | #endif /* __GNUC__ */ |
| 58 | #endif /* MIN */ |
| 59 | |
| 60 | /* |
| 61 | * A macro for debugging the ASN.1 internals. |
| 62 | * You may enable or override it. |
| 63 | */ |
| 64 | #ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */ |
| 65 | #if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */ |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 66 | #ifdef __GNUC__ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 67 | #define ASN_DEBUG(fmt, args...) do { \ |
| 68 | fprintf(stderr, fmt, ##args); \ |
| 69 | fprintf(stderr, "\n"); \ |
| 70 | } while(0) |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 71 | #else /* !__GNUC__ */ |
| 72 | extern void ASN_DEBUG_f(const char *fmt, ...); |
| 73 | #define ASN_DEBUG ASN_DEBUG_f |
| 74 | #endif /* __GNUC__ */ |
vlm | 7d8db86 | 2004-08-11 10:09:03 +0000 | [diff] [blame] | 75 | #else /* EMIT_ASN_DEBUG != 1 */ |
vlm | e517408 | 2004-08-11 09:34:42 +0000 | [diff] [blame] | 76 | #ifdef __GNUC__ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 77 | #define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */ |
vlm | e517408 | 2004-08-11 09:34:42 +0000 | [diff] [blame] | 78 | #else /* __GNUC__ */ |
| 79 | static void ASN_DEBUG(const char *fmt, ...) { (void)fmt; }; |
| 80 | #endif /* __GNUC__ */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 81 | #endif /* EMIT_ASN_DEBUG */ |
| 82 | #endif /* ASN_DEBUG */ |
| 83 | |
| 84 | |
| 85 | /* |
| 86 | * Generic type of an application-defined callback to return various |
| 87 | * types of data to the application. |
| 88 | * EXPECTED RETURN VALUES: |
| 89 | * -1: Failed to consume bytes. Abort the mission. |
| 90 | * Other return values indicate success, and ignored. |
| 91 | */ |
| 92 | typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size, |
| 93 | void *application_specific_key); |
| 94 | |
| 95 | #endif /* _ASN_TYPES_H_ */ |