Skip to content

Commit

Permalink
util/stream: Add ostream_write_str function
Browse files Browse the repository at this point in the history
This is simple utility function to write null terminated
string to stream.

Function is already referenced in msc_fat_view.
  • Loading branch information
kasjer committed Jul 1, 2024
1 parent 2c78031 commit 753831d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions util/stream/include/stream/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
7 changes: 7 additions & 0 deletions util/stream/src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 753831d

Please sign in to comment.