From 753831d32861ce30ed4955777157fb8a9b72128b Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Mon, 1 Jul 2024 14:34:06 +0200 Subject: [PATCH] util/stream: Add ostream_write_str function This is simple utility function to write null terminated string to stream. Function is already referenced in msc_fat_view. --- util/stream/include/stream/stream.h | 10 ++++++++++ util/stream/src/stream.c | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/util/stream/include/stream/stream.h b/util/stream/include/stream/stream.h index 61137951f7..1bc00c4179 100644 --- a/util/stream/include/stream/stream.h +++ b/util/stream/include/stream/stream.h @@ -250,4 +250,14 @@ ostream_write_uint32(struct out_stream *ostream, uint32_t data) return ostream_write(ostream, (uint8_t *)&data, 4, false); } +/** + * Write null terminated string to output stream + * + * @param ostream - stream to write to + * @param str - string to write to stream + * + * @return number of bytes written, negative on error + */ +int ostream_write_str(struct out_stream *ostream, const char *str); + #endif /* H_STREAM_ */ diff --git a/util/stream/src/stream.c b/util/stream/src/stream.c index fe76051579..80473505b7 100644 --- a/util/stream/src/stream.c +++ b/util/stream/src/stream.c @@ -136,3 +136,10 @@ stream_pump(struct in_stream *istream, struct out_stream *ostream, uint32_t coun } return pumped; } + +int +ostream_write_str(struct out_stream *ostream, const char *str) +{ + int len = strlen(str); + return ostream_write(ostream, (const uint8_t *)str, len, false); +}