faux.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /** @file faux.h
  2. * @brief Additional usefull data types and base functions.
  3. */
  4. #ifndef _faux_types_h
  5. #define _faux_types_h
  6. #include <stdlib.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <sys/uio.h>
  10. /**
  11. * A standard boolean type. The possible values are
  12. * BOOL_FALSE and BOOL_TRUE.
  13. */
  14. typedef enum {
  15. BOOL_FALSE = 0,
  16. BOOL_TRUE = 1
  17. } bool_t;
  18. /**
  19. * A tri-state boolean. The possible values are
  20. * TRI_FALSE, TRI_TRUE, TRI_UNDEFINED.
  21. */
  22. typedef enum {
  23. TRI_UNDEFINED = -1,
  24. TRI_FALSE = 0,
  25. TRI_TRUE = 1
  26. } tri_t;
  27. /** @def C_DECL_BEGIN
  28. * This macro can be used instead standard preprocessor
  29. * directive like this:
  30. * @code
  31. * #ifdef __cplusplus
  32. * extern "C" {
  33. * #endif
  34. *
  35. * int foobar(void);
  36. *
  37. * #ifdef __cplusplus
  38. * }
  39. * #endif
  40. * @endcode
  41. * It make linker to use C-style linking for functions.
  42. * Use C_DECL_BEGIN before functions declaration and C_DECL_END
  43. * after declaration:
  44. * @code
  45. * C_DECL_BEGIN
  46. *
  47. * int foobar(void);
  48. *
  49. * C_DECL_END
  50. * @endcode
  51. */
  52. /** @def C_DECL_END
  53. * See the macro C_DECL_BEGIN.
  54. * @sa C_DECL_BEGIN
  55. */
  56. #ifdef __cplusplus
  57. #define C_DECL_BEGIN extern "C" {
  58. #define C_DECL_END }
  59. #else
  60. #define C_DECL_BEGIN
  61. #define C_DECL_END
  62. #endif
  63. C_DECL_BEGIN
  64. // Memory
  65. void faux_free(void *ptr);
  66. void *faux_malloc(size_t size);
  67. void faux_bzero(void *ptr, size_t size);
  68. void *faux_zmalloc(size_t size);
  69. // I/O
  70. ssize_t faux_write(int fd, const void *buf, size_t n);
  71. ssize_t faux_read(int fd, void *buf, size_t n);
  72. ssize_t faux_write_block(int fd, const void *buf, size_t n);
  73. size_t faux_read_block(int fd, void *buf, size_t n);
  74. ssize_t faux_read_whole_file(const char *path, void **data);
  75. // Filesystem
  76. ssize_t faux_filesize(const char *path);
  77. bool_t faux_isdir(const char *path);
  78. int faux_rm(const char *path);
  79. char *faux_expand_tilde(const char *path);
  80. C_DECL_END
  81. #endif /* _faux_types_h */