blob: 7cd6058278192c7daa561fd61d2cbfede4b33758 [file] [log] [blame]
Lev Walkinda997b12017-08-04 01:38:41 -07001#ifndef ASN1P_INTEGER_H
2#define ASN1P_INTEGER_H
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif /* HAVE_CONFIG_H */
7
8#ifdef HAVE_SYS_TYPES_H
9#include <sys/types.h>
10#endif /* HAVE_SYS_TYPES_H */
11#ifdef HAVE_INTTYPES_H
12#include <inttypes.h> /* POSIX 1003.1-2001, C99 */
13#else /* HAVE_INTTYPES_H */
14#ifdef HAVE_STDINT_H
15#include <stdint.h> /* SUSv2+ */
16#endif /* HAVE_STDINT_H */
17#endif /* HAVE_INTTYPES_H */
18
19/*
20 * Basic integer type used in numerous places.
21 * ASN.1 does not define any limits on this number, so it must be sufficiently
22 * large to accomodate typical inputs. It does not have to be a dynamically
23 * allocated type with potentially unlimited width: consider the width of
24 * an integer defined here as one of the "compiler limitations".
25 * NOTE: this is NOT a type for ASN.1 "INTEGER" type representation, this
26 * type is used by the compiler itself to handle large integer values
27 * specified inside ASN.1 grammar.
28 */
29#ifdef HAVE_128_BIT_INT
30typedef __int128 asn1c_integer_t;
31#else
32typedef intmax_t asn1c_integer_t;
33#endif
34
35int asn1p_atoi(const char *ptr, asn1c_integer_t *r_value);
36const char *asn1p_itoa(asn1c_integer_t value); /* Ptr to a static buf */
37/*
38 * Return values:
39 * -1: The value did not fit in the buffer.
40 * >0: The length in bytes of the stringified numeric value.
41 */
42int asn1p_itoa_s(char *buf, size_t size,
43 asn1c_integer_t value); /* Return -1 on error, or length. */
44
45#endif /* ASN1P_INTEGER_H */