pb_syshdr.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef _PB_SYSHDR_H_
  11. #define _PB_SYSHDR_H_
  12. /* stdint.h subset */
  13. #ifdef HAVE_STDINT_H
  14. #include <stdint.h>
  15. #else
  16. /* You will need to modify these to match the word size of your platform. */
  17. typedef signed char int8_t;
  18. typedef unsigned char uint8_t;
  19. typedef signed short int16_t;
  20. typedef unsigned short uint16_t;
  21. typedef signed int int32_t;
  22. typedef unsigned int uint32_t;
  23. typedef signed long long int64_t;
  24. typedef unsigned long long uint64_t;
  25. /* These are ok for most platforms, unless uint8_t is actually not available,
  26. * in which case you should give the smallest available type. */
  27. typedef int8_t int_least8_t;
  28. typedef uint8_t uint_least8_t;
  29. typedef uint8_t uint_fast8_t;
  30. typedef int16_t int_least16_t;
  31. typedef uint16_t uint_least16_t;
  32. #endif
  33. /* stddef.h subset */
  34. #ifdef HAVE_STDDEF_H
  35. #include <stddef.h>
  36. #else
  37. typedef uint32_t size_t;
  38. #define offsetof(st, m) ((size_t)(&((st *)0)->m))
  39. #ifndef NULL
  40. #define NULL 0
  41. #endif
  42. #endif
  43. /* stdbool.h subset */
  44. #ifdef HAVE_STDBOOL_H
  45. #include <stdbool.h>
  46. #else
  47. #ifndef __cplusplus
  48. typedef int bool;
  49. #define false 0
  50. #define true 1
  51. #endif
  52. #endif
  53. /* stdlib.h subset */
  54. #ifdef PB_ENABLE_MALLOC
  55. #ifdef HAVE_STDLIB_H
  56. #include <stdlib.h>
  57. #else
  58. void *realloc(void *ptr, size_t size);
  59. void free(void *ptr);
  60. #endif
  61. #endif
  62. /* string.h subset */
  63. #ifdef HAVE_STRING_H
  64. #include <string.h>
  65. #else
  66. /* Implementations are from the Public Domain C Library (PDCLib). */
  67. static size_t strlen( const char * s )
  68. {
  69. size_t rc = 0;
  70. while ( s[rc] )
  71. {
  72. ++rc;
  73. }
  74. return rc;
  75. }
  76. static void * memcpy( void *s1, const void *s2, size_t n )
  77. {
  78. char * dest = (char *) s1;
  79. const char * src = (const char *) s2;
  80. while ( n-- )
  81. {
  82. *dest++ = *src++;
  83. }
  84. return s1;
  85. }
  86. static void * memset( void * s, int c, size_t n )
  87. {
  88. unsigned char * p = (unsigned char *) s;
  89. while ( n-- )
  90. {
  91. *p++ = (unsigned char) c;
  92. }
  93. return s;
  94. }
  95. #endif
  96. /* limits.h subset */
  97. #ifdef HAVE_LIMITS_H
  98. #include <limits.h>
  99. #else
  100. #define CHAR_BIT 8
  101. #endif
  102. #endif