xref: /freebsd/lib/libutil++/freebsd__FILE_up.3 (revision cb2887746f8b9dd4ad6b1e757cdc053a08b25a2e)
1.\"
2.\" SPDX-License-Identifier: BSD-2-Clause
3.\"
4.\" Copyright (c) 2025 Chelsio Communications, Inc.
5.\" Written by: John Baldwin <jhb@FreeBSD.org>
6.\"
7.Dd July 31, 2025
8.Dt FREEBSD::FILE_UP 3
9.Os
10.Sh NAME
11.Nm freebsd::FILE_up
12.Nd std::unique_ptr specialization for stdio FILE objects
13.Sh LIBRARY
14.Lb libutil++
15.Sh SYNOPSIS
16.In libutil++.hh
17.Ft using FILE_up = std::unique_ptr<FILE, fclose_deleter>;
18.Sh DESCRIPTION
19This class is a specialization of
20.Vt std::unique_ptr
21for stdio
22.Vt FILE
23objects.
24When a
25.Vt FILE
26object managed by an instance of this class is disposed,
27.Xr fclose 3
28is invoked to dispose of the
29.Vt FILE
30object.
31.Sh EXAMPLES
32.Bd -literal -offset indent
33freebsd::FILE_up fp(fopen("foo.txt", "w"));
34if (!fp)
35	err(1, "fopen");
36fprintf(fp.get(), "hello\n");
37// `fp' is implicitly closed on destruction
38.Ed
39.Sh SEE ALSO
40.Xr fclose 3 ,
41.Xr fopen 3
42