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 | |
| 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 */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 16 | #include <stddef.h> /* for offsetof and ptrdiff_t */ |
vlm | e55716a | 2004-08-11 09:10:59 +0000 | [diff] [blame] | 17 | #ifndef WIN32 |
vlm | 6e73a04 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 18 | #include <inttypes.h> /* C99 Standard specifies this file, for uintXX_t */ |
| 19 | #else |
| 20 | typedef unsigned char uint8_t; |
| 21 | typedef unsigned short int uint16_t; |
| 22 | typedef unsigned int uint32_t; |
| 23 | typedef int ssize_t; |
| 24 | #endif |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 25 | |
vlm | 6e73a04 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 26 | #ifdef WIN32 |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 27 | #define snprintf _snprintf |
| 28 | #define vsnprintf _vsnprintf |
vlm | 6e73a04 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 29 | #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> */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 37 | #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... */ |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 60 | #ifdef __GNUC__ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 61 | #define ASN_DEBUG(fmt, args...) do { \ |
| 62 | fprintf(stderr, fmt, ##args); \ |
| 63 | fprintf(stderr, "\n"); \ |
| 64 | } while(0) |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 65 | #else /* !__GNUC__ */ |
| 66 | extern void ASN_DEBUG_f(const char *fmt, ...); |
| 67 | #define ASN_DEBUG ASN_DEBUG_f |
| 68 | #endif /* __GNUC__ */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 69 | #else /* EMIT_ASN_DEBUG */ |
vlm | e517408 | 2004-08-11 09:34:42 +0000 | [diff] [blame^] | 70 | #ifdef __GNUC__ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 71 | #define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */ |
vlm | e517408 | 2004-08-11 09:34:42 +0000 | [diff] [blame^] | 72 | #else /* __GNUC__ */ |
| 73 | static void ASN_DEBUG(const char *fmt, ...) { (void)fmt; }; |
| 74 | #endif /* __GNUC__ */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 75 | #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 | */ |
| 86 | typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size, |
| 87 | void *application_specific_key); |
| 88 | |
| 89 | #endif /* _ASN_TYPES_H_ */ |