Add C89 stdint compatibility
This commit is contained in:
parent
7c0333124b
commit
27224cdd4c
4 changed files with 100 additions and 9 deletions
5
configure
vendored
5
configure
vendored
|
|
@ -221,6 +221,7 @@ HAVE_B64_NTOP=
|
||||||
HAVE_CAPSICUM=
|
HAVE_CAPSICUM=
|
||||||
HAVE_CRYPT=
|
HAVE_CRYPT=
|
||||||
HAVE_CRYPT_NEWHASH=
|
HAVE_CRYPT_NEWHASH=
|
||||||
|
HAVE_C99_STDINT=
|
||||||
HAVE_ENDIAN_H=
|
HAVE_ENDIAN_H=
|
||||||
HAVE_ERR=
|
HAVE_ERR=
|
||||||
HAVE_EXPLICIT_BZERO=
|
HAVE_EXPLICIT_BZERO=
|
||||||
|
|
@ -391,6 +392,7 @@ runtest b64_ntop B64_NTOP "" "" "-lresolv" || true
|
||||||
runtest capsicum CAPSICUM || true
|
runtest capsicum CAPSICUM || true
|
||||||
runtest crypt CRYPT "" "" "-lcrypt" || true
|
runtest crypt CRYPT "" "" "-lcrypt" || true
|
||||||
runtest crypt_newhash CRYPT_NEWHASH || true
|
runtest crypt_newhash CRYPT_NEWHASH || true
|
||||||
|
runtest c99_stdint C99_STDINT || true
|
||||||
runtest endian_h ENDIAN_H || true
|
runtest endian_h ENDIAN_H || true
|
||||||
runtest err ERR || true
|
runtest err ERR || true
|
||||||
runtest explicit_bzero EXPLICIT_BZERO || true
|
runtest explicit_bzero EXPLICIT_BZERO || true
|
||||||
|
|
@ -513,7 +515,7 @@ fi
|
||||||
if [ ${HAVE_MD5} -eq 0 -o \
|
if [ ${HAVE_MD5} -eq 0 -o \
|
||||||
${HAVE_SHA2} -eq 0 ]
|
${HAVE_SHA2} -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "#include <stdint.h> /* C99 [u]int[nn]_t types */"
|
echo "#include \"sj_stdint.h\" /* C99 stdint.h or C89 fallback types */"
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -555,6 +557,7 @@ cat << __HEREDOC__
|
||||||
#define HAVE_CAPSICUM ${HAVE_CAPSICUM}
|
#define HAVE_CAPSICUM ${HAVE_CAPSICUM}
|
||||||
#define HAVE_CRYPT ${HAVE_CRYPT}
|
#define HAVE_CRYPT ${HAVE_CRYPT}
|
||||||
#define HAVE_CRYPT_NEWHASH ${HAVE_CRYPT_NEWHASH}
|
#define HAVE_CRYPT_NEWHASH ${HAVE_CRYPT_NEWHASH}
|
||||||
|
#define HAVE_C99_STDINT ${HAVE_C99_STDINT}
|
||||||
#define HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
|
#define HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
|
||||||
#define HAVE_ERR ${HAVE_ERR}
|
#define HAVE_ERR ${HAVE_ERR}
|
||||||
#define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
|
#define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
|
||||||
|
|
|
||||||
66
sj_stdint.h
Normal file
66
sj_stdint.h
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Small fixed-width integer compatibility layer for SJ3.
|
||||||
|
*
|
||||||
|
* In C99 or newer translation units, use <stdint.h>. In C89 translation
|
||||||
|
* units, provide the fixed-width names that SJ3 needs when the host integer
|
||||||
|
* model has matching types.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SJ_STDINT_H_
|
||||||
|
#define SJ_STDINT_H_
|
||||||
|
|
||||||
|
#if defined(HAVE_C99_STDINT) && HAVE_C99_STDINT && \
|
||||||
|
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||||
|
#include <stdint.h>
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#if !defined(UINT8_MAX)
|
||||||
|
# if UCHAR_MAX == 255
|
||||||
|
typedef signed char int8_t;
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
# define UINT8_MAX UCHAR_MAX
|
||||||
|
# else
|
||||||
|
# error "SJ3 requires an 8-bit unsigned char"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(UINT16_MAX)
|
||||||
|
# if USHRT_MAX == 65535
|
||||||
|
typedef short int16_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
# define UINT16_MAX USHRT_MAX
|
||||||
|
# else
|
||||||
|
# error "SJ3 requires a 16-bit unsigned short"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(UINT32_MAX)
|
||||||
|
# if UINT_MAX == 4294967295U
|
||||||
|
typedef int int32_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
# define UINT32_MAX UINT_MAX
|
||||||
|
# elif ULONG_MAX == 4294967295UL
|
||||||
|
typedef long int32_t;
|
||||||
|
typedef unsigned long uint32_t;
|
||||||
|
# define UINT32_MAX ULONG_MAX
|
||||||
|
# else
|
||||||
|
# error "SJ3 requires a 32-bit integer type"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(UINT64_MAX) && (ULONG_MAX > 4294967295UL)
|
||||||
|
typedef long int64_t;
|
||||||
|
typedef unsigned long uint64_t;
|
||||||
|
# define UINT64_MAX ULONG_MAX
|
||||||
|
#elif !defined(UINT64_MAX) && (defined(_MSC_VER) || defined(_WIN32))
|
||||||
|
typedef __int64 int64_t;
|
||||||
|
typedef unsigned __int64 uint64_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* SJ_STDINT_H_ */
|
||||||
17
sj_typedef.h
17
sj_typedef.h
|
|
@ -40,17 +40,18 @@
|
||||||
#define _SJ_TYPEDEF 1
|
#define _SJ_TYPEDEF 1
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "sj_stdint.h"
|
||||||
|
|
||||||
typedef unsigned char TypeGroup;
|
typedef uint8_t TypeGroup;
|
||||||
typedef unsigned char TypeGram;
|
typedef uint8_t TypeGram;
|
||||||
typedef unsigned short TypeIdxOfs;
|
typedef uint16_t TypeIdxOfs;
|
||||||
typedef short TypeDicSeg;
|
typedef short TypeDicSeg;
|
||||||
typedef unsigned short TypeDicOfs;
|
typedef uint16_t TypeDicOfs;
|
||||||
typedef ino_t TypeDicID;
|
typedef ino_t TypeDicID;
|
||||||
typedef unsigned char TypeCnct;
|
typedef uint8_t TypeCnct;
|
||||||
typedef unsigned short TypeStyNum;
|
typedef uint16_t TypeStyNum;
|
||||||
typedef unsigned char TypeClass;
|
typedef uint8_t TypeClass;
|
||||||
typedef unsigned char TypeBunNum;
|
typedef uint8_t TypeBunNum;
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
# define NULL 0
|
# define NULL 0
|
||||||
|
|
|
||||||
21
tests.c
21
tests.c
|
|
@ -81,6 +81,27 @@ main(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* TEST_CRYPT_NEWHASH */
|
#endif /* TEST_CRYPT_NEWHASH */
|
||||||
|
#if TEST_C99_STDINT
|
||||||
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
|
||||||
|
# error "C99 is required for stdint.h"
|
||||||
|
#endif
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
uint8_t u8;
|
||||||
|
uint16_t u16;
|
||||||
|
uint32_t u32;
|
||||||
|
uint64_t u64;
|
||||||
|
|
||||||
|
u8 = 0;
|
||||||
|
u16 = 0;
|
||||||
|
u32 = 0;
|
||||||
|
u64 = 0;
|
||||||
|
return (int)(u8 + u16 + u32 + u64);
|
||||||
|
}
|
||||||
|
#endif /* TEST_C99_STDINT */
|
||||||
#if TEST_ENDIAN_H
|
#if TEST_ENDIAN_H
|
||||||
#if defined(__linux__) || defined(__wasi__)
|
#if defined(__linux__) || defined(__wasi__)
|
||||||
# define _DEFAULT_SOURCE
|
# define _DEFAULT_SOURCE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue