Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 1 | #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 |
| 30 | typedef __int128 asn1c_integer_t; |
| 31 | #else |
| 32 | typedef intmax_t asn1c_integer_t; |
| 33 | #endif |
| 34 | |
| 35 | int asn1p_atoi(const char *ptr, asn1c_integer_t *r_value); |
| 36 | const 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 | */ |
| 42 | int 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 */ |