Lines Matching +full:space +full:- +full:constraint

1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* util/support/k5buf.c - string buffer functions */
13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
29 * Can't include krb5.h here, or k5-int.h which includes it, because krb5.h
33 #include "k5-platform.h"
34 #include "k5-buf.h"
43 * space > 0
44 * len < space
52 return (char *)buf->data + buf->len; in endptr()
58 buf->buftype = K5BUF_ERROR; in set_error()
59 buf->data = NULL; in set_error()
60 buf->space = buf->len = 0; in set_error()
74 if (buf->buftype == K5BUF_ERROR) in ensure_space()
76 if (buf->space - buf->len >= len) /* Enough room already. */ in ensure_space()
78 if (buf->buftype == K5BUF_FIXED) /* Can't resize a fixed buffer. */ in ensure_space()
80 assert(buf->buftype == K5BUF_DYNAMIC || buf->buftype == K5BUF_DYNAMIC_ZAP); in ensure_space()
81 new_space = buf->space * 2; in ensure_space()
82 while (new_space - buf->len < len) { in ensure_space()
87 if (buf->buftype == K5BUF_DYNAMIC_ZAP) { in ensure_space()
92 memcpy(new_data, buf->data, buf->len); in ensure_space()
93 zap(buf->data, buf->len); in ensure_space()
94 free(buf->data); in ensure_space()
96 new_data = realloc(buf->data, new_space); in ensure_space()
100 buf->data = new_data; in ensure_space()
101 buf->space = new_space; in ensure_space()
105 if (buf->buftype == K5BUF_DYNAMIC_ZAP) in ensure_space()
106 zap(buf->data, buf->len); in ensure_space()
107 if (buf->buftype == K5BUF_DYNAMIC_ZAP || buf->buftype == K5BUF_DYNAMIC) in ensure_space()
108 free(buf->data); in ensure_space()
114 k5_buf_init_fixed(struct k5buf *buf, void *data, size_t space) in k5_buf_init_fixed() argument
116 assert(space > 0); in k5_buf_init_fixed()
117 buf->buftype = K5BUF_FIXED; in k5_buf_init_fixed()
118 buf->data = data; in k5_buf_init_fixed()
119 buf->space = space; in k5_buf_init_fixed()
120 buf->len = 0; in k5_buf_init_fixed()
126 buf->buftype = K5BUF_DYNAMIC; in k5_buf_init_dynamic()
127 buf->space = 128; in k5_buf_init_dynamic()
128 buf->data = malloc(buf->space); in k5_buf_init_dynamic()
129 if (buf->data == NULL) { in k5_buf_init_dynamic()
133 buf->len = 0; in k5_buf_init_dynamic()
140 if (buf->buftype == K5BUF_DYNAMIC) in k5_buf_init_dynamic_zap()
141 buf->buftype = K5BUF_DYNAMIC_ZAP; in k5_buf_init_dynamic_zap()
157 buf->len += len; in k5_buf_add_len()
168 if (buf->buftype == K5BUF_ERROR) in k5_buf_add_vfmt()
170 remaining = buf->space - buf->len; in k5_buf_add_vfmt()
172 if (buf->buftype == K5BUF_FIXED) { in k5_buf_add_vfmt()
178 buf->len += (unsigned int) r; in k5_buf_add_vfmt()
183 assert(buf->buftype == K5BUF_DYNAMIC || buf->buftype == K5BUF_DYNAMIC_ZAP); in k5_buf_add_vfmt()
188 buf->len += (unsigned int) r; in k5_buf_add_vfmt()
193 /* snprintf correctly told us how much space is required. */ in k5_buf_add_vfmt()
196 remaining = buf->space - buf->len; in k5_buf_add_vfmt()
201 buf->len += (unsigned int) r; in k5_buf_add_vfmt()
205 /* It's a pre-C99 snprintf implementation, or something else went wrong. in k5_buf_add_vfmt()
215 buf->len += r; in k5_buf_add_vfmt()
217 if (buf->buftype == K5BUF_DYNAMIC_ZAP) in k5_buf_add_vfmt()
238 return buf->data; in k5_buf_cstring()
246 buf->len += len; in k5_buf_get_space()
247 return endptr(buf) - len; in k5_buf_get_space()
253 if (buf->buftype == K5BUF_ERROR) in k5_buf_truncate()
255 assert(len <= buf->len); in k5_buf_truncate()
256 buf->len = len; in k5_buf_truncate()
262 return (buf->buftype == K5BUF_ERROR) ? ENOMEM : 0; in k5_buf_status()
268 if (buf->buftype == K5BUF_ERROR) in k5_buf_free()
270 assert(buf->buftype == K5BUF_DYNAMIC || buf->buftype == K5BUF_DYNAMIC_ZAP); in k5_buf_free()
271 if (buf->buftype == K5BUF_DYNAMIC_ZAP) in k5_buf_free()
272 zap(buf->data, buf->len); in k5_buf_free()
273 free(buf->data); in k5_buf_free()