adb: extract the adb-specific unique_fd out into its own header. am: 924d35a8d5
am: 2c6ff3d2b5
Change-Id: I921ef808d09872901454a6ed92e2c164df435c0c
This commit is contained in:
commit
d70699ef75
6 changed files with 34 additions and 10 deletions
26
adb/adb_unique_fd.h
Normal file
26
adb/adb_unique_fd.h
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <android-base/unique_fd.h>
|
||||||
|
|
||||||
|
// Helper to automatically close an FD when it goes out of scope.
|
||||||
|
struct AdbCloser {
|
||||||
|
static void Close(int fd);
|
||||||
|
};
|
||||||
|
|
||||||
|
using unique_fd = android::base::unique_fd_impl<AdbCloser>;
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#define TRACE_TAG ADB
|
#define TRACE_TAG ADB
|
||||||
|
|
||||||
#include "adb_utils.h"
|
#include "adb_utils.h"
|
||||||
|
#include "adb_unique_fd.h"
|
||||||
|
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -309,3 +310,7 @@ std::string adb_get_android_dir_path() {
|
||||||
}
|
}
|
||||||
return android_dir;
|
return android_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AdbCloser::Close(int fd) {
|
||||||
|
adb_close(fd);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <android-base/macros.h>
|
#include <android-base/macros.h>
|
||||||
#include <android-base/unique_fd.h>
|
|
||||||
|
|
||||||
void close_stdin();
|
void close_stdin();
|
||||||
|
|
||||||
|
|
@ -57,13 +56,4 @@ extern int adb_close(int fd);
|
||||||
bool forward_targets_are_valid(const std::string& source, const std::string& dest,
|
bool forward_targets_are_valid(const std::string& source, const std::string& dest,
|
||||||
std::string* error);
|
std::string* error);
|
||||||
|
|
||||||
// Helper to automatically close an FD when it goes out of scope.
|
|
||||||
struct AdbCloser {
|
|
||||||
static void Close(int fd) {
|
|
||||||
adb_close(fd);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using unique_fd = android::base::unique_fd_impl<AdbCloser>;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
#include "adb_auth.h"
|
#include "adb_auth.h"
|
||||||
#include "adb_client.h"
|
#include "adb_client.h"
|
||||||
#include "adb_io.h"
|
#include "adb_io.h"
|
||||||
|
#include "adb_unique_fd.h"
|
||||||
#include "adb_utils.h"
|
#include "adb_utils.h"
|
||||||
#include "bugreport.h"
|
#include "bugreport.h"
|
||||||
#include "commandline.h"
|
#include "commandline.h"
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
#include "adb_io.h"
|
#include "adb_io.h"
|
||||||
|
#include "adb_unique_fd.h"
|
||||||
#include "adb_utils.h"
|
#include "adb_utils.h"
|
||||||
|
|
||||||
/* here's how these things work.
|
/* here's how these things work.
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
#include "adb_io.h"
|
#include "adb_io.h"
|
||||||
#include "adb_trace.h"
|
#include "adb_trace.h"
|
||||||
|
#include "adb_unique_fd.h"
|
||||||
#include "adb_utils.h"
|
#include "adb_utils.h"
|
||||||
#include "security_log_tags.h"
|
#include "security_log_tags.h"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue