mirror of
https://github.com/opnsense/src.git
synced 2026-06-27 01:20:18 -04:00
- 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
41 lines
861 B
Groff
41 lines
861 B
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::FILE_UP 3
|
|
.Os
|
|
.Sh NAME
|
|
.Nm freebsd::FILE_up
|
|
.Nd std::unique_ptr specialization for stdio FILE objects
|
|
.Sh LIBRARY
|
|
.Lb libutil++
|
|
.Sh SYNOPSIS
|
|
.In libutil++.hh
|
|
.Ft using FILE_up = std::unique_ptr<FILE, fclose_deleter>;
|
|
.Sh DESCRIPTION
|
|
This class is a specialization of
|
|
.Vt std::unique_ptr
|
|
for stdio
|
|
.Vt FILE
|
|
objects.
|
|
When a
|
|
.Vt FILE
|
|
object managed by an instance of this class is disposed,
|
|
.Xr fclose 3
|
|
is invoked to dispose of the
|
|
.Vt FILE
|
|
object.
|
|
.Sh EXAMPLES
|
|
.Bd -literal -offset indent
|
|
freebsd::FILE_up fp(fopen("foo.txt", "w"));
|
|
if (!fp)
|
|
err(1, "fopen");
|
|
fprintf(fp.get(), "hello\n");
|
|
// `fp' is implicitly closed on destruction
|
|
.Ed
|
|
.Sh SEE ALSO
|
|
.Xr fclose 3 ,
|
|
.Xr fopen 3
|