VSF Documented
type.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_TYPE_H_INCLUDED__
19#define __VSF_TYPE_H_INCLUDED__
20
21
22
23/*============================ INCLUDES ======================================*/
24
25#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
26typedef unsigned char uint8_t;
27typedef signed char int8_t;
28typedef unsigned char uint_fast8_t;
29typedef signed char int_fast8_t;
30
31typedef unsigned short uint16_t;
32typedef signed short int16_t;
33typedef unsigned short uint_fast16_t;
34typedef signed short int_fast16_t;
35
36typedef unsigned long int uint32_t;
37typedef signed long int int32_t;
38typedef unsigned long int uint_fast32_t;
39typedef signed long int int_fast32_t;
40
45#else
46#include <stdint.h>
47#endif
48
49#if !defined(__USE_LOCAL_STDBOOL__)
50# if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
51typedef enum {
52 false = 0,
53 true = !false,
54} bool;
55# else
56# include <stdbool.h>
57# endif
58#else
59# undef __USE_LOCAL_STDINT_STDBOOL__
60#endif
61
62#if !__IS_COMPILER_GCC__ && !__IS_COMPILER_LLVM__
63# include <uchar.h>
64#endif
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/*============================ MACROS ========================================*/
71
72#define __optimal_bit_sz (sizeof(uintalu_t) * 8)
73#define __optimal_bit_msk (__optimal_bit_sz - 1)
74
75/*============================ MACROFIED FUNCTIONS ===========================*/
76/*============================ TYPES =========================================*/
77
78#if defined(__CPU_X86__) || defined(__CPU_WEBASSEMBLY__)
79typedef uint32_t uintalu_t;
80typedef int32_t intalu_t;
81#elif defined(__CPU_X64__)
82typedef uint64_t uintalu_t;
83typedef int64_t intalu_t;
84#endif
85
86/*============================ GLOBAL VARIABLES ==============================*/
87/*============================ LOCAL VARIABLES ===============================*/
88/*============================ PROTOTYPES ====================================*/
89
90#ifdef __cplusplus
91}
92#endif
93
94#endif // __APP_TYPE_H_INCLUDED__
95
96/*============================ Multiple-Entry ================================*/
97
98#include "../__common/__type.h"
99
100/*============================ Library Patch ================================*/
101
102#ifdef __cplusplus
103extern "C" {
104#endif
105
106#ifdef __WIN__
107# if !(VSF_USE_LINUX == ENABLED && VSF_LINUX_USE_SIMPLE_LIBC == ENABLED && VSF_LINUX_USE_SIMPLE_STDIO == ENABLED)
108// __WIN__ has no 64-bit stdio APIs, if simple_stdio in simple_libc is not used,
109// implement 64-but stdio APIs here
110
111# ifndef __VSF_COMPILER_STDIO_H__
112# define __VSF_COMPILER_STDIO_H__
113# ifdef __CPU_X64__
114typedef long long off_t;
115# else
116typedef long off_t;
117# endif
118typedef long long off64_t;
119# endif
120
121# define ftello64 ftell
122# define fseeko64 fseek
123# define ftello ftell
124# define fseeko fseek
125# endif
126
127// win has no such constants in math.h
128# define M_E 2.71828182845904523536 // e
129# define M_LOG2E 1.44269504088896340736 // log2(e)
130# define M_LOG10E 0.434294481903251827651 // log10(e)
131# define M_LN2 0.693147180559945309417 // ln(2)
132# define M_LN10 2.30258509299404568402 // ln(10)
133# define M_PI 3.14159265358979323846 // pi
134# define M_PI_2 1.57079632679489661923 // pi/2
135# define M_PI_4 0.785398163397448309616 // pi/4
136# define M_1_PI 0.318309886183790671538 // 1/pi
137# define M_2_PI 0.636619772367581343076 // 2/pi
138# define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi)
139# define M_SQRT2 1.41421356237309504880 // sqrt(2)
140# define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2)
141
142// __WIN__ uses stricmp instead of strcasecmp in strings.h
143# ifndef __VSF_APPLET__
144# define strcasecmp stricmp
145# define strncasecmp strnicmp
146# endif
147// __WIN__ uses _alloca instead of alloca in alloca.h
148
149# ifndef __VSF_APPLET__
150# ifndef alloca
151# define alloca _alloca
152# endif
153extern void * _alloca(size_t);
154extern int stricmp(const char *s1, const char *s2);
155extern int strnicmp(const char *s1, const char *s2, size_t n);
156
157extern char * strsep(char **stringp, const char *delim);
158extern size_t strlcpy(char *dst, const char *src, size_t dsize);
159extern size_t strlcat(char *dst, const char *src, size_t dsize);
160extern char * strcasestr(const char *str, const char *substr);
161extern char * strtok_r(char *str, const char *delim, char **saveptr);
162
163extern void srandom(unsigned int seed);
164extern long int random(void);
165# endif
166
167#include <time.h>
168# if !(VSF_USE_LINUX == ENABLED && VSF_LINUX_USE_SIMPLE_LIBC == ENABLED && VSF_LINUX_USE_SIMPLE_TIME == ENABLED)
169# ifndef __VSF_COMPILER_TIME_H__
170# define __VSF_COMPILER_TIME_H__
171typedef enum {
174} clockid_t;
175extern int clock_gettime(clockid_t clk_id, struct timespec *tp);
176extern int nanosleep(const struct timespec *requested_time, struct timespec *remaining);
177# endif
178# endif
179#endif
180
181#ifdef __cplusplus
182}
183#endif
int64_t intmax_t
Definition type.h:52
uint32_t uintptr_t
Definition type.h:49
unsigned int uint_fast16_t
Definition type.h:32
signed short int16_t
Definition type.h:31
unsigned short uint16_t
Definition type.h:30
uint64_t uintmax_t
Definition type.h:51
signed int int_fast8_t
Definition type.h:28
unsigned int uint32_t
Definition type.h:35
int32_t intptr_t
Definition type.h:50
unsigned int uint_fast32_t
Definition type.h:37
signed int int_fast16_t
Definition type.h:33
signed int int32_t
Definition type.h:36
unsigned char uint8_t
Definition type.h:25
unsigned int uint_fast8_t
Definition type.h:27
signed int int_fast32_t
Definition type.h:38
signed char int8_t
Definition type.h:26
int32_t intalu_t
Definition type.h:69
uint32_t uintalu_t
Definition type.h:68
bool
Definition type.h:30
clockid_t
Definition types.h:138
#define CLOCK_MONOTONIC
Definition types.h:142
#define CLOCK_REALTIME
Definition types.h:140
long long off64_t
Definition types.h:97
long off_t
Definition types.h:95
#define clock_gettime
Definition time.h:33
#define nanosleep
Definition time.h:42
unsigned uint32_t
Definition stdint.h:9
int int32_t
Definition stdint.h:8
long long int64_t
Definition stdint.h:10
unsigned long long uint64_t
Definition stdint.h:11
long int random(void)
void srandom(unsigned int seed)
char * strtok_r(char *str, const char *delim, char **saveptr)
size_t strlcpy(char *dest, const char *src, size_t n)
Definition vsf_xboot.c:39
char * strcasestr(const char *haystack, const char *needle)
char * strsep(char **strp, const char *delim)
Definition vsf_xboot.c:44
Definition time.h:66
size_t strlcat(char *dst, const char *src, size_t dsize)
Definition x86_compiler.c:52