Changeset 3f7fe9e in mainline for abi/include/limits.h


Ignore:
Timestamp:
2018-10-01T18:36:42Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5cef315
Parents:
1938b381
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-29 16:13:55)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-10-01 18:36:42)
Message:

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.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • abi/include/limits.h

    r1938b381 r3f7fe9e  
    3636#define LIBC_LIMITS_H_
    3737
    38 #ifdef __cplusplus
    39 extern "C" {
     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");
    4064#endif
    4165
    42 #include <_bits/limits.h>
     66#define CHAR_MAX  SCHAR_MAX
     67#define CHAR_MIN  SCHAR_MIN
    4368
    44 #ifdef __cplusplus
    45 }
     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
    46103#endif
    47104
Note: See TracChangeset for help on using the changeset viewer.