opnsense-src/lib/libutil++/freebsd::stringf.3
John Baldwin b3127a2dc2 libutil++: New library containing C++ utility classes for use in base
- freebsd::FILE_up is a wrapper class for std::unique_ptr<> for FILE
  objects which uses a custom deleter that calls fclose().

- freebsd::malloc_up<T> is a wrapper class for std::unique_ptr<> which
  uses a custom deleter that calls free().  It is useful for pointers
  allocated by malloc() such as strdup().

- The freebsd::stringf() functions return a std::string constructed
  using a printf format string.

  The current implementation of freebsd::stringf() uses fwopen() where
  the write function appends to a std::string.

Sponsored by:	Chelsio Communications
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1794
2025-08-04 15:38:06 -04:00

48 lines
1.2 KiB
Groff

.\"
.\" SPDX-License-Identifier: BSD-2-Clause
.\"
.\" Copyright (c) 2025 Chelsio Communications, Inc.
.\" Written by: John Baldwin <jhb@FreeBSD.org>
.\"
.Dd July 31, 2025
.Dt FREEBSD::STRINGF 3
.Os
.Sh NAME
.Nm freebsd::stringf
.Nd build a std::string using stdio formatting
.Sh LIBRARY
.Lb libutil++
.Sh SYNOPSIS
.In libutil++.hh
.Ft std::string
.Fn freebsd::stringf "const char *fmt" "..."
.Ft std::string
.Fn freebsd::stringf "const char *fmt" "va_list ap"
.Sh DESCRIPTION
These functions construct a
.Vt std::string
object containing a formatted string.
The output of the string is dictated by the
.Fa fmt
argument and additional arguments using the same conventions documented in
.Xr printf 3 .
The first form provides functionality similar to
.Xr asprintf 3
and the second form is similar to
.Xr vasprintf 3 .
.Sh RETURN VALUES
These functions return a std::string object.
.Sh EXCEPTIONS
These functions may throw one of the following exceptions:
.Bl -tag -width Er
.It Bq Er std::bad_alloc
Failed to allocate memory.
.It Bq Er std::length_error
The result would exceeed the maximum possible string size.
.El
.Sh EXAMPLES
.Bd -literal -offset indent
std::string s = freebsd::stringf("hello %s", "world");
.Ed
.Sh SEE ALSO
.Xr asprintf 3