Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcos_string.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*=============================================================================
  26. VideoCore OS Abstraction Layer - public header file
  27. =============================================================================*/
  28. #ifndef VCOS_STRING_H
  29. #define VCOS_STRING_H
  30. /**
  31. * \file
  32. *
  33. * String functions.
  34. *
  35. */
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "vcos_types.h"
  40. #include "pthreads/vcos_platform.h"
  41. #ifdef __KERNEL__
  42. #include <linux/string.h>
  43. #else
  44. #include <string.h>
  45. #endif
  46. /** Case insensitive string comparison.
  47. *
  48. */
  49. VCOS_INLINE_DECL
  50. int vcos_strcasecmp(const char *s1, const char *s2);
  51. VCOS_INLINE_DECL
  52. int vcos_strncasecmp(const char *s1, const char *s2, size_t n);
  53. VCOSPRE_ int VCOSPOST_ vcos_vsnprintf(char *buf, size_t buflen, const char *fmt, va_list ap);
  54. VCOSPRE_ int VCOSPOST_ vcos_snprintf(char *buf, size_t buflen, const char *fmt, ...);
  55. /** Like vsnprintf, except it places the output at the specified offset.
  56. * Output is truncated to fit in buflen bytes, and is guaranteed to be NUL-terminated.
  57. * Returns the string length before/without truncation.
  58. */
  59. VCOSPRE_ size_t VCOSPOST_ vcos_safe_vsprintf(char *buf, size_t buflen, size_t offset, const char *fmt, va_list ap);
  60. #define VCOS_SAFE_VSPRINTF(buf, offset, fmt, ap) \
  61. vcos_safe_vsprintf(buf, sizeof(buf) + ((char (*)[sizeof(buf)])buf - &(buf)), offset, fmt, ap)
  62. /** Like snprintf, except it places the output at the specified offset.
  63. * Output is truncated to fit in buflen bytes, and is guaranteed to be NUL-terminated.
  64. * Returns the string length before/without truncation.
  65. */
  66. VCOSPRE_ size_t VCOSPOST_ vcos_safe_sprintf(char *buf, size_t buflen, size_t offset, const char *fmt, ...);
  67. /* The Metaware compiler currently has a bug in its variadic macro handling which
  68. causes it to append a spurious command to the end of its __VA_ARGS__ data.
  69. Do not use until this has been fixed (and this comment has been deleted). */
  70. #define VCOS_SAFE_SPRINTF(buf, offset, ...) \
  71. vcos_safe_sprintf(buf, sizeof(buf) + ((char (*)[sizeof(buf)])buf - &(buf)), offset, __VA_ARGS__)
  72. /** Copies string src to dst at the specified offset.
  73. * Output is truncated to fit in dstlen bytes, i.e. the string is at most
  74. * (buflen - 1) characters long. Unlike strncpy, exactly one NUL is written
  75. * to dst, which is always NUL-terminated.
  76. * Returns the string length before/without truncation.
  77. */
  78. VCOSPRE_ size_t VCOSPOST_ vcos_safe_strcpy(char *dst, const char *src, size_t dstlen, size_t offset);
  79. #define VCOS_SAFE_STRCPY(dst, src, offset) \
  80. vcos_safe_strcpy(dst, src, sizeof(dst) + ((char (*)[sizeof(dst)])dst - &(dst)), offset)
  81. VCOS_STATIC_INLINE
  82. int vcos_strlen(const char *s) { return (int)strlen(s); }
  83. VCOS_STATIC_INLINE
  84. int vcos_strcmp(const char *s1, const char *s2) { return strcmp(s1,s2); }
  85. VCOS_STATIC_INLINE
  86. int vcos_strncmp(const char *cs, const char *ct, size_t count) { return strncmp(cs, ct, count); }
  87. VCOS_STATIC_INLINE
  88. char *vcos_strcpy(char *dst, const char *src) { return strcpy(dst, src); }
  89. VCOS_STATIC_INLINE
  90. char *vcos_strncpy(char *dst, const char *src, size_t count) { return strncpy(dst, src, count); }
  91. VCOS_STATIC_INLINE
  92. void *vcos_memcpy(void *dst, const void *src, size_t n) { memcpy(dst, src, n); return dst; }
  93. VCOS_STATIC_INLINE
  94. void *vcos_memset(void *p, int c, size_t n) { return memset(p, c, n); }
  95. VCOS_STATIC_INLINE
  96. int vcos_memcmp(const void *ptr1, const void *ptr2, size_t count) { return memcmp(ptr1, ptr2, count); }
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif