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. */
19 typedef signed char int8_t;
20 typedef unsigned char uint8_t;
21 typedef signed short int16_t;
22 typedef unsigned short uint16_t;
23 typedef signed int int32_t;
24 typedef unsigned int uint32_t;
25 typedef signed long long int64_t;
26 typedef unsigned long long uint64_t;
27 #endif
28
29 /* stddef.h subset */
30 #ifdef HAVE_STDDEF_H
31 #include <stddef.h>
32 #else
33
34 typedef uint32_t size_t;
35 #define offsetof(st, m) ((size_t)(&((st *)0)->m))
36
37 #ifndef NULL
38 #define NULL 0
39 #endif
40
41 #endif
42
43 /* stdbool.h subset */
44 #ifdef HAVE_STDBOOL_H
45 #include <stdbool.h>
46 #else
47
48 #ifndef __cplusplus
49 typedef int bool;
50 #define false 0
51 #define true 1
52 #endif
53
54 #endif
55
56 /* stdlib.h subset */
57 #ifdef PB_ENABLE_MALLOC
58 #ifdef HAVE_STDLIB_H
59 #include <stdlib.h>
60 #else
61 void *realloc(void *ptr, size_t size);
62 void free(void *ptr);
63 #endif
64 #endif
65
66 /* string.h subset */
67 #ifdef HAVE_STRING_H
68 #include <string.h>
69 #else
70
71 /* Implementations are from the Public Domain C Library (PDCLib). */
strlen(const char * s)72 static size_t strlen( const char * s )
73 {
74 size_t rc = 0;
75 while ( s[rc] )
76 {
77 ++rc;
78 }
79 return rc;
80 }
81
memcpy(void * s1,const void * s2,size_t n)82 static void * memcpy( void *s1, const void *s2, size_t n )
83 {
84 char * dest = (char *) s1;
85 const char * src = (const char *) s2;
86 while ( n-- )
87 {
88 *dest++ = *src++;
89 }
90 return s1;
91 }
92
memset(void * s,int c,size_t n)93 static void * memset( void * s, int c, size_t n )
94 {
95 unsigned char * p = (unsigned char *) s;
96 while ( n-- )
97 {
98 *p++ = (unsigned char) c;
99 }
100 return s;
101 }
102 #endif
103
104 #endif
105