From 40f0a7495aa1353d90c8fb68912b82c3af2ff01d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 23:20:54 -0700 Subject: [PATCH] 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 --- include/saa.h | 1 + nasmlib/saa.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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; -- 2.11.4.GIT