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 
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. */
30 typedef int8_t int_least8_t;
31 typedef uint8_t uint_least8_t;
32 typedef uint8_t uint_fast8_t;
33 typedef int16_t int_least16_t;
34 typedef uint16_t uint_least16_t;
35 #endif
36 
37 /* stddef.h subset */
38 #ifdef HAVE_STDDEF_H
39 #include <stddef.h>
40 #else
41 
42 typedef uint32_t size_t;
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
57 typedef 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
69 void *realloc(void *ptr, size_t size);
70 void 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). */
strlen(const char * s)80 static 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 
memcpy(void * s1,const void * s2,size_t n)90 static 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 
memset(void * s,int c,size_t n)101 static 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 #endif
113