mysqlnd_read_buffer.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2006-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andrey Hristov <andrey@php.net> |
  16. | Ulf Wendel <uw@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #include "php.h"
  20. #include "mysqlnd.h"
  21. #include "mysqlnd_debug.h"
  22. #include "mysqlnd_read_buffer.h"
  23. /* {{{ mysqlnd_read_buffer_is_empty */
  24. static zend_bool
  25. mysqlnd_read_buffer_is_empty(const MYSQLND_READ_BUFFER * const buffer)
  26. {
  27. return buffer->len? FALSE:TRUE;
  28. }
  29. /* }}} */
  30. /* {{{ mysqlnd_read_buffer_read */
  31. static void
  32. mysqlnd_read_buffer_read(MYSQLND_READ_BUFFER * buffer, const size_t count, zend_uchar * dest)
  33. {
  34. if (buffer->len >= count) {
  35. memcpy(dest, buffer->data + buffer->offset, count);
  36. buffer->offset += count;
  37. buffer->len -= count;
  38. }
  39. }
  40. /* }}} */
  41. /* {{{ mysqlnd_read_buffer_bytes_left */
  42. static size_t
  43. mysqlnd_read_buffer_bytes_left(const MYSQLND_READ_BUFFER * const buffer)
  44. {
  45. return buffer->len;
  46. }
  47. /* }}} */
  48. /* {{{ mysqlnd_read_buffer_free */
  49. static void
  50. mysqlnd_read_buffer_free(MYSQLND_READ_BUFFER ** buffer)
  51. {
  52. DBG_ENTER("mysqlnd_read_buffer_free");
  53. if (*buffer) {
  54. mnd_efree((*buffer)->data);
  55. mnd_efree(*buffer);
  56. *buffer = NULL;
  57. }
  58. DBG_VOID_RETURN;
  59. }
  60. /* }}} */
  61. /* {{{ mysqlnd_create_read_buffer */
  62. PHPAPI MYSQLND_READ_BUFFER *
  63. mysqlnd_create_read_buffer(const size_t count)
  64. {
  65. MYSQLND_READ_BUFFER * ret = mnd_emalloc(sizeof(MYSQLND_READ_BUFFER));
  66. DBG_ENTER("mysqlnd_create_read_buffer");
  67. ret->is_empty = mysqlnd_read_buffer_is_empty;
  68. ret->read = mysqlnd_read_buffer_read;
  69. ret->bytes_left = mysqlnd_read_buffer_bytes_left;
  70. ret->free_buffer = mysqlnd_read_buffer_free;
  71. ret->data = mnd_emalloc(count);
  72. ret->size = ret->len = count;
  73. ret->offset = 0;
  74. DBG_RETURN(ret);
  75. }
  76. /* }}} */
  77. /*
  78. * Local variables:
  79. * tab-width: 4
  80. * c-basic-offset: 4
  81. * End:
  82. * vim600: noet sw=4 ts=4 fdm=marker
  83. * vim<600: noet sw=4 ts=4
  84. */