diff --git a/include/saa.h b/include/saa.h index 8a8bd0754..afd25a455 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 a0350c103..c4af5aa03 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;