Home | History | Annotate | Download | only in common

Lines Matching refs:buf

22 	struct byte_buffer *buf;
23 buf = (struct byte_buffer *)
25 if (!buf)
26 return buf;
27 buf->max_size = buffer_size_bytes;
28 buf->used_size = buffer_size_bytes;
29 return buf;
32 static inline void byte_buffer_set_used_size(struct byte_buffer *buf,
35 buf->used_size = MIN(used_size, buf->max_size);
39 static inline void byte_buffer_destroy(struct byte_buffer *buf)
41 free(buf);
44 static inline unsigned int buf_writable_bytes(struct byte_buffer *buf)
46 if (buf->level >= buf->used_size)
48 if (buf->write_idx < buf->read_idx)
49 return buf->read_idx - buf->write_idx;
51 return buf->used_size - buf->write_idx;
54 static inline unsigned int buf_readable_bytes(struct byte_buffer *buf)
56 if (buf->level == 0)
59 if (buf->read_idx < buf->write_idx)
60 return buf->write_idx - buf->read_idx;
62 return buf->used_size - buf->read_idx;
65 static inline unsigned int buf_queued_bytes(struct byte_buffer *buf)
67 return buf->level;
70 static inline unsigned int buf_available_bytes(const struct byte_buffer *buf)
72 return buf->used_size - buf->level;
75 static inline uint8_t *buf_read_pointer(struct byte_buffer *buf)
77 return &buf->bytes[buf->read_idx];
80 static inline uint8_t *buf_read_pointer_size(struct byte_buffer *buf,
83 *readable = buf_readable_bytes(buf);
84 return buf_read_pointer(buf);
87 static inline void buf_increment_read(struct byte_buffer *buf, size_t inc)
89 inc = MIN(inc, buf->level);
90 buf->read_idx += inc;
91 buf->read_idx %= buf->used_size;
92 buf->level -= inc;
95 static inline uint8_t *buf_write_pointer(struct byte_buffer *buf)
97 return &buf->bytes[buf->write_idx];
100 static inline uint8_t *buf_write_pointer_size(struct byte_buffer *buf,
103 *writeable = buf_writable_bytes(buf);
104 return buf_write_pointer(buf);
107 static inline void buf_increment_write(struct byte_buffer *buf, size_t inc)
109 buf->write_idx += inc;
110 buf->write_idx %= buf->used_size;
111 if (buf->level + inc < buf->used_size)
112 buf->level += inc;
114 buf->level = buf->used_size;
117 static inline void buf_reset(struct byte_buffer *buf)
119 buf->write_idx = 0;
120 buf->read_idx = 0;
121 buf->level = 0;