Merge branch 'dev_get_rid_of_ternary_operator'
[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 #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 /* string.h subset */
57 #ifdef HAVE_STRING_H
58 #include <string.h>
59 #else
60
61 /* Implementations are from the Public Domain C Library (PDCLib). */
62 static size_t strlen( const char * s )
63 {
64     size_t rc = 0;
65     while ( s[rc] )
66     {
67         ++rc;
68     }
69     return rc;
70 }
71
72 static void * memcpy( void *s1, const void *s2, size_t n )
73 {
74     char * dest = (char *) s1;
75     const char * src = (const char *) s2;
76     while ( n-- )
77     {
78         *dest++ = *src++;
79     }
80     return s1;
81 }
82
83 static void * memset( void * s, int c, size_t n )
84 {
85     unsigned char * p = (unsigned char *) s;
86     while ( n-- )
87     {
88         *p++ = (unsigned char) c;
89     }
90     return s;
91 }
92 #endif
93
94 #endif