9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek * @brief The iobuf structure that holds the data, its capacity and
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek * a pointer to the data.
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek * @see sss_iobuf_init_empty()
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek * @see sss_iobuf_init_readonly()
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekstruct sss_iobuf *sss_iobuf_init_empty(TALLOC_CTX *mem_ctx,
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek iobuf = talloc_zero(mem_ctx, struct sss_iobuf);
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekstruct sss_iobuf *sss_iobuf_init_readonly(TALLOC_CTX *mem_ctx,
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek iobuf = sss_iobuf_init_empty(mem_ctx, size, size);
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozeksize_t sss_iobuf_get_len(struct sss_iobuf *iobuf)
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozeksize_t sss_iobuf_get_capacity(struct sss_iobuf *iobuf)
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozeksize_t sss_iobuf_get_size(struct sss_iobuf *iobuf)
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekuint8_t *sss_iobuf_get_data(struct sss_iobuf *iobuf)
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekstatic size_t iobuf_get_len(struct sss_iobuf *iobuf)
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekstatic errno_t ensure_bytes(struct sss_iobuf *iobuf,
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek /* Enough space already */
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek /* Else, try to extend the iobuf */
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek /* We will never grow past capacity */
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek /* Double the size until we add at least nbytes, but stop if we double past capacity */
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek (newsize < wantsize) && (newsize < iobuf->capacity);
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek newdata = talloc_realloc(iobuf, iobuf->data, uint8_t, newsize);
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekstatic inline uint8_t *iobuf_ptr(struct sss_iobuf *iobuf)
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek safealign_memcpy(_buf, iobuf_ptr(iobuf), len, &iobuf->dp);
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_read_len(struct sss_iobuf *iobuf,
18e4fe9d836e8f7bee52724374ffc0011172329fPavel Březina ret = sss_iobuf_read(iobuf, len, _buf, &read_bytes);
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozekerrno_t sss_iobuf_write_len(struct sss_iobuf *iobuf,
9a9b5e115b079751422be22fd252c0b283611c62Jakub Hrozek safealign_memcpy(iobuf_ptr(iobuf), buf, len, &iobuf->dp);
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_read_uint32(struct sss_iobuf *iobuf,
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek SAFEALIGN_COPY_UINT32_CHECK(_val, iobuf_ptr(iobuf),
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_read_int32(struct sss_iobuf *iobuf,
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek SAFEALIGN_COPY_INT32_CHECK(_val, iobuf_ptr(iobuf),
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_write_uint32(struct sss_iobuf *iobuf,
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek SAFEALIGN_SETMEM_UINT32(iobuf_ptr(iobuf), val, &iobuf->dp);
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_write_int32(struct sss_iobuf *iobuf,
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek SAFEALIGN_SETMEM_INT32(iobuf_ptr(iobuf), val, &iobuf->dp);
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_read_stringz(struct sss_iobuf *iobuf,
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek const char **_out)
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek end = memchr(iobuf_ptr(iobuf), '\0', sss_iobuf_get_size(iobuf));
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozekerrno_t sss_iobuf_write_stringz(struct sss_iobuf *iobuf,
5f7f45a64bdb9353f15b945db4ad2564b4b28ab2Jakub Hrozek const char *str)