aboutsummaryrefslogtreecommitdiff
path: root/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'text.c')
-rw-r--r--text.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/text.c b/text.c
index bf597da..93e79d6 100644
--- a/text.c
+++ b/text.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <errno.h>
#include <wchar.h>
+#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -1441,6 +1442,17 @@ size_t text_bytes_get(Text *txt, size_t pos, size_t len, char *buf) {
return len - rem;
}
+char *text_bytes_alloc0(Text *txt, size_t pos, size_t len) {
+ if (len == SIZE_MAX)
+ return NULL;
+ char *buf = malloc(len+1);
+ if (!buf)
+ return NULL;
+ len = text_bytes_get(txt, pos, len, buf);
+ buf[len] = '\0';
+ return buf;
+}
+
size_t text_size(Text *txt) {
return txt->size;
}