faux.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /** @def FAUX_HIDDEN
  64. *
  65. * Make symbol hidden within DSO (dynamic shared object). It's usefull to don't
  66. * pollute library namespace.
  67. */
  68. #define FAUX_HIDDEN __attribute__ ((visibility ("hidden")))
  69. C_DECL_BEGIN
  70. // Memory
  71. void faux_free(void *ptr);
  72. void *faux_malloc(size_t size);
  73. void faux_bzero(void *ptr, size_t size);
  74. void *faux_zmalloc(size_t size);
  75. // I/O
  76. ssize_t faux_write(int fd, const void *buf, size_t n);
  77. ssize_t faux_read(int fd, void *buf, size_t n);
  78. ssize_t faux_write_block(int fd, const void *buf, size_t n);
  79. size_t faux_read_block(int fd, void *buf, size_t n);
  80. ssize_t faux_read_whole_file(const char *path, void **data);
  81. // Filesystem
  82. ssize_t faux_filesize(const char *path);
  83. bool_t faux_isdir(const char *path);
  84. bool_t faux_isfile(const char *path);
  85. bool_t faux_rm(const char *path);
  86. char *faux_expand_tilde(const char *path);
  87. C_DECL_END
  88. #endif /* _faux_types_h */