zero_stream.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file zero stream interface
  8. */
  9. #include <string.h>
  10. #include <stdint.h>
  11. #include "zero_stream.h"
  12. #include "stream_internal.h"
  13. static int _zero_stream_open(io_stream_t handle,stream_mode mode)
  14. {
  15. handle->total_size = UINT32_MAX;
  16. return 0;
  17. }
  18. static int _zero_stream_read(io_stream_t handle, unsigned char *buf, int len)
  19. {
  20. memset(buf, 0, len);
  21. handle->rofs += len;
  22. return 0;
  23. }
  24. static int _zero_stream_write(io_stream_t handle, unsigned char *buf, int len)
  25. {
  26. handle->wofs += len;
  27. return len;
  28. }
  29. static int _zero_stream_get_length(io_stream_t handle)
  30. {
  31. return INT32_MAX;
  32. }
  33. static int _zero_stream_get_space(io_stream_t handle)
  34. {
  35. return INT32_MAX;
  36. }
  37. static int _zero_stream_close(io_stream_t handle)
  38. {
  39. return 0;
  40. }
  41. static const stream_ops_t zero_stream_ops = {
  42. .open = _zero_stream_open,
  43. .read = _zero_stream_read,
  44. .write = _zero_stream_write,
  45. .close = _zero_stream_close,
  46. .get_length = _zero_stream_get_length,
  47. .get_space = _zero_stream_get_space,
  48. };
  49. io_stream_t zero_stream_create(void)
  50. {
  51. return stream_create(&zero_stream_ops, NULL);
  52. }