pipe.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "pipe.h"
  2. #ifndef STATIC_ONLY
  3. #include <malloc.h>
  4. #endif
  5. zv_pipe_t * zv_pipe_create() {
  6. #ifdef STATIC_ONLY
  7. return (zv_pipe_t *) NULL;
  8. #else
  9. zv_pipe_t *self = (zv_pipe_t *) malloc(sizeof(zv_pipe_t));
  10. if (self == NULL) {
  11. return self;
  12. }
  13. zv_pipe_init(self);
  14. return self;
  15. #endif
  16. }
  17. void zv_pipe_init(zv_pipe_t *self) {
  18. self->content = (zv_pipe_t *) NULL;
  19. self->changed = false;
  20. }
  21. void zv_pipe_delete(zv_pipe_t *self) {
  22. #ifndef STATIC_ONLY
  23. if (self != NULL) {
  24. free(self);
  25. }
  26. #endif
  27. }
  28. bool zv_pipe_is_changed(zv_pipe_t *self) {
  29. return self->changed;
  30. }
  31. intptr_t zv_pipe_read_number(zv_pipe_t *self) {
  32. self->changed = false;
  33. return (intptr_t) self->content;
  34. }
  35. void * zv_pipe_read_content(zv_pipe_t *self) {
  36. self->changed = false;
  37. return self->content;
  38. }
  39. void zv_pipe_write_number(zv_pipe_t *self, intptr_t content) {
  40. self->changed = true;
  41. self->content = (void *) content;
  42. }
  43. void zv_pipe_write_content(zv_pipe_t *self, void *content) {
  44. self->changed = true;
  45. self->content = content;
  46. }