Debian Codegraph @

include/ruby/backward/2/limits.h

raw
1 #ifndef RUBY_BACKWARD2_LIMITS_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RUBY_BACKWARD2_LIMITS_H
3 /**
4 * @author Ruby developers <[email protected]>
5 * @copyright This file is a part of the programming language Ruby.
6 * Permission is hereby granted, to either redistribute and/or
7 * modify this file, provided that the conditions mentioned in the
8 * file COPYING are met. Consult the file for details.
9 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
10 * implementation details. Don't take them as canon. They could
11 * rapidly appear then vanish. The name (path) of this header file
12 * is also an implementation detail. Do not expect it to persist
13 * at the place it is now. Developers are free to move it anywhere
14 * anytime at will.
15 * @note To ruby-core: remember that this header can be possibly
16 * recursively included from extension libraries written in C++.
17 * Do not expect for instance `__VA_ARGS__` is always available.
18 * We assume C99 for ruby itself but we don't assume languages of
19 * extension libraries. They could be written in C++98.
20 * @brief Historical shim for `<limits.h>`.
21 *
22 * The macros in this header file are obsolescent. Does anyone really need our
23 * own definition of `CHAR_BIT` today?
24 */
25 #include "ruby/internal/config.h"
26
27 #ifdef HAVE_LIMITS_H
28 # include <limits.h>
29 #endif
30
31 #include "ruby/backward/2/long_long.h"
32
33 #ifndef LONG_MAX
34 # /* assuming 32bit(2's complement) long */
35 # define LONG_MAX 2147483647L
36 #endif
37
38 #ifndef LONG_MIN
39 # define LONG_MIN (-LONG_MAX-1)
40 #endif
41
42 #ifndef CHAR_BIT
43 # define CHAR_BIT 8
44 #endif
45
46 #ifdef LLONG_MAX
47 # /* Take that. */
48 #elif defined(LONG_LONG_MAX)
49 # define LLONG_MAX LONG_LONG_MAX
50 #elif defined(_I64_MAX)
51 # define LLONG_MAX _I64_MAX
52 #else
53 # /* assuming 64bit(2's complement) long long */
54 # define LLONG_MAX 9223372036854775807LL
55 #endif
56
57 #ifdef LLONG_MIN
58 # /* Take that. */
59 #elif defined(LONG_LONG_MIN)
60 # define LLONG_MIN LONG_LONG_MIN
61 #elif defined(_I64_MAX)
62 # define LLONG_MIN _I64_MIN
63 #else
64 # define LLONG_MIN (-LLONG_MAX-1)
65 #endif
66
67 #ifdef SIZE_MAX
68 # /* Take that. */
69 #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
70 # define SIZE_MAX ULLONG_MAX
71 # define SIZE_MIN ULLONG_MIN
72 #elif SIZEOF_SIZE_T == SIZEOF_LONG
73 # define SIZE_MAX ULONG_MAX
74 # define SIZE_MIN ULONG_MIN
75 #elif SIZEOF_SIZE_T == SIZEOF_INT
76 # define SIZE_MAX UINT_MAX
77 # define SIZE_MIN UINT_MIN
78 #else
79 # define SIZE_MAX USHRT_MAX
80 # define SIZE_MIN USHRT_MIN
81 #endif
82
83 #ifdef SSIZE_MAX
84 # /* Take that. */
85 #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
86 # define SSIZE_MAX LLONG_MAX
87 # define SSIZE_MIN LLONG_MIN
88 #elif SIZEOF_SIZE_T == SIZEOF_LONG
89 # define SSIZE_MAX LONG_MAX
90 # define SSIZE_MIN LONG_MIN
91 #elif SIZEOF_SIZE_T == SIZEOF_INT
92 # define SSIZE_MAX INT_MAX
93 # define SSIZE_MIN INT_MIN
94 #else
95 # define SSIZE_MAX SHRT_MAX
96 # define SSIZE_MIN SHRT_MIN
97 #endif
98
99 #endif /* RUBY_BACKWARD2_LIMITS_H */