blob: 80ab061e8261e9a214a376e6afbf0eced2038386 [file] [log] [blame]
Lev Walkinf15320b2004-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
Lev Walkin0ede18c2004-09-07 10:47:39 +000011#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
Lev Walkinf15320b2004-06-03 03:38:44 +000015#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 Walkinf15320b2004-06-03 03:38:44 +000020#include <stddef.h> /* for offsetof and ptrdiff_t */
Lev Walkin0ede18c2004-09-07 10:47:39 +000021
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 Walkin1ff369a2004-09-07 07:26:32 +000029#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin0ede18c2004-09-07 10:47:39 +000030#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000031
Lev Walkin1ff369a2004-09-07 07:26:32 +000032#ifdef WIN32
Lev Walkin7a5e3022004-08-11 08:32:04 +000033#define snprintf _snprintf
34#define vsnprintf _vsnprintf
Lev Walkin64399722004-08-11 07:17:22 +000035#define alloca(size) _alloca(size)
Lev Walkin1ff369a2004-09-07 07:26:32 +000036#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000037
38#ifndef __GNUC__
39#define __attribute__(ignore)
40#endif
41
42#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +000043#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
44#endif /* offsetof */
45
Lev Walkinf15320b2004-06-03 03:38:44 +000046#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 Walkinf15320b2004-06-03 03:38:44 +000056 * 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 */
62typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size,
63 void *application_specific_key);
64
65#endif /* _ASN_TYPES_H_ */