summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-04-23 23:20:54 -0700
committerH. Peter Anvin <hpa@zytor.com>2017-04-23 23:20:54 -0700
commit40f0a7495aa1353d90c8fb68912b82c3af2ff01d (patch)
tree65ad7104642e35add53837d431066e81e88e919d
parentd00d8c6ac396a84e85900cff7058f88180bf68fa (diff)
downloadnasm-40f0a7495aa1353d90c8fb68912b82c3af2ff01d.tar.gz
SAA: add saa_wcstring()
Add saa_wcstring() to write a C string (a string including final NUL) to an SAA, and return the number of bytes written. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--include/saa.h1
-rw-r--r--nasmlib/saa.c15
2 files changed, 15 insertions, 1 deletions
diff --git a/include/saa.h b/include/saa.h
index 8a8bd075..afd25a45 100644
--- a/include/saa.h
+++ b/include/saa.h
@@ -70,6 +70,7 @@ struct SAA *saa_init(size_t elem_len); /* 1 == byte */
void saa_free(struct SAA *);
void *saa_wstruct(struct SAA *); /* return a structure of elem_len */
void saa_wbytes(struct SAA *, const void *, size_t); /* write arbitrary bytes */
+size_t saa_wcstring(struct SAA *s, const char *str); /* write a C string */
void saa_rewind(struct SAA *); /* for reading from beginning */
void *saa_rstruct(struct SAA *); /* return NULL on EOA */
const void *saa_rbytes(struct SAA *, size_t *); /* return 0 on EOA */
diff --git a/nasmlib/saa.c b/nasmlib/saa.c
index a0350c10..c4af5aa0 100644
--- a/nasmlib/saa.c
+++ b/nasmlib/saa.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2017 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -149,6 +149,19 @@ void saa_wbytes(struct SAA *s, const void *data, size_t len)
}
}
+/*
+ * Writes a string, *including* the final null, to the specified SAA,
+ * and return the number of bytes written.
+ */
+size_t saa_wcstring(struct SAA *s, const char *str)
+{
+ size_t bytes = strlen(str) + 1;
+
+ saa_wbytes(s, str, bytes);
+
+ return bytes;
+}
+
void saa_rewind(struct SAA *s)
{
s->rblk = s->blk_ptrs;