zend_long.h revision c429c74b
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,     |
88ee2a4a9SAnatol Belski   | 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
278ee2a4a9SAnatol Belski/* This is the heart of the whole int64 enablement in zval. Based on this
28c3e3c98eSAnatol Belski   macros the size_t datatype is handled, see zend_types.h */
298ee2a4a9SAnatol Belski#if defined(__X86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
308ee2a4a9SAnatol Belski# define ZEND_ENABLE_INT64 1
318ee2a4a9SAnatol Belski#endif
328ee2a4a9SAnatol Belski
338ee2a4a9SAnatol Belski/* Integer types or the old bad long. */
348ee2a4a9SAnatol Belski#ifdef ZEND_ENABLE_INT64
358ee2a4a9SAnatol Belski# ifdef ZEND_WIN32
368ee2a4a9SAnatol Belski#  ifdef _WIN64
37c3e3c98eSAnatol Belskitypedef __int64 zend_long;
38c3e3c98eSAnatol Belskitypedef unsigned __int64 zend_ulong;
398ee2a4a9SAnatol Belskitypedef __int64 zend_off_t;
404d997f63SAnatol Belski#   define ZEND_LONG_MAX _I64_MAX
414d997f63SAnatol Belski#   define ZEND_LONG_MIN _I64_MIN
42455741fcSAnatol Belski#   define ZEND_ULONG_MAX _UI64_MAX
43b9514bb8SAnatol Belski#   define Z_L(i) i##i64
44455741fcSAnatol Belski#   define Z_UL(i) i##Ui64
458ee2a4a9SAnatol Belski#  else
468ee2a4a9SAnatol Belski#   error Cant enable 64 bit integers on non 64 bit platform
478ee2a4a9SAnatol Belski#  endif
488ee2a4a9SAnatol Belski# else
498ee2a4a9SAnatol Belski#  if defined(__X86_64__) || defined(__LP64__) || defined(_LP64)
50c3e3c98eSAnatol Belskitypedef int64_t zend_long;
51c3e3c98eSAnatol Belskitypedef uint64_t zend_ulong;
528ee2a4a9SAnatol Belskitypedef off_t zend_off_t;
534d997f63SAnatol Belski#   define ZEND_LONG_MAX INT64_MAX
544d997f63SAnatol Belski#   define ZEND_LONG_MIN INT64_MIN
55455741fcSAnatol Belski#   define ZEND_ULONG_MAX UINT64_MAX
56b9514bb8SAnatol Belski#   define Z_L(i) i##LL
57455741fcSAnatol Belski#   define Z_UL(i) i##ULL
588ee2a4a9SAnatol Belski#  else
598ee2a4a9SAnatol Belski#   error Cant enable 64 bit integers on non 64 bit platform
608ee2a4a9SAnatol Belski#  endif
618ee2a4a9SAnatol Belski# endif
6228b7a033SAnatol Belski# define SIZEOF_ZEND_LONG 8
638ee2a4a9SAnatol Belski#else
64c429c74bSAnatol Belskitypedef int32_t zend_long;
65c429c74bSAnatol Belskitypedef uint32_t zend_ulong;
66c429c74bSAnatol Belskitypedef int32_t zend_off_t;
67c429c74bSAnatol Belski# define ZEND_LONG_MAX INT32_MAX
68c429c74bSAnatol Belski# define ZEND_LONG_MIN INT32_MIN
69c429c74bSAnatol Belski# define ZEND_ULONG_MAX UINT32_MAX
70b9514bb8SAnatol Belski# define Z_L(i) i##L
71455741fcSAnatol Belski# define Z_UL(i) i##UL
7228b7a033SAnatol Belski# define SIZEOF_ZEND_LONG SIZEOF_LONG
738ee2a4a9SAnatol Belski#endif
748ee2a4a9SAnatol Belski
758ee2a4a9SAnatol Belski
768ee2a4a9SAnatol Belski/* conversion macros */
774d997f63SAnatol Belski#define ZEND_LTOA_BUF_LEN 65
788ee2a4a9SAnatol Belski
798ee2a4a9SAnatol Belski#ifdef ZEND_ENABLE_INT64
80c429c74bSAnatol Belski# define ZEND_LONG_FMT "%" PRId64
81c429c74bSAnatol Belski# define ZEND_ULONG_FMT "%" PRIu64
82c429c74bSAnatol Belski# define ZEND_LONG_FMT_SPEC PRId64
83c429c74bSAnatol Belski# define ZEND_ULONG_FMT_SPEC PRIu64
848ee2a4a9SAnatol Belski# ifdef PHP_WIN32
854d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) _i64toa_s((i), (s), (len), 10)
864d997f63SAnatol Belski#  define ZEND_ATOL(i, s) i = _atoi64((s))
874d997f63SAnatol Belski#  define ZEND_STRTOL(s0, s1, base) _strtoi64((s0), (s1), (base))
884d997f63SAnatol Belski#  define ZEND_STRTOUL(s0, s1, base) _strtoui64((s0), (s1), (base))
894d997f63SAnatol Belski#  define ZEND_STRTOL_PTR _strtoi64
904d997f63SAnatol Belski#  define ZEND_STRTOUL_PTR _strtoui64
918ee2a4a9SAnatol Belski#  define ZEND_ABS _abs64
928ee2a4a9SAnatol Belski# else
934d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) \
948ee2a4a9SAnatol Belski	do { \
95c429c74bSAnatol Belski		int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
968ee2a4a9SAnatol Belski		(s)[st] = '\0'; \
978ee2a4a9SAnatol Belski 	} while (0)
984d997f63SAnatol Belski#  define ZEND_ATOL(i, s) (i) = atoll((s))
994d997f63SAnatol Belski#  define ZEND_STRTOL(s0, s1, base) strtoll((s0), (s1), (base))
1004d997f63SAnatol Belski#  define ZEND_STRTOUL(s0, s1, base) strtoull((s0), (s1), (base))
1014d997f63SAnatol Belski#  define ZEND_STRTOL_PTR strtoll
1024d997f63SAnatol Belski#  define ZEND_STRTOUL_PTR strtoull
1038ee2a4a9SAnatol Belski#  define ZEND_ABS llabs
1048ee2a4a9SAnatol Belski# endif
1058ee2a4a9SAnatol Belski#else
1064d997f63SAnatol Belski# define ZEND_STRTOL(s0, s1, base) strtol((s0), (s1), (base))
1074d997f63SAnatol Belski# define ZEND_STRTOUL(s0, s1, base) strtoul((s0), (s1), (base))
108c429c74bSAnatol Belski# define ZEND_LONG_FMT "%" PRId32
109c429c74bSAnatol Belski# define ZEND_ULONG_FMT "%" PRIu32
110c429c74bSAnatol Belski# define ZEND_LONG_FMT_SPEC PRId32
111c429c74bSAnatol Belski# define ZEND_ULONG_FMT_SPEC PRIu32
1128ee2a4a9SAnatol Belski# ifdef PHP_WIN32
1134d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) _ltoa_s((i), (s), (len), 10)
1144d997f63SAnatol Belski#  define ZEND_ATOL(i, s) i = atol((s))
1158ee2a4a9SAnatol Belski# else
1164d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) \
1178ee2a4a9SAnatol Belski	do { \
118c429c74bSAnatol Belski		int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
1198ee2a4a9SAnatol Belski		(s)[st] = '\0'; \
1208ee2a4a9SAnatol Belski 	} while (0)
1214d997f63SAnatol Belski#  define ZEND_ATOL(i, s) (i) = atol((s))
1228ee2a4a9SAnatol Belski# endif
1234d997f63SAnatol Belski# define ZEND_STRTOL_PTR strtol
1244d997f63SAnatol Belski# define ZEND_STRTOUL_PTR strtoul
1258ee2a4a9SAnatol Belski# define ZEND_ABS abs
1268ee2a4a9SAnatol Belski#endif
1278ee2a4a9SAnatol Belski
1288ee2a4a9SAnatol Belski
1294d997f63SAnatol Belski#endif /* ZEND_LONG_H */
1308ee2a4a9SAnatol Belski
1318ee2a4a9SAnatol Belski/*
1328ee2a4a9SAnatol Belski * Local variables:
1338ee2a4a9SAnatol Belski * tab-width: 4
1348ee2a4a9SAnatol Belski * c-basic-offset: 4
1358ee2a4a9SAnatol Belski * indent-tabs-mode: t
1368ee2a4a9SAnatol Belski * End:
1378ee2a4a9SAnatol Belski */
138