limits.c revision 1
1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * Glenn Fowler
1N/A * AT&T Research
1N/A *
1N/A * generate limits features
1N/A *
1N/A * FOPEN_MAX POSIX says ANSI defines it but it's not in ANSI
1N/A *
1N/A * NOTE: two's complement binary integral representation assumed
1N/A */
1N/A
1N/A#if defined(__STDPP__directive) && defined(__STDPP__hide)
1N/A__STDPP__directive pragma pp:hide getpagesize getdtablesize
1N/A#else
1N/A#define getpagesize ______getpagesize
1N/A#define getdtablesize ______getdtablesize
1N/A#endif
1N/A
1N/A/*
1N/A * we'd like as many symbols as possible defined
1N/A * the standards push the vendors the other way
1N/A * but don't provide guard that lets everything through
1N/A * so each vendor adds their own guard
1N/A * many now include something like <standards.h> to
1N/A * get it straight in one place -- <sys/types.h> should
1N/A * kick that in
1N/A */
1N/A
1N/A#include "FEATURE/standards"
1N/A#include "FEATURE/lib"
1N/A
1N/A#ifdef __sun
1N/A#define _timespec timespec
1N/A#endif
1N/A
1N/A#include <sys/types.h>
1N/A
1N/A#undef _SGIAPI
1N/A#define _SGIAPI 1
1N/A
1N/A#if _hdr_limits
1N/A#include <limits.h>
1N/A#endif
1N/A
1N/A#undef _SGIAPI
1N/A#define _SGIAPI 0
1N/A
1N/A#include "FEATURE/lib"
1N/A#include "FEATURE/common"
1N/A
1N/A#if _hdr_unistd
1N/A#include <unistd.h>
1N/A#endif
1N/A
1N/A#include "FEATURE/param"
1N/A
1N/A#if defined(__STDPP__directive) && defined(__STDPP__hide)
1N/A__STDPP__directive pragma pp:nohide getpagesize getdtablesize
1N/A#else
1N/A#undef getpagesize
1N/A#undef getdtablesize
1N/A#endif
1N/A
1N/Aint main()
1N/A{
1N/A char c;
1N/A unsigned char uc;
1N/A unsigned short us;
1N/A unsigned int ui;
1N/A unsigned long ul;
1N/A unsigned long val;
1N/A#if _typ_uint64_t
1N/A uint64_t ull;
1N/A uint64_t vll;
1N/A#endif
1N/A
1N/A /*
1N/A * <limits.h> with *constant* valued macros
1N/A */
1N/A
1N/A printf("\n");
1N/A#ifndef CHAR_BIT
1N/A uc = 0;
1N/A uc = ~uc;
1N/A val = 1;
1N/A while (uc >>= 1) val++;
1N/A printf("#define CHAR_BIT %lu\n", val);
1N/A#endif
1N/A#ifndef MB_LEN_MAX
1N/A val = 1;
1N/A printf("#define MB_LEN_MAX %lu\n", val);
1N/A#endif
1N/A
1N/A c = 0;
1N/A c = ~c;
1N/A uc = 0;
1N/A uc = ~uc;
1N/A us = 0;
1N/A us = ~us;
1N/A ui = 0;
1N/A ui = ~ui;
1N/A ul = 0;
1N/A ul = ~ul;
1N/A#if _typ_uint64_t
1N/A ull = 0;
1N/A ull = ~ull;
1N/A#endif
1N/A
1N/A#ifndef UCHAR_MAX
1N/A val = uc;
1N/A printf("#if defined(__STDC__)\n");
1N/A printf("#define UCHAR_MAX %luU\n", val);
1N/A printf("#else\n");
1N/A printf("#define UCHAR_MAX %lu\n", val);
1N/A printf("#endif\n");
1N/A#endif
1N/A
1N/A#ifndef SCHAR_MIN
1N/A val = (unsigned char)(uc >> 1) + 1;
1N/A printf("#define SCHAR_MIN (-%lu)\n", val);
1N/A#endif
1N/A
1N/A#ifndef SCHAR_MAX
1N/A val = (unsigned char)(uc >> 1);
1N/A printf("#define SCHAR_MAX %lu\n", val);
1N/A#endif
1N/A
1N/A if (c < 0)
1N/A {
1N/A#ifndef CHAR_MIN
1N/A printf("#define CHAR_MIN SCHAR_MIN\n");
1N/A#endif
1N/A
1N/A#ifndef CHAR_MAX
1N/A printf("#define CHAR_MAX SCHAR_MAX\n");
1N/A#endif
1N/A }
1N/A else
1N/A {
1N/A#ifndef CHAR_MIN
1N/A printf("#define CHAR_MIN 0\n");
1N/A#endif
1N/A
1N/A#ifndef CHAR_MAX
1N/A printf("#define CHAR_MAX UCHAR_MAX\n");
1N/A#endif
1N/A }
1N/A
1N/A#ifndef USHRT_MAX
1N/A val = us;
1N/A printf("#if defined(__STDC__)\n");
1N/A printf("#define USHRT_MAX %luU\n", val);
1N/A printf("#else\n");
1N/A printf("#define USHRT_MAX %lu\n", val);
1N/A printf("#endif\n");
1N/A#endif
1N/A
1N/A#ifndef SHRT_MIN
1N/A val = (unsigned short)(us >> 1) + 1;
1N/A printf("#define SHRT_MIN (-%lu)\n", val);
1N/A#endif
1N/A
1N/A#ifndef SHRT_MAX
1N/A val = (unsigned short)(us >> 1);
1N/A printf("#define SHRT_MAX %lu\n", val);
1N/A#endif
1N/A
1N/A if (ui == us)
1N/A {
1N/A#ifndef UINT_MAX
1N/A printf("#define UINT_MAX USHRT_MAX\n");
1N/A#endif
1N/A
1N/A#ifndef INT_MIN
1N/A printf("#define INT_MIN SHRT_MIN\n");
1N/A#endif
1N/A
1N/A#ifndef INT_MAX
1N/A printf("#define INT_MAX SHRT_MAX\n");
1N/A#endif
1N/A }
1N/A else
1N/A {
1N/A#ifndef UINT_MAX
1N/A val = ui;
1N/A printf("#if defined(__STDC__)\n");
1N/A printf("#define UINT_MAX %luU\n", val);
1N/A printf("#else\n");
1N/A printf("#define UINT_MAX %lu\n", val);
1N/A printf("#endif\n");
1N/A#endif
1N/A
1N/A#ifndef INT_MIN
1N/A val = (unsigned int)(ui >> 1) + 1;
1N/A if (ui == ul) printf("#define INT_MIN (-%lu-1)\n", val - 1);
1N/A else printf("#define INT_MIN (-%lu)\n", val);
1N/A#endif
1N/A
1N/A#ifndef INT_MAX
1N/A val = (unsigned int)(ui >> 1);
1N/A printf("#define INT_MAX %lu\n", val);
1N/A#endif
1N/A }
1N/A
1N/A if (ul == ui)
1N/A {
1N/A#ifndef ULONG_MAX
1N/A printf("#define ULONG_MAX UINT_MAX\n");
1N/A#endif
1N/A
1N/A#ifndef LONG_MIN
1N/A printf("#define LONG_MIN INT_MIN\n");
1N/A#endif
1N/A
1N/A#ifndef LONG_MAX
1N/A printf("#define LONG_MAX INT_MAX\n");
1N/A#endif
1N/A }
1N/A else
1N/A {
1N/A#ifndef ULONG_MAX
1N/A val = ul;
1N/A printf("#if defined(__STDC__)\n");
1N/A printf("#define ULONG_MAX %luLU\n", val);
1N/A printf("#else\n");
1N/A printf("#define ULONG_MAX %lu\n", val);
1N/A printf("#endif\n");
1N/A#endif
1N/A
1N/A#ifndef LONG_MIN
1N/A val = (unsigned long)(ul >> 1) + 1;
1N/A printf("#define LONG_MIN (-%luL-1L)\n", val - 1);
1N/A#endif
1N/A
1N/A#ifndef LONG_MAX
1N/A val = (unsigned long)(ul >> 1);
1N/A printf("#define LONG_MAX %luL\n", val);
1N/A#endif
1N/A }
1N/A
1N/A#if _typ_uint64_t && !_ast_intmax_long
1N/A if (ull == ul)
1N/A {
1N/A#ifndef ULLONG_MAX
1N/A printf("#define ULLONG_MAX ULONG_MAX\n");
1N/A#endif
1N/A
1N/A#ifndef LLONG_MIN
1N/A printf("#define LLONG_MIN LONG_MIN\n");
1N/A#endif
1N/A
1N/A#ifndef LLONG_MAX
1N/A printf("#define LLONG_MAX LONG_MAX\n");
1N/A#endif
1N/A }
1N/A else
1N/A {
1N/A#ifndef ULLONG_MAX
1N/A vll = ull;
1N/A printf("#ifndef ULLONG_MAX\n");
1N/A printf("#if defined(__STDC__) && _ast_LL\n");
1N/A printf("#define ULLONG_MAX %lluULL\n", vll);
1N/A printf("#else\n");
1N/A printf("#define ULLONG_MAX %llu\n", vll);
1N/A printf("#endif\n");
1N/A printf("#endif\n");
1N/A#endif
1N/A
1N/A#ifndef LLONG_MIN
1N/A vll = (uint64_t)(ull >> 1) + 1;
1N/A printf("#ifndef LLONG_MIN\n");
1N/A printf("#if defined(__STDC__) && _ast_LL\n");
1N/A printf("#define LLONG_MIN (-%lluLL-1LL)\n", vll - 1);
1N/A printf("#else\n");
1N/A printf("#define LLONG_MIN (-%llu-1)\n", vll - 1);
1N/A printf("#endif\n");
1N/A printf("#endif\n");
1N/A#endif
1N/A
1N/A#ifndef LLONG_MAX
1N/A vll = (uint64_t)(ull >> 1);
1N/A printf("#ifndef LLONG_MAX\n");
1N/A printf("#if defined(__STDC__) && _ast_LL\n");
1N/A printf("#define LLONG_MAX %lluLL\n", vll);
1N/A printf("#else\n");
1N/A printf("#define LLONG_MAX %llu\n", vll);
1N/A printf("#endif\n");
1N/A printf("#endif\n");
1N/A#endif
1N/A }
1N/A#endif
1N/A
1N/A printf("\n");
1N/A#ifdef _UWIN
1N/A printf("#ifdef _UWIN\n");
1N/A printf("#ifndef DBL_DIG\n");
1N/A printf("#define DBL_DIG 15\n");
1N/A printf("#endif\n");
1N/A printf("#ifndef DBL_MAX\n");
1N/A printf("#define DBL_MAX 1.7976931348623158e+308\n");
1N/A printf("#endif\n");
1N/A printf("#ifndef FLT_DIG\n");
1N/A printf("#define FLT_DIG 6\n");
1N/A printf("#endif\n");
1N/A printf("#ifndef FLT_MAX\n");
1N/A printf("#define FLT_MAX 3.402823466e+38F\n");
1N/A printf("#endif\n");
1N/A printf("#endif\n");
1N/A printf("\n");
1N/A#endif
1N/A
1N/A#include "conflim.h"
1N/A
1N/A printf("\n");
1N/A
1N/A return 0;
1N/A}