Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
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.
 
 
 
 

88 lines
2.6 KiB

  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef BYTE_H
  3. #define BYTE_H
  4. /* for size_t: */
  5. #include <stddef.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /* dietlibc defines these in sys/cdefs.h, which is included from stddef.h */
  10. #ifndef __pure__
  11. #define __pure__
  12. #endif
  13. #ifndef __writememsz__
  14. #define __writememsz__(a,b)
  15. #define __readmemsz__(a,b)
  16. #endif
  17. /* byte_chr returns the smallest integer i between 0 and len-1
  18. * inclusive such that one[i] equals needle, or len if not found. */
  19. __readmemsz__(1,2)
  20. size_t byte_chr(const void* haystack, size_t len, char needle) __pure__;
  21. /* byte_rchr returns the largest integer i between 0 and len-1 inclusive
  22. * such that one[i] equals needle, or len if not found. */
  23. __readmemsz__(1,2)
  24. size_t byte_rchr(const void* haystack,size_t len,char needle) __pure__;
  25. /* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
  26. * to out[len-1]. */
  27. __writememsz__(1,2)
  28. __readmemsz__(3,2)
  29. void byte_copy(void* out, size_t len, const void* in);
  30. /* byte_copyr copies in[len-1] to out[len-1], in[len-2] to out[len-2],
  31. * ... and in[0] to out[0] */
  32. __writememsz__(1,2)
  33. __readmemsz__(3,2)
  34. void byte_copyr(void* out, size_t len, const void* in);
  35. /* byte_diff returns negative, 0, or positive, depending on whether the
  36. * string a[0], a[1], ..., a[len-1] is lexicographically smaller
  37. * than, equal to, or greater than the string b[0], b[1], ...,
  38. * b[len-1]. When the strings are different, byte_diff does not read
  39. * bytes past the first difference. */
  40. __readmemsz__(1,2)
  41. __readmemsz__(3,2)
  42. int byte_diff(const void* a, size_t len, const void* b) __pure__;
  43. /* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */
  44. __writememsz__(1,2)
  45. void byte_zero(void* out, size_t len);
  46. #define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
  47. /* Return 1 iff (b,blen) is a prefix of (a,alen), 0 otherwise.
  48. * Will abort early on mismatch */
  49. __readmemsz__(1,2)
  50. __readmemsz__(3,4)
  51. int byte_start(const void* a,size_t alen,const void* b,size_t blen) __pure__;
  52. /* equivalent to byte_start(a,alen,str,strlen(str)) */
  53. __readmemsz__(1,2)
  54. __readmem__(3)
  55. int byte_starts(const void* a,size_t alen,const char* str) __pure__;
  56. #if defined(__GNUC__) && !defined(__LIBOWFAT_INTERNAL)
  57. /* If str is a string constant, strlen will be done at compile time */
  58. #define byte_starts(a,alen,str) (__builtin_constant_p(str) ? byte_start(a,alen,str,strlen(str)) : byte_starts(a,alen,str))
  59. #endif
  60. __readmemsz__(1,2)
  61. __readmemsz__(3,2)
  62. int byte_equal_notimingattack(const void* a, size_t len,const void* b) __pure__;
  63. #if defined(__i386__) || defined(__x86_64__)
  64. #define UNALIGNED_ACCESS_OK
  65. #endif
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif