source: mainline/abi/include/limits.h@ e344422

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e344422 was 3f7fe9e, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Clean up headers

Depends on <limits.h> and <stdint.h> being provided, which is a step up from
depending on mostly undocumented predefined macros.
In principle, <limits.h> and <stdint.h> mostly describe properties of
the compiler, so even though we depend on certain values for their contents,
actually defining them in the library is kind of reversal of concerns.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2017 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#ifndef LIBC_LIMITS_H_
36#define LIBC_LIMITS_H_
37
38#ifdef __GNUC__
39/*
40 * Default to compiler's version of limits.h, so we don't have to care about
41 * language version and whatnot.
42 */
43#include_next <limits.h>
44#else
45
46/* HelenOS requires 8-bit char and two's complement arithmetic. */
47#define CHAR_BIT 8
48#define SCHAR_MAX 0x7f
49#define SCHAR_MIN (-SCHAR_MAX - 1)
50#define SHRT_MAX 0x7fff
51#define SHRT_MIN (-SHRT_MAX - 1)
52#define INT_MAX 0x7fffffff
53#define INT_MIN (-INT_MAX - 1)
54#define LLONG_MAX 0x7fffffffffffffffll
55#define LLONG_MIN (-LLONG_MAX - 1)
56
57#define UCHAR_MAX 0xff
58#define USHRT_MAX 0xffff
59#define UINT_MAX 0xffffffffu
60#define ULLONG_MAX 0xffffffffffffffffull
61
62#if __STDC_VERSION__ >= 201112L
63_Static_assert(((char)-1) < 0, "char should be signed");
64#endif
65
66#define CHAR_MAX SCHAR_MAX
67#define CHAR_MIN SCHAR_MIN
68
69#ifdef __32_BITS__
70#define LONG_MAX 0x7fffffffl
71#define LONG_MIN (-LONG_MAX - 1)
72#define ULONG_MAX 0xfffffffful
73#endif
74
75#ifdef __64_BITS__
76#define LONG_MAX 0x7fffffffffffffffl
77#define LONG_MIN (-LONG_MAX - 1)
78#define ULONG_MAX 0xfffffffffffffffful
79#endif
80
81#endif /* !defined(__GNUC__) */
82
83#undef MB_LEN_MAX
84#define MB_LEN_MAX 4
85
86#define UCHAR_MIN 0
87#define USHRT_MIN 0
88#define UINT_MIN (0u)
89#define ULONG_MIN (0ul)
90#define ULLONG_MIN (0ull)
91
92/* GCC's <limits.h> doesn't define these for C++11, even though it should. */
93#if __cplusplus >= 201103L
94#ifndef LLONG_MAX
95#define LLONG_MAX 0x7fffffffffffffffll
96#endif
97#ifndef LLONG_MIN
98#define LLONG_MIN (-LLONG_MAX - 1)
99#endif
100#ifndef ULLONG_MAX
101#define ULLONG_MAX 0xffffffffffffffffull
102#endif
103#endif
104
105#endif
106
107/** @}
108 */
Note: See TracBrowser for help on using the repository browser.