diff options
| author | Julian Andres Klode <jak@debian.org> | 2024-11-12 13:29:09 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2024-11-12 13:29:09 +0000 |
| commit | 8fd0ebc330bcdbced85877ff48bf40582bf983f9 (patch) | |
| tree | 9e8c83e567731fba5f00cc959b075fa0ee9533ba /apt-pkg/contrib/fileutl.h | |
| parent | 8342f913c05c453e784bf038745351047d09af0a (diff) | |
| parent | a05e6fe18329ff8d91acf10efd4a1408858b0fda (diff) | |
Merge branch 'more' into 'main'
APT_BUFFER_SIZE pkgTagFile default size. std::vector(1024) -> std::array<1024>. dpkgpm buffers
See merge request apt-team/apt!390
Diffstat (limited to 'apt-pkg/contrib/fileutl.h')
| -rw-r--r-- | apt-pkg/contrib/fileutl.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index db29ad71c..4ecddbf86 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -29,6 +29,7 @@ #include <ctime> #include <set> +#include <memory> #include <string> #include <vector> #include <sys/stat.h> @@ -284,4 +285,32 @@ APT_HIDDEN bool OpenConfigurationFileFd(std::string const &File, FileFd &Fd); APT_HIDDEN int Inhibit(const char *what, const char *who, const char *why, const char *mode); + +namespace { + struct FILEFcloseDeleter { + void operator()(FILE *p) { + fclose(p); + } + }; + struct FILEPcloseDeleter { + void operator()(FILE *p) { + pclose(p); + } + }; + + [[maybe_unused]] std::unique_ptr<FILE, FILEFcloseDeleter> make_unique_FILE(const char *const filename, char const *const mode) + { + return {fopen(filename, mode), {}}; + } + [[maybe_unused]] std::unique_ptr<FILE, FILEFcloseDeleter> make_unique_FILE(std::string const &filename, char const *const mode) + { + return make_unique_FILE(filename.c_str(), mode); + } + + [[maybe_unused]] std::unique_ptr<FILE, FILEPcloseDeleter> make_unique_popen(const char *program, char const *const mode) + { + return {popen(program, mode), {}}; + } +} + #endif |
