Lev Walkin | f15320b | 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 | |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 11 | #ifdef HAVE_CONFIG_H |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
Lev Walkin | f15320b | 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 */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | #include <stddef.h> /* for offsetof and ptrdiff_t */ |
Lev Walkin | 0ede18c | 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 */ |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 29 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 30 | #endif |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 32 | #ifdef WIN32 |
Lev Walkin | 7a5e302 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 33 | #define snprintf _snprintf |
| 34 | #define vsnprintf _vsnprintf |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 35 | #define alloca(size) _alloca(size) |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 36 | #endif /* WIN32 */ |
Lev Walkin | 6439972 | 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> */ |
Lev Walkin | f15320b | 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 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 46 | #ifndef MIN /* Suitable for comparing primitive types (integers) */ |
| 47 | #if defined(__GNUC__) |
| 48 | #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ |
| 49 | ((_a)<(_b)?(_a):(_b)); }) |
| 50 | #else /* !__GNUC__ */ |
| 51 | #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ |
| 52 | #endif /* __GNUC__ */ |
| 53 | #endif /* MIN */ |
| 54 | |
| 55 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | * Generic type of an application-defined callback to return various |
| 57 | * types of data to the application. |
| 58 | * EXPECTED RETURN VALUES: |
| 59 | * -1: Failed to consume bytes. Abort the mission. |
| 60 | * Other return values indicate success, and ignored. |
| 61 | */ |
| 62 | typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size, |
| 63 | void *application_specific_key); |
| 64 | |
| 65 | #endif /* _ASN_TYPES_H_ */ |