diff --git a/fmt/fmt_strm.3 b/fmt/fmt_strm.3 index 3aa4901..6860f50 100644 --- a/fmt/fmt_strm.3 +++ b/fmt/fmt_strm.3 @@ -17,4 +17,4 @@ If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_str returns the number of bytes it would have written, i.e. the number of leading nonzero bytes of \fIsource\fR and following function arguments. .SH "SEE ALSO" -fmt_str(3), strcpy(3) +fmt_str(3), strcpy(3), fmt_strm_alloca(3), fmt_strm_malloc(3) diff --git a/fmt/fmt_strm_alloca.3 b/fmt/fmt_strm_alloca.3 new file mode 100644 index 0000000..ffcbc01 --- /dev/null +++ b/fmt/fmt_strm_alloca.3 @@ -0,0 +1,25 @@ +.TH fmt_strm_alloca 3 +.SH NAME +fmt_strm_alloca \- write multiple ASCII strings +.SH SYNTAX +.B #include + +char* \fBfmt_strm_alloca\fP(const char *\fIsource\fR, ...); +.SH DESCRIPTION +fmt_strm_alloca copies all leading nonzero bytes from \fIsource\fR and +following function arguments to a freshly allocated stack buffer and +returns a pointer to it. + +Unlink fmt_strm, fmt_strm_alloca does append \\0. + +Warning: Using variable size stack buffers is dangerous. If the size of +the buffer is larger than the hardware page size, then it can be used to +skip over the guard page and cause memory corruption. fmt_strm_alloca +has a built-in limit of 100000 bytes. Use this only for trivially small +strings. + +If the strings do not come from a trusted place or you are not sure they +are small, prefer fmt_strm_malloc instead. + +.SH "SEE ALSO" +fmt_str(3), fmt_strm(3), fmt_strm_malloc(3), alloca(3), strcpy(3) diff --git a/fmt/fmt_strm_malloc.3 b/fmt/fmt_strm_malloc.3 new file mode 100644 index 0000000..8966301 --- /dev/null +++ b/fmt/fmt_strm_malloc.3 @@ -0,0 +1,19 @@ +.TH fmt_strm_malloc 3 +.SH NAME +fmt_strm_malloc \- write multiple ASCII strings +.SH SYNTAX +.B #include + +char* \fBfmt_strm_malloc\fP(const char *\fIsource\fR, ...); +.SH DESCRIPTION +fmt_strm_malloc copies all leading nonzero bytes from \fIsource\fR and +following function arguments to a freshly allocated heap buffer and +returns a pointer to it. + +The buffer was allocated with \fImalloc\fR and you need to call +\fIfree\fR on it when you are done. + +Unlink fmt_strm, fmt_strm_malloc does append \\0. + +.SH "SEE ALSO" +fmt_str(3), fmt_strm(3), fmt_strm_alloca(3), alloca(3), strcpy(3)