faux.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #include <sys/stat.h>
  11. #include <fcntl.h>
  12. /**
  13. * A standard boolean type. The possible values are
  14. * BOOL_FALSE and BOOL_TRUE.
  15. */
  16. typedef enum {
  17. BOOL_FALSE = 0,
  18. BOOL_TRUE = 1
  19. } bool_t;
  20. /**
  21. * A tri-state boolean. The possible values are
  22. * TRI_FALSE, TRI_TRUE, TRI_UNDEFINED.
  23. */
  24. typedef enum {
  25. TRI_UNDEFINED = -1,
  26. TRI_FALSE = 0,
  27. TRI_TRUE = 1
  28. } tri_t;
  29. /** @def C_DECL_BEGIN
  30. * This macro can be used instead standard preprocessor
  31. * directive like this:
  32. * @code
  33. * #ifdef __cplusplus
  34. * extern "C" {
  35. * #endif
  36. *
  37. * int foobar(void);
  38. *
  39. * #ifdef __cplusplus
  40. * }
  41. * #endif
  42. * @endcode
  43. * It make linker to use C-style linking for functions.
  44. * Use C_DECL_BEGIN before functions declaration and C_DECL_END
  45. * after declaration:
  46. * @code
  47. * C_DECL_BEGIN
  48. *
  49. * int foobar(void);
  50. *
  51. * C_DECL_END
  52. * @endcode
  53. */
  54. /** @def C_DECL_END
  55. * See the macro C_DECL_BEGIN.
  56. * @sa C_DECL_BEGIN
  57. */
  58. #ifdef __cplusplus
  59. #define C_DECL_BEGIN extern "C" {
  60. #define C_DECL_END }
  61. #else
  62. #define C_DECL_BEGIN
  63. #define C_DECL_END
  64. #endif
  65. /** @def FAUX_HIDDEN
  66. *
  67. * Make symbol hidden within DSO (dynamic shared object). It's usefull to don't
  68. * pollute library namespace.
  69. */
  70. #define FAUX_HIDDEN __attribute__ ((visibility ("hidden")))
  71. // For symbol versions
  72. #define FAUX_SYMVER(symbol,iface,version) asm(".symver symbol,iface@version")
  73. C_DECL_BEGIN
  74. // Memory
  75. void faux_free(void *ptr);
  76. void *faux_malloc(size_t size);
  77. void faux_bzero(void *ptr, size_t size);
  78. void *faux_zmalloc(size_t size);
  79. void faux_cleanse(void *ptr, size_t size);
  80. // I/O
  81. ssize_t faux_write(int fd, const void *buf, size_t n);
  82. ssize_t faux_read(int fd, void *buf, size_t n);
  83. ssize_t faux_write_block(int fd, const void *buf, size_t n);
  84. size_t faux_read_block(int fd, void *buf, size_t n);
  85. ssize_t faux_read_whole_file(const char *path, void **data);
  86. // Filesystem
  87. ssize_t faux_filesize(const char *path);
  88. bool_t faux_isdir(const char *path);
  89. bool_t faux_isfile(const char *path);
  90. bool_t faux_rm(const char *path);
  91. bool_t faux_mkdir_p(const char *path, mode_t mode);
  92. char *faux_expand_tilde(const char *path);
  93. // System
  94. bool_t faux_daemon(int nochdir, int noclose, const char *pidfile, mode_t mode);
  95. C_DECL_END
  96. #endif /* _faux_types_h */