aboutsummaryrefslogtreecommitdiff
path: root/text.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-01-10 12:23:32 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-01-10 12:45:58 +0100
commite6e077c8469f857ac58d804c788e887ce86e2303 (patch)
tree5d2a54577bb177e62f43c37ffeffb904a5063467 /text.h
parent713f90fd5dacb768731fa48b93a873bd37e085ad (diff)
downloadvis-e6e077c8469f857ac58d804c788e887ce86e2303.tar.gz
vis-e6e077c8469f857ac58d804c788e887ce86e2303.tar.xz
text: introduce text_bytes_alloc0 utility function
Heap allocates a zero terminated string of the given range. Freeing is the caller's responsibility. Checks for unsigned integer overflow i.e. passing SIZE_MAX as len will always fail because there is no room for the terminating NUL byte. This is important as EPOS is defined to be SIZE_MAX.
Diffstat (limited to 'text.h')
-rw-r--r--text.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/text.h b/text.h
index b2783b3..90da900 100644
--- a/text.h
+++ b/text.h
@@ -72,6 +72,9 @@ bool text_byte_get(Text*, size_t pos, char *buf);
* indicates how many bytes were copied into `buf'. WARNING buf will not be
* NUL terminated. */
size_t text_bytes_get(Text*, size_t pos, size_t len, char *buf);
+/* allocate a NUL terminated buffer and fill at most `len' bytes
+ * starting at `pos'. Freeing is the caller's responsibility! */
+char *text_bytes_alloc0(Text*, size_t pos, size_t len);
Iterator text_iterator_get(Text*, size_t pos);
bool text_iterator_valid(const Iterator*);