Add an example pb_syshdr.h file for platforms without C99.
[apps/agl-service-can-low-level.git] / compat / pb_syshdr.h
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  * compat 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 /* You will need to modify these to match the word size of your platform. */
16 typedef signed char int8_t;
17 typedef unsigned char uint8_t;
18 typedef signed short int16_t;
19 typedef unsigned short uint16_t;
20 typedef signed int int32_t;
21 typedef unsigned int uint32_t;
22 typedef signed long long int64_t;
23 typedef unsigned long long uint64_t;
24
25 /* stddef.h subset */
26 typedef uint32_t size_t;
27 #define offsetof(st, m) ((size_t)(&((st *)0)->m))
28
29 #ifndef NULL
30 #define NULL 0
31 #endif
32
33 /* stdbool.h subset */
34 typedef int bool;
35 #define false 0
36 #define true 1
37
38 /* string.h subset */
39 /* Implementations are from the Public Domain C Library (PDCLib). */
40 static size_t strlen( const char * s )
41 {
42     size_t rc = 0;
43     while ( s[rc] )
44     {
45         ++rc;
46     }
47     return rc;
48 }
49
50 static void * memcpy( void *s1, const void *s2, size_t n )
51 {
52     char * dest = (char *) s1;
53     const char * src = (const char *) s2;
54     while ( n-- )
55     {
56         *dest++ = *src++;
57     }
58     return s1;
59 }
60
61 static void * memset( void * s, int c, size_t n )
62 {
63     unsigned char * p = (unsigned char *) s;
64     while ( n-- )
65     {
66         *p++ = (unsigned char) c;
67     }
68     return s;
69 }
70
71 #endif