faux.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /** @def C_DECL_BEGIN
  19. * This macro can be used instead standard preprocessor
  20. * directive like this:
  21. * @code
  22. * #ifdef __cplusplus
  23. * extern "C" {
  24. * #endif
  25. *
  26. * int foobar(void);
  27. *
  28. * #ifdef __cplusplus
  29. * }
  30. * #endif
  31. * @endcode
  32. * It make linker to use C-style linking for functions.
  33. * Use C_DECL_BEGIN before functions declaration and C_DECL_END
  34. * after declaration:
  35. * @code
  36. * C_DECL_BEGIN
  37. *
  38. * int foobar(void);
  39. *
  40. * C_DECL_END
  41. * @endcode
  42. */
  43. /** @def C_DECL_END
  44. * See the macro C_DECL_BEGIN.
  45. * @sa C_DECL_BEGIN
  46. */
  47. #ifdef __cplusplus
  48. #define C_DECL_BEGIN extern "C" {
  49. #define C_DECL_END }
  50. #else
  51. #define C_DECL_BEGIN
  52. #define C_DECL_END
  53. #endif
  54. C_DECL_BEGIN
  55. // Memory
  56. void faux_free(void *ptr);
  57. void *faux_malloc(size_t size);
  58. void faux_bzero(void *ptr, size_t size);
  59. void *faux_zmalloc(size_t size);
  60. // I/O
  61. ssize_t faux_write(int fd, const void *buf, size_t n);
  62. ssize_t faux_read(int fd, void *buf, size_t n);
  63. ssize_t faux_write_block(int fd, const void *buf, size_t n);
  64. size_t faux_read_block(int fd, void *buf, size_t n);
  65. // Filesystem
  66. int faux_rm(const char *path);
  67. char *faux_expand_tilde(const char *path);
  68. C_DECL_END
  69. #endif /* _faux_types_h */