zend_long.h revision 79c9dc75
18ee2a4a9SAnatol Belski/*
28ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
38ee2a4a9SAnatol Belski   | Zend Engine                                                          |
48ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
58ee2a4a9SAnatol Belski   | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
68ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
78ee2a4a9SAnatol Belski   | This source file is subject to version 2.00 of the Zend license,     |
8b7a7b1a6SStanislav Malyshev   | that is bundled with this package in the file LICENSE, and is        |
98ee2a4a9SAnatol Belski   | available through the world-wide-web at the following url:           |
108ee2a4a9SAnatol Belski   | http://www.zend.com/license/2_00.txt.                                |
118ee2a4a9SAnatol Belski   | If you did not receive a copy of the Zend license and are unable to  |
128ee2a4a9SAnatol Belski   | obtain it through the world-wide-web, please send a note to          |
138ee2a4a9SAnatol Belski   | license@zend.com so we can mail you a copy immediately.              |
148ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
158ee2a4a9SAnatol Belski   | Authors: Anatol Belski <ab@php.net>                                  |
168ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
178ee2a4a9SAnatol Belski*/
188ee2a4a9SAnatol Belski
198ee2a4a9SAnatol Belski/* $Id$ */
208ee2a4a9SAnatol Belski
218ee2a4a9SAnatol Belski
224d997f63SAnatol Belski#ifndef ZEND_LONG_H
234d997f63SAnatol Belski#define ZEND_LONG_H
248ee2a4a9SAnatol Belski
25c3e3c98eSAnatol Belski#include "main/php_stdint.h"
268ee2a4a9SAnatol Belski
27baee5922SAnatol Belski/* This is the heart of the whole int64 enablement in zval. */
288ee2a4a9SAnatol Belski#if defined(__X86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
295d062b61SAnatol Belski# define ZEND_ENABLE_ZVAL_LONG64 1
308ee2a4a9SAnatol Belski#endif
318ee2a4a9SAnatol Belski
32202e8db1SAnatol Belski/* Integer types. */
335d062b61SAnatol Belski#ifdef ZEND_ENABLE_ZVAL_LONG64
345d030000SAnatol Belskitypedef int64_t zend_long;
355d030000SAnatol Belskitypedef uint64_t zend_ulong;
365d030000SAnatol Belskitypedef int64_t zend_off_t;
375d030000SAnatol Belski# define ZEND_LONG_MAX INT64_MAX
385d030000SAnatol Belski# define ZEND_LONG_MIN INT64_MIN
395d030000SAnatol Belski# define ZEND_ULONG_MAX UINT64_MAX
4079c9dc75SAnatol Belski# define Z_L(i) INT64_C(i)
4179c9dc75SAnatol Belski# define Z_UL(i) UINT64_C(i)
4228b7a033SAnatol Belski# define SIZEOF_ZEND_LONG 8
438ee2a4a9SAnatol Belski#else
44c429c74bSAnatol Belskitypedef int32_t zend_long;
45c429c74bSAnatol Belskitypedef uint32_t zend_ulong;
46c429c74bSAnatol Belskitypedef int32_t zend_off_t;
47c429c74bSAnatol Belski# define ZEND_LONG_MAX INT32_MAX
48c429c74bSAnatol Belski# define ZEND_LONG_MIN INT32_MIN
49c429c74bSAnatol Belski# define ZEND_ULONG_MAX UINT32_MAX
50964e1174SNikita Popov# define Z_L(i) INT32_C(i)
51964e1174SNikita Popov# define Z_UL(i) UINT32_C(i)
525d030000SAnatol Belski# define SIZEOF_ZEND_LONG 4
538ee2a4a9SAnatol Belski#endif
548ee2a4a9SAnatol Belski
558ee2a4a9SAnatol Belski
56202e8db1SAnatol Belski/* Conversion macros. */
574d997f63SAnatol Belski#define ZEND_LTOA_BUF_LEN 65
588ee2a4a9SAnatol Belski
595d062b61SAnatol Belski#ifdef ZEND_ENABLE_ZVAL_LONG64
60c429c74bSAnatol Belski# define ZEND_LONG_FMT "%" PRId64
61c429c74bSAnatol Belski# define ZEND_ULONG_FMT "%" PRIu64
62c429c74bSAnatol Belski# define ZEND_LONG_FMT_SPEC PRId64
63c429c74bSAnatol Belski# define ZEND_ULONG_FMT_SPEC PRIu64
648ee2a4a9SAnatol Belski# ifdef PHP_WIN32
654d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) _i64toa_s((i), (s), (len), 10)
664d997f63SAnatol Belski#  define ZEND_ATOL(i, s) i = _atoi64((s))
674d997f63SAnatol Belski#  define ZEND_STRTOL(s0, s1, base) _strtoi64((s0), (s1), (base))
684d997f63SAnatol Belski#  define ZEND_STRTOUL(s0, s1, base) _strtoui64((s0), (s1), (base))
694d997f63SAnatol Belski#  define ZEND_STRTOL_PTR _strtoi64
704d997f63SAnatol Belski#  define ZEND_STRTOUL_PTR _strtoui64
718ee2a4a9SAnatol Belski#  define ZEND_ABS _abs64
728ee2a4a9SAnatol Belski# else
734d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) \
748ee2a4a9SAnatol Belski	do { \
75c429c74bSAnatol Belski		int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
768ee2a4a9SAnatol Belski		(s)[st] = '\0'; \
778ee2a4a9SAnatol Belski 	} while (0)
784d997f63SAnatol Belski#  define ZEND_ATOL(i, s) (i) = atoll((s))
794d997f63SAnatol Belski#  define ZEND_STRTOL(s0, s1, base) strtoll((s0), (s1), (base))
804d997f63SAnatol Belski#  define ZEND_STRTOUL(s0, s1, base) strtoull((s0), (s1), (base))
814d997f63SAnatol Belski#  define ZEND_STRTOL_PTR strtoll
824d997f63SAnatol Belski#  define ZEND_STRTOUL_PTR strtoull
83d6930c9aSAnatol Belski#  define ZEND_ABS imaxabs
848ee2a4a9SAnatol Belski# endif
858ee2a4a9SAnatol Belski#else
864d997f63SAnatol Belski# define ZEND_STRTOL(s0, s1, base) strtol((s0), (s1), (base))
874d997f63SAnatol Belski# define ZEND_STRTOUL(s0, s1, base) strtoul((s0), (s1), (base))
88c429c74bSAnatol Belski# define ZEND_LONG_FMT "%" PRId32
89c429c74bSAnatol Belski# define ZEND_ULONG_FMT "%" PRIu32
90c429c74bSAnatol Belski# define ZEND_LONG_FMT_SPEC PRId32
91c429c74bSAnatol Belski# define ZEND_ULONG_FMT_SPEC PRIu32
928ee2a4a9SAnatol Belski# ifdef PHP_WIN32
934d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) _ltoa_s((i), (s), (len), 10)
944d997f63SAnatol Belski#  define ZEND_ATOL(i, s) i = atol((s))
958ee2a4a9SAnatol Belski# else
964d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) \
978ee2a4a9SAnatol Belski	do { \
98c429c74bSAnatol Belski		int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
998ee2a4a9SAnatol Belski		(s)[st] = '\0'; \
1008ee2a4a9SAnatol Belski 	} while (0)
1014d997f63SAnatol Belski#  define ZEND_ATOL(i, s) (i) = atol((s))
1028ee2a4a9SAnatol Belski# endif
1034d997f63SAnatol Belski# define ZEND_STRTOL_PTR strtol
1044d997f63SAnatol Belski# define ZEND_STRTOUL_PTR strtoul
1058ee2a4a9SAnatol Belski# define ZEND_ABS abs
1068ee2a4a9SAnatol Belski#endif
1078ee2a4a9SAnatol Belski
10861d37e05SDmitry Stogov#if SIZEOF_ZEND_LONG == 4
10961d37e05SDmitry Stogov# define MAX_LENGTH_OF_LONG 11
11061d37e05SDmitry Stogov# define LONG_MIN_DIGITS "2147483648"
11161d37e05SDmitry Stogov#elif SIZEOF_ZEND_LONG == 8
11261d37e05SDmitry Stogov# define MAX_LENGTH_OF_LONG 20
11361d37e05SDmitry Stogov# define LONG_MIN_DIGITS "9223372036854775808"
11461d37e05SDmitry Stogov#else
11561d37e05SDmitry Stogov# error "Unknown SIZEOF_ZEND_LONG"
11661d37e05SDmitry Stogov#endif
11761d37e05SDmitry Stogov
11861d37e05SDmitry Stogovstatic const char long_min_digits[] = LONG_MIN_DIGITS;
1198ee2a4a9SAnatol Belski
1204d997f63SAnatol Belski#endif /* ZEND_LONG_H */
1218ee2a4a9SAnatol Belski
1228ee2a4a9SAnatol Belski/*
1238ee2a4a9SAnatol Belski * Local variables:
1248ee2a4a9SAnatol Belski * tab-width: 4
1258ee2a4a9SAnatol Belski * c-basic-offset: 4
1268ee2a4a9SAnatol Belski * indent-tabs-mode: t
1278ee2a4a9SAnatol Belski * End:
1288ee2a4a9SAnatol Belski */
129