joylink_syshdr.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // joylink_syshdr.h
  3. //
  4. // @brief system header , specailly for Device ,which has no operation system and necessary lib
  5. //
  6. //
  7. #ifndef _JOYLINK_SYSHDR_H_
  8. #define _JOYLINK_SYSHDR_H_
  9. #define JL_INT_32
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /* stdint.h subset */
  14. #ifndef JL_MISS_STDINT_H
  15. #include <stdint.h>
  16. #else
  17. /* You will need to modify these to match the word size of your platform. */
  18. typedef signed char int8_t;
  19. typedef unsigned char uint8_t;
  20. typedef signed short int16_t;
  21. typedef unsigned short uint16_t;
  22. #ifdef JL_INT_32
  23. typedef signed int int32_t;
  24. typedef unsigned int uint32_t;
  25. #else
  26. typedef signed long int32_t;
  27. typedef unsigned long uint32_t;
  28. #endif
  29. #endif
  30. /* stddef.h subset */
  31. #ifndef JL_MISS_STDDEF_H
  32. #include <stddef.h>
  33. #else
  34. #ifndef NULL
  35. #define NULL 0
  36. #endif
  37. #endif
  38. /* stdbool.h subset */
  39. #ifndef JL_MISS_STDBOOL_H
  40. #include <stdbool.h>
  41. #else
  42. #ifndef __cplusplus
  43. typedef int bool;
  44. #define false 0
  45. #define true 1
  46. #endif
  47. #endif
  48. /* stdlib.h subset */
  49. #ifndef JL_MISS_STDLIB_H
  50. #include <stdlib.h>
  51. #else
  52. #endif
  53. #ifndef JL_MISS_STRING_H
  54. #include <string.h>
  55. //for Broadcom build
  56. #ifdef JL_ONLY_BCM
  57. #include "spar_utils.h"
  58. #endif
  59. #else
  60. static size_t strlen( const char * s )
  61. {
  62. size_t rc = 0;
  63. while ( s[rc] )
  64. {
  65. ++rc;
  66. }
  67. return rc;
  68. }
  69. static void * memcpy( void *s1, const void *s2, size_t n )
  70. {
  71. char * dest = (char *) s1;
  72. const char * src = (const char *) s2;
  73. while ( n-- )
  74. {
  75. *dest++ = *src++;
  76. }
  77. return s1;
  78. }
  79. static void * memset( void * s, int c, size_t n )
  80. {
  81. unsigned char * p = (unsigned char *) s;
  82. while ( n-- )
  83. {
  84. *p++ = (unsigned char) c;
  85. }
  86. return s;
  87. }
  88. static int memcmp (const void *s1, const void *s2, size_t n){
  89. if (!n)
  90. return(0);
  91. while ( --n && *(char *)s1 == *(char *)s2)
  92. {
  93. s1 = (char *)s1 + 1;
  94. s2 = (char *)s2 + 1;
  95. }
  96. return( *((unsigned char *)s1) - *((unsigned char *)s2) );
  97. }
  98. #endif
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif