MOS Source Code
Loading...
Searching...
No Matches
pb_syshdr.h
Go to the documentation of this file.
1/* This is an example of a header file for platforms/compilers that do
2 * not come with stdint.h/stddef.h/stdbool.h/string.h. To use it, define
3 * PB_SYSTEM_HEADER as "pb_syshdr.h", including the quotes, and add the
4 * extra folder to your include path.
5 *
6 * It is very likely that you will need to customize this file to suit
7 * your platform. For any compiler that supports C99, this file should
8 * not be necessary.
9 */
10
11#ifndef _PB_SYSHDR_H_
12#define _PB_SYSHDR_H_
13
14/* stdint.h subset */
15#ifdef HAVE_STDINT_H
16#include <stdint.h>
17#else
18/* You will need to modify these to match the word size of your platform. */
19typedef signed char int8_t;
20typedef unsigned char uint8_t;
21typedef signed short int16_t;
22typedef unsigned short uint16_t;
23typedef signed int int32_t;
24typedef unsigned int uint32_t;
25typedef signed long long int64_t;
26typedef unsigned long long uint64_t;
27
28/* These are ok for most platforms, unless uint8_t is actually not available,
29 * in which case you should give the smallest available type. */
35#endif
36
37/* stddef.h subset */
38#ifdef HAVE_STDDEF_H
39#include <stddef.h>
40#else
41
43#define offsetof(st, m) ((size_t)(&((st *)0)->m))
44
45#ifndef NULL
46#define NULL 0
47#endif
48
49#endif
50
51/* stdbool.h subset */
52#ifdef HAVE_STDBOOL_H
53#include <stdbool.h>
54#else
55
56#ifndef __cplusplus
57typedef int bool;
58#define false 0
59#define true 1
60#endif
61
62#endif
63
64/* stdlib.h subset */
65#ifdef PB_ENABLE_MALLOC
66#ifdef HAVE_STDLIB_H
67#include <stdlib.h>
68#else
69void *realloc(void *ptr, size_t size);
70void free(void *ptr);
71#endif
72#endif
73
74/* string.h subset */
75#ifdef HAVE_STRING_H
76#include <string.h>
77#else
78
79/* Implementations are from the Public Domain C Library (PDCLib). */
80static size_t strlen( const char * s )
81{
82 size_t rc = 0;
83 while ( s[rc] )
84 {
85 ++rc;
86 }
87 return rc;
88}
89
90static void * memcpy( void *s1, const void *s2, size_t n )
91{
92 char * dest = (char *) s1;
93 const char * src = (const char *) s2;
94 while ( n-- )
95 {
96 *dest++ = *src++;
97 }
98 return s1;
99}
100
101static void * memset( void * s, int c, size_t n )
102{
103 unsigned char * p = (unsigned char *) s;
104 while ( n-- )
105 {
106 *p++ = (unsigned char) c;
107 }
108 return s;
109}
110#endif
111
112
113/* limits.h subset */
114#ifdef HAVE_LIMITS_H
115#include <limits.h>
116#else
117#define CHAR_BIT 8
118#endif
119
120#endif
static void * memcpy(void *s1, const void *s2, size_t n)
Definition pb_syshdr.h:90
int bool
Definition pb_syshdr.h:57
int16_t int_least16_t
Definition pb_syshdr.h:33
signed short int16_t
Definition pb_syshdr.h:21
unsigned short uint16_t
Definition pb_syshdr.h:22
uint32_t size_t
Definition pb_syshdr.h:42
unsigned int uint32_t
Definition pb_syshdr.h:24
uint16_t uint_least16_t
Definition pb_syshdr.h:34
static void * memset(void *s, int c, size_t n)
Definition pb_syshdr.h:101
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
unsigned long long uint64_t
Definition pb_syshdr.h:26
int8_t int_least8_t
Definition pb_syshdr.h:30
signed int int32_t
Definition pb_syshdr.h:23
unsigned char uint8_t
Definition pb_syshdr.h:20
uint8_t uint_least8_t
Definition pb_syshdr.h:31
uint8_t uint_fast8_t
Definition pb_syshdr.h:32
signed long long int64_t
Definition pb_syshdr.h:25
signed char int8_t
Definition pb_syshdr.h:19
size_t size
Definition slab.c:30