use common AutoDeleter types

Change-Id: I115e14b76f3ff049c5f7d9471efd3619a0038fcf
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3483
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
This commit is contained in:
X512 2020-12-09 18:39:56 +09:00 committed by Adrien Destugues
parent 47404f12f2
commit cdccd323b5
19 changed files with 48 additions and 60 deletions

View File

@ -1,17 +0,0 @@
/*
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
* Distributed under the terms of the MIT License.
*/
#ifndef UTILS_H
#define UTILS_H
#include <AutoDeleter.h>
#include <vfs.h>
typedef CObjectDeleter<vnode, void, vfs_put_vnode> VnodePutter;
#endif // UTILS_H

View File

@ -19,11 +19,11 @@
#include <vfs.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include "DebugSupport.h"
#include "kernel_interface.h"
#include "Node.h"
#include "Utils.h"
// #pragma mark - Volume
@ -51,8 +51,7 @@ Volume::Mount(const char* parameterString)
{
const char* source = NULL;
void* parameterHandle = parse_driver_settings_string(parameterString);
CObjectDeleter<void, status_t, delete_driver_settings>
parameterDeleter(parameterHandle);
DriverSettingsUnloader parameterDeleter(parameterHandle);
if (parameterHandle != NULL)
source = get_driver_parameter(parameterHandle, "source", NULL, NULL);
if (source == NULL || source[0] == '\0') {

View File

@ -12,12 +12,11 @@
#include <vfs.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include "DebugSupport.h"
#include "kernel_interface.h"
#include "Node.h"
#include "Utils.h"
#include "Volume.h"

View File

@ -6,7 +6,7 @@
#include "PackageFSRoot.h"
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <vfs.h>
@ -114,7 +114,7 @@ PackageFSRoot::RegisterVolume(Volume* volume)
relativeRootPath, strerror(error));
RETURN_ERROR(error);
}
CObjectDeleter<struct vnode, void, vfs_put_vnode> vnodePutter(vnode);
VnodePutter vnodePutter(vnode);
// stat it
struct stat st;

View File

@ -8,7 +8,7 @@
#include <driver_settings.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <directories.h>
#include <fs/KPath.h>
#include <vfs.h>
@ -216,8 +216,7 @@ PackageSettings::Load(dev_t mountPointDeviceID, ino_t mountPointNodeID,
void* settingsHandle = load_driver_settings(path.Path());
if (settingsHandle == NULL)
return B_ENTRY_NOT_FOUND;
CObjectDeleter<void, status_t, unload_driver_settings>
settingsDeleter(settingsHandle);
DriverSettingsUnloader settingsDeleter(settingsHandle);
const driver_settings* settings = get_driver_settings(settingsHandle);
for (int i = 0; i < settings->parameter_count; i++) {

View File

@ -22,6 +22,8 @@
#include <package/PackageInfoAttributes.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include <AutoDeleterDrivers.h>
#include <PackagesDirectoryDefs.h>
#include <vfs.h>
@ -329,8 +331,7 @@ Volume::Mount(const char* parameterString)
NULL);
}
CObjectDeleter<void, status_t, delete_driver_settings>
parameterHandleDeleter(parameterHandle);
DriverSettingsUnloader parameterHandleDeleter(parameterHandle);
if (packages != NULL && packages[0] == '\0') {
FATAL("invalid package folder ('packages' parameter)!\n");
@ -711,7 +712,7 @@ Volume::_LoadOldPackagesStates(const char* packagesState)
ERROR("Failed to open administrative directory: %s\n", strerror(errno));
RETURN_ERROR(errno);
}
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
while (dirent* entry = readdir(dir)) {
if (strncmp(entry->d_name, "state_", 6) != 0
@ -903,7 +904,7 @@ Volume::_AddInitialPackagesFromDirectory()
fPackagesDirectory->Path(), strerror(errno));
RETURN_ERROR(errno);
}
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
while (dirent* entry = readdir(dir)) {
// skip "." and ".."
@ -1778,7 +1779,7 @@ Volume::_PublishShineThroughDirectories()
_RemoveNode(directory);
continue;
}
CObjectDeleter<struct vnode, void, vfs_put_vnode> vnodePutter(vnode);
VnodePutter vnodePutter(vnode);
// stat it
struct stat st;

View File

@ -51,6 +51,7 @@
#include <AppMisc.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include <cpu_type.h>
#include <parsedate.h>
#include <system_revision.h>
@ -1463,7 +1464,7 @@ AboutView::_AddCopyrightsFromAttribute()
close(attrFD);
return;
}
CObjectDeleter<FILE, int, fclose> _(attrFile);
FileCloser _(attrFile);
// read and parse the copyrights
BMessage package;

View File

@ -12,7 +12,7 @@
#include <termios.h>
#include <unistd.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include <user_group.h>
@ -38,7 +38,7 @@ read_password(const char* prompt, char* password, size_t bufferSize,
in = tty;
out = tty;
}
CObjectDeleter<FILE, int, fclose> ttyCloser(tty);
FileCloser ttyCloser(tty);
// disable echo
int inFD = fileno(in);

View File

@ -14,6 +14,7 @@
#include <package/hpkg/HPKGDefs.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
status_t
@ -27,7 +28,7 @@ add_current_directory_entries(BPackageWriter& packageWriter,
strerror(errno));
return errno;
}
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
while (dirent* entry = readdir(dir)) {
// skip "." and ".."

View File

@ -17,6 +17,7 @@
#include <String.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include <StringForSize.h>
#include <TextTable.h>
@ -387,7 +388,7 @@ command_list(int argc, const char* const* argv)
strerror(errno));
return 1;
}
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
TextTable table;
table.AddColumn("ID", B_ALIGN_RIGHT);

View File

@ -19,6 +19,7 @@
#include <Message.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <package/PackageInfo.h>
@ -360,8 +361,7 @@ BRepositoryInfo::_SetTo(const BEntry& entry)
void* settingsHandle = parse_driver_settings_string(configString.String());
if (settingsHandle == NULL)
return B_BAD_DATA;
CObjectDeleter<void, status_t, unload_driver_settings>
settingsHandleDeleter(settingsHandle);
DriverSettingsUnloader settingsHandleDeleter(settingsHandle);
const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL);
const char* identifier = get_driver_parameter(settingsHandle, "identifier", NULL, NULL);

View File

@ -33,6 +33,7 @@
#include <package/hpkg/PackageDataReader.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include <RangeArray.h>
#include <package/hpkg/HPKGDefsPrivate.h>
@ -1138,7 +1139,7 @@ PackageWriterImpl::_UpdateCheckEntryCollisions(Attribute* parentAttribute,
// first we check for colliding node attributes, though
if (DIR* attrDir = fs_fopen_attr_dir(fd)) {
CObjectDeleter<DIR, int, fs_close_attr_dir> attrDirCloser(attrDir);
AttrDirCloser attrDirCloser(attrDir);
while (dirent* entry = fs_read_attr_dir(attrDir)) {
attr_info attrInfo;
@ -1184,7 +1185,7 @@ PackageWriterImpl::_UpdateCheckEntryCollisions(Attribute* parentAttribute,
close(clonedFD);
throw status_t(errno);
}
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
while (dirent* entry = readdir(dir)) {
// skip "." and ".."
@ -1525,7 +1526,7 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
// add attributes
if (DIR* attrDir = fs_fopen_attr_dir(fd)) {
CObjectDeleter<DIR, int, fs_close_attr_dir> attrDirCloser(attrDir);
AttrDirCloser attrDirCloser(attrDir);
while (dirent* entry = fs_read_attr_dir(attrDir)) {
attr_info attrInfo;
@ -1586,7 +1587,7 @@ PackageWriterImpl::_AddDirectoryChildren(Entry* entry, int fd, char* pathBuffer)
close(clonedFD);
throw status_t(errno);
}
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
while (dirent* entry = readdir(dir)) {
// skip "." and ".."

View File

@ -18,6 +18,7 @@
#include <Path.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include "PackageManagerUtils.h"
@ -210,7 +211,7 @@ BRepositoryBuilder::AddPackagesDirectory(const char* path)
DIR* dir = opendir(path);
if (dir == NULL)
DIE(errno, "failed to open package directory \"%s\"", path);
CObjectDeleter<DIR, int, closedir> dirCloser(dir);
DirCloser dirCloser(dir);
// iterate through directory entries
while (dirent* entry = readdir(dir)) {

View File

@ -18,6 +18,7 @@
#include <string.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
@ -139,8 +140,7 @@ Settings::ReadSwapSettings()
void* settings = load_driver_settings(kVirtualMemorySettings);
if (settings == NULL)
return kErrorSettingsNotFound;
CObjectDeleter<void, status_t, unload_driver_settings>
settingDeleter(settings);
DriverSettingsUnloader settingDeleter(settings);
const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
const char* automatic = get_driver_parameter(settings, "swap_auto",

View File

@ -20,6 +20,7 @@
#include <StringList.h>
#include <AutoDeleter.h>
#include <AutoDeleterPosix.h>
#include <LaunchRoster.h>
#include <RegistrarDefs.h>
@ -568,14 +569,14 @@ public:
debug_printf("REG: Failed to open passwd file \"%s\" for "
"writing: %s\n", kPasswdFile, strerror(errno));
}
CObjectDeleter<FILE, int, fclose> _1(passwdFile);
FileCloser _1(passwdFile);
FILE* shadowFile = fopen(kShadowPwdFile, "w");
if (shadowFile == NULL) {
debug_printf("REG: Failed to open shadow passwd file \"%s\" for "
"writing: %s\n", kShadowPwdFile, strerror(errno));
}
CObjectDeleter<FILE, int, fclose> _2(shadowFile);
FileCloser _2(shadowFile);
// write users
for (map<uid_t, User*>::const_iterator it = fUsersByID.begin();
@ -694,7 +695,7 @@ public:
debug_printf("REG: Failed to open group file \"%s\" for "
"writing: %s\n", kGroupFile, strerror(errno));
}
CObjectDeleter<FILE, int, fclose> _1(groupFile);
FileCloser _1(groupFile);
// write groups
for (map<gid_t, Group*>::const_iterator it = fGroupsByID.begin();
@ -1245,7 +1246,7 @@ AuthenticationManager::_InitPasswdDB()
kPasswdFile, strerror(errno));
return errno;
}
CObjectDeleter<FILE, int, fclose> _(file);
FileCloser _(file);
char lineBuffer[LINE_MAX];
while (char* line = fgets(lineBuffer, sizeof(lineBuffer), file)) {
@ -1294,7 +1295,7 @@ AuthenticationManager::_InitGroupDB()
kGroupFile, strerror(errno));
return errno;
}
CObjectDeleter<FILE, int, fclose> _(file);
FileCloser _(file);
char lineBuffer[LINE_MAX];
while (char* line = fgets(lineBuffer, sizeof(lineBuffer), file)) {
@ -1342,7 +1343,7 @@ AuthenticationManager::_InitShadowPwdDB()
kShadowPwdFile, strerror(errno));
return errno;
}
CObjectDeleter<FILE, int, fclose> _(file);
FileCloser _(file);
char lineBuffer[LINE_MAX];
while (char* line = fgets(lineBuffer, sizeof(lineBuffer), file)) {

View File

@ -8,7 +8,7 @@
#include <driver_settings.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <boot/vfs.h>
#include <system/directories.h>
@ -54,8 +54,7 @@ PackageSettingsItem::Load(::Directory* systemDirectory, const char* name)
void* settingsHandle = load_driver_settings_file(fd);
if (settingsHandle == NULL)
return NULL;
CObjectDeleter<void, status_t, &unload_driver_settings>
settingsDeleter(settingsHandle);
DriverSettingsUnloader settingsDeleter(settingsHandle);
const driver_settings* settings = get_driver_settings(settingsHandle);
for (int i = 0; i < settings->parameter_count; i++) {

View File

@ -16,6 +16,7 @@
#include <OS.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <BytePointer.h>
#include <syscalls.h>
@ -497,7 +498,7 @@ dup_foreign_fd(team_id fromTeam, int fd, bool kernel)
file_descriptor* descriptor = get_fd(fromContext, fd);
if (descriptor == NULL)
return B_FILE_ERROR;
CObjectDeleter<file_descriptor, void, put_fd> descriptorPutter(descriptor);
DescriptorPutter descriptorPutter(descriptor);
// create a new FD in the target I/O context
int result = new_fd(get_current_io_context(kernel), descriptor);

View File

@ -15,6 +15,7 @@
#include <heap.h>
#include <AutoDeleterDrivers.h>
// #pragma mark - AsyncIOCallback
@ -478,7 +479,7 @@ do_fd_io(int fd, io_request* request)
return B_FILE_ERROR;
}
CObjectDeleter<file_descriptor, void, put_fd> descriptorPutter(descriptor);
DescriptorPutter descriptorPutter(descriptor);
return vfs_vnode_io(vnode, descriptor->cookie, request);
}
@ -500,7 +501,7 @@ do_iterative_fd_io(int fd, io_request* request, iterative_io_get_vecs getVecs,
return B_FILE_ERROR;
}
CObjectDeleter<file_descriptor, void, put_fd> descriptorPutter(descriptor);
DescriptorPutter descriptorPutter(descriptor);
if (!HAS_FS_CALL(vnode, io)) {
// no io() call -- fall back to synchronous I/O

View File

@ -21,7 +21,7 @@
#include <OS.h>
#include <KernelExport.h>
#include <AutoDeleter.h>
#include <AutoDeleterDrivers.h>
#include <symbol_versioning.h>
@ -2054,7 +2054,7 @@ _vm_map_file(team_id team, const char* name, void** _address,
status_t status = vfs_get_vnode_from_fd(fd, kernel, &vnode);
if (status < B_OK)
return status;
CObjectDeleter<struct vnode, void, vfs_put_vnode> vnodePutter(vnode);
VnodePutter vnodePutter(vnode);
// If we're going to pre-map pages, we need to reserve the pages needed by
// the mapping backend upfront.