Merge "[installd] Modernize codebase by replacing NULL with nullptr"
am: a6ada23472
Change-Id: I89a2a44bddda13f3e5e080a841de640493305ee8
diff --git a/cmds/installd/CacheItem.cpp b/cmds/installd/CacheItem.cpp
index 515f915..e29ff4c 100644
--- a/cmds/installd/CacheItem.cpp
+++ b/cmds/installd/CacheItem.cpp
@@ -73,7 +73,7 @@
FTS *fts;
FTSENT *p;
char *argv[] = { (char*) path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
PLOG(WARNING) << "Failed to fts_open " << path;
return -1;
}
diff --git a/cmds/installd/CacheTracker.cpp b/cmds/installd/CacheTracker.cpp
index ea0cd9e..a7242c3 100644
--- a/cmds/installd/CacheTracker.cpp
+++ b/cmds/installd/CacheTracker.cpp
@@ -103,7 +103,7 @@
FTS *fts;
FTSENT *p;
char *argv[] = { (char*) path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
PLOG(WARNING) << "Failed to fts_open " << path;
return;
}
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index f5f74bf..28ffdf1 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -661,7 +661,7 @@
auto ce_path = create_data_user_ce_path(uuid_, user);
auto de_path = create_data_user_de_path(uuid_, user);
char *argv[] = { (char*) ce_path.c_str(), (char*) de_path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
return error("Failed to fts_open");
}
while ((p = fts_read(fts)) != nullptr) {
@@ -786,7 +786,7 @@
};
LOG(DEBUG) << "Copying " << from << " to " << to;
- int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, NULL, false, true);
+ int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, nullptr, false, true);
if (rc != 0) {
res = error(rc, "Failed copying " + from + " to " + to);
goto fail;
@@ -832,7 +832,7 @@
argv[7] = (char*) to.c_str();
LOG(DEBUG) << "Copying " << from << " to " << to;
- int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, NULL, false, true);
+ int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, nullptr, false, true);
if (rc != 0) {
res = error(rc, "Failed copying " + from + " to " + to);
goto fail;
@@ -845,7 +845,7 @@
argv[7] = (char*) to.c_str();
LOG(DEBUG) << "Copying " << from << " to " << to;
- int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, NULL, false, true);
+ int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, nullptr, false, true);
if (rc != 0) {
res = error(rc, "Failed copying " + from + " to " + to);
goto fail;
@@ -868,20 +868,20 @@
// Nuke everything we might have already copied
{
auto to = create_data_app_package_path(to_uuid, data_app_name);
- if (delete_dir_contents(to.c_str(), 1, NULL) != 0) {
+ if (delete_dir_contents(to.c_str(), 1, nullptr) != 0) {
LOG(WARNING) << "Failed to rollback " << to;
}
}
for (auto user : users) {
{
auto to = create_data_user_de_package_path(to_uuid, user, package_name);
- if (delete_dir_contents(to.c_str(), 1, NULL) != 0) {
+ if (delete_dir_contents(to.c_str(), 1, nullptr) != 0) {
LOG(WARNING) << "Failed to rollback " << to;
}
}
{
auto to = create_data_user_ce_package_path(to_uuid, user, package_name);
- if (delete_dir_contents(to.c_str(), 1, NULL) != 0) {
+ if (delete_dir_contents(to.c_str(), 1, nullptr) != 0) {
LOG(WARNING) << "Failed to rollback " << to;
}
}
@@ -984,10 +984,10 @@
auto media_path = findDataMediaPath(uuid, user) + "/Android/data/";
char *argv[] = { (char*) ce_path.c_str(), (char*) de_path.c_str(),
(char*) media_path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
return error("Failed to fts_open");
}
- while ((p = fts_read(fts)) != NULL) {
+ while ((p = fts_read(fts)) != nullptr) {
if (p->fts_info == FTS_D && p->fts_level == 1) {
uid_t uid = p->fts_statp->st_uid;
if (multiuser_get_app_id(uid) == AID_MEDIA_RW) {
@@ -1337,11 +1337,11 @@
FTS *fts;
FTSENT *p;
char *argv[] = { (char*) path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
PLOG(ERROR) << "Failed to fts_open " << path;
return;
}
- while ((p = fts_read(fts)) != NULL) {
+ while ((p = fts_read(fts)) != nullptr) {
p->fts_number = p->fts_parent->fts_number;
switch (p->fts_info) {
case FTS_D:
@@ -1747,10 +1747,10 @@
FTSENT *p;
auto path = create_data_media_path(uuid_, userId);
char *argv[] = { (char*) path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
return error("Failed to fts_open " + path);
}
- while ((p = fts_read(fts)) != NULL) {
+ while ((p = fts_read(fts)) != nullptr) {
char* ext;
int64_t size = (p->fts_statp->st_blocks * 512);
switch (p->fts_info) {
@@ -1980,7 +1980,7 @@
}
} else {
if (S_ISDIR(libStat.st_mode)) {
- if (delete_dir_contents(libsymlink, 1, NULL) < 0) {
+ if (delete_dir_contents(libsymlink, 1, nullptr) < 0) {
res = error("Failed to delete " + _libsymlink);
goto out;
}
@@ -2022,14 +2022,14 @@
static void run_idmap(const char *target_apk, const char *overlay_apk, int idmap_fd)
{
execl(kIdMapPath, kIdMapPath, "--fd", target_apk, overlay_apk,
- StringPrintf("%d", idmap_fd).c_str(), (char*)NULL);
+ StringPrintf("%d", idmap_fd).c_str(), (char*)nullptr);
PLOG(ERROR) << "execl (" << kIdMapPath << ") failed";
}
static void run_verify_idmap(const char *target_apk, const char *overlay_apk, int idmap_fd)
{
execl(kIdMapPath, kIdMapPath, "--verify", target_apk, overlay_apk,
- StringPrintf("%d", idmap_fd).c_str(), (char*)NULL);
+ StringPrintf("%d", idmap_fd).c_str(), (char*)nullptr);
PLOG(ERROR) << "execl (" << kIdMapPath << ") failed";
}
@@ -2080,7 +2080,7 @@
static int flatten_path(const char *prefix, const char *suffix,
const char *overlay_path, char *idmap_path, size_t N)
{
- if (overlay_path == NULL || idmap_path == NULL) {
+ if (overlay_path == nullptr || idmap_path == nullptr) {
return -1;
}
const size_t len_overlay_path = strlen(overlay_path);
@@ -2421,7 +2421,7 @@
std::to_string(shmSize));
}
auto data = std::unique_ptr<void, std::function<void (void *)>>(
- mmap(NULL, contentSize, PROT_READ, MAP_SHARED, verityInputAshmem.get(), 0),
+ mmap(nullptr, contentSize, PROT_READ, MAP_SHARED, verityInputAshmem.get(), 0),
[contentSize] (void* ptr) {
if (ptr != MAP_FAILED) {
munmap(ptr, contentSize);
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index 03a411d..66dece7 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -190,9 +190,9 @@
strlcpy(buf, str, sizeof(buf));
char *pBuf = buf;
- while(strtok_r(pBuf, " ", &ctx) != NULL) {
+ while(strtok_r(pBuf, " ", &ctx) != nullptr) {
count++;
- pBuf = NULL;
+ pBuf = nullptr;
}
return count;
@@ -205,9 +205,9 @@
char *tok;
char *pBuf = buf;
- while((tok = strtok_r(pBuf, " ", &ctx)) != NULL) {
+ while((tok = strtok_r(pBuf, " ", &ctx)) != nullptr) {
argv[count++] = tok;
- pBuf = NULL;
+ pBuf = nullptr;
}
return count;
@@ -216,7 +216,7 @@
static const char* get_location_from_path(const char* path) {
static constexpr char kLocationSeparator = '/';
const char *location = strrchr(path, kLocationSeparator);
- if (location == NULL) {
+ if (location == nullptr) {
return path;
} else {
// Skip the separator character.
@@ -243,17 +243,17 @@
const char* relative_input_file_name = get_location_from_path(input_file_name);
char dex2oat_Xms_flag[kPropertyValueMax];
- bool have_dex2oat_Xms_flag = get_property("dalvik.vm.dex2oat-Xms", dex2oat_Xms_flag, NULL) > 0;
+ bool have_dex2oat_Xms_flag = get_property("dalvik.vm.dex2oat-Xms", dex2oat_Xms_flag, nullptr) > 0;
char dex2oat_Xmx_flag[kPropertyValueMax];
- bool have_dex2oat_Xmx_flag = get_property("dalvik.vm.dex2oat-Xmx", dex2oat_Xmx_flag, NULL) > 0;
+ bool have_dex2oat_Xmx_flag = get_property("dalvik.vm.dex2oat-Xmx", dex2oat_Xmx_flag, nullptr) > 0;
char dex2oat_threads_buf[kPropertyValueMax];
bool have_dex2oat_threads_flag = get_property(post_bootcomplete
? "dalvik.vm.dex2oat-threads"
: "dalvik.vm.boot-dex2oat-threads",
dex2oat_threads_buf,
- NULL) > 0;
+ nullptr) > 0;
char dex2oat_threads_arg[kPropertyValueMax + 2];
if (have_dex2oat_threads_flag) {
sprintf(dex2oat_threads_arg, "-j%s", dex2oat_threads_buf);
@@ -263,20 +263,20 @@
sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
char dex2oat_isa_features[kPropertyValueMax];
bool have_dex2oat_isa_features = get_property(dex2oat_isa_features_key,
- dex2oat_isa_features, NULL) > 0;
+ dex2oat_isa_features, nullptr) > 0;
char dex2oat_isa_variant_key[kPropertyKeyMax];
sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
char dex2oat_isa_variant[kPropertyValueMax];
bool have_dex2oat_isa_variant = get_property(dex2oat_isa_variant_key,
- dex2oat_isa_variant, NULL) > 0;
+ dex2oat_isa_variant, nullptr) > 0;
const char *dex2oat_norelocation = "-Xnorelocate";
bool have_dex2oat_relocation_skip_flag = false;
char dex2oat_flags[kPropertyValueMax];
int dex2oat_flags_count = get_property("dalvik.vm.dex2oat-flags",
- dex2oat_flags, NULL) <= 0 ? 0 : split_count(dex2oat_flags);
+ dex2oat_flags, nullptr) <= 0 ? 0 : split_count(dex2oat_flags);
ALOGV("dalvik.vm.dex2oat-flags=%s\n", dex2oat_flags);
// If we are booting without the real /data, don't spend time compiling.
@@ -291,14 +291,14 @@
char app_image_format[kPropertyValueMax];
char image_format_arg[strlen("--image-format=") + kPropertyValueMax];
bool have_app_image_format =
- image_fd >= 0 && get_property("dalvik.vm.appimageformat", app_image_format, NULL) > 0;
+ image_fd >= 0 && get_property("dalvik.vm.appimageformat", app_image_format, nullptr) > 0;
if (have_app_image_format) {
sprintf(image_format_arg, "--image-format=%s", app_image_format);
}
char dex2oat_large_app_threshold[kPropertyValueMax];
bool have_dex2oat_large_app_threshold =
- get_property("dalvik.vm.dex2oat-very-large", dex2oat_large_app_threshold, NULL) > 0;
+ get_property("dalvik.vm.dex2oat-very-large", dex2oat_large_app_threshold, nullptr) > 0;
char dex2oat_large_app_threshold_arg[strlen("--very-large-app-threshold=") + kPropertyValueMax];
if (have_dex2oat_large_app_threshold) {
sprintf(dex2oat_large_app_threshold_arg,
@@ -400,7 +400,7 @@
if (!have_dex2oat_compiler_filter_flag) {
char dex2oat_compiler_filter_flag[kPropertyValueMax];
have_dex2oat_compiler_filter_flag = get_property("dalvik.vm.dex2oat-filter",
- dex2oat_compiler_filter_flag, NULL) > 0;
+ dex2oat_compiler_filter_flag, nullptr) > 0;
if (have_dex2oat_compiler_filter_flag) {
sprintf(dex2oat_compiler_filter_arg,
"--compiler-filter=%s",
@@ -552,7 +552,7 @@
argv[i++] = compilation_reason_arg.c_str();
}
// Do not add after dex2oat_flags, they should override others for debugging.
- argv[i] = NULL;
+ argv[i] = nullptr;
execv(dex2oat_bin, (char * const *)argv);
PLOG(ERROR) << "execv(" << dex2oat_bin << ") failed";
@@ -792,7 +792,7 @@
}
// Do not add after dex2oat_flags, they should override others for debugging.
- argv[i] = NULL;
+ argv[i] = nullptr;
execv(profman_bin, (char * const *)argv);
PLOG(ERROR) << "execv(" << profman_bin << ") failed";
@@ -948,7 +948,7 @@
for (const std::string& profman_arg : profman_args) {
argv[i++] = profman_arg.c_str();
}
- argv[i] = NULL;
+ argv[i] = nullptr;
execv(PROFMAN_BIN, (char * const *)argv);
PLOG(ERROR) << "execv(" << PROFMAN_BIN << ") failed";
@@ -1308,7 +1308,7 @@
}
char app_image_format[kPropertyValueMax];
bool have_app_image_format =
- get_property("dalvik.vm.appimageformat", app_image_format, NULL) > 0;
+ get_property("dalvik.vm.appimageformat", app_image_format, nullptr) > 0;
if (!have_app_image_format) {
return Dex2oatFileWrapper();
}
@@ -1629,7 +1629,7 @@
if (class_loader_context != nullptr) {
argv[i++] = class_loader_context_arg.c_str();
}
- argv[i] = NULL;
+ argv[i] = nullptr;
execv(dexoptanalyzer_bin, (char * const *)argv);
ALOGE("execv(%s) failed: %s\n", dexoptanalyzer_bin, strerror(errno));
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index 95ed2ff..673ff0d 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -107,7 +107,7 @@
DIR *dir;
struct dirent *dirent;
dir = opendir("/data/user");
- if (dir != NULL) {
+ if (dir != nullptr) {
while ((dirent = readdir(dir))) {
const char *name = dirent->d_name;
@@ -146,10 +146,10 @@
closedir(dir);
if (access(keychain_added_dir, F_OK) == 0) {
- delete_dir_contents(keychain_added_dir, 1, 0);
+ delete_dir_contents(keychain_added_dir, 1, nullptr);
}
if (access(keychain_removed_dir, F_OK) == 0) {
- delete_dir_contents(keychain_removed_dir, 1, 0);
+ delete_dir_contents(keychain_removed_dir, 1, nullptr);
}
}
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 8672206..6b9cf0d 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -310,7 +310,7 @@
std::string path(create_data_path(volume_uuid) + "/" + SECONDARY_USER_PREFIX);
DIR* dir = opendir(path.c_str());
- if (dir == NULL) {
+ if (dir == nullptr) {
// Unable to discover other users, but at least return owner
PLOG(ERROR) << "Failed to opendir " << path;
return users;
@@ -340,13 +340,13 @@
FTSENT *p;
int64_t matchedSize = 0;
char *argv[] = { (char*) path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
if (errno != ENOENT) {
PLOG(ERROR) << "Failed to fts_open " << path;
}
return -1;
}
- while ((p = fts_read(fts)) != NULL) {
+ while ((p = fts_read(fts)) != nullptr) {
switch (p->fts_info) {
case FTS_D:
case FTS_DEFAULT:
@@ -469,7 +469,7 @@
continue;
}
subdir = fdopendir(subfd);
- if (subdir == NULL) {
+ if (subdir == nullptr) {
ALOGE("Couldn't fdopendir %s: %s\n", name, strerror(errno));
close(subfd);
result = -1;
@@ -495,11 +495,11 @@
}
int delete_dir_contents(const std::string& pathname, bool ignore_if_missing) {
- return delete_dir_contents(pathname.c_str(), 0, NULL, ignore_if_missing);
+ return delete_dir_contents(pathname.c_str(), 0, nullptr, ignore_if_missing);
}
int delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing) {
- return delete_dir_contents(pathname.c_str(), 1, NULL, ignore_if_missing);
+ return delete_dir_contents(pathname.c_str(), 1, nullptr, ignore_if_missing);
}
int delete_dir_contents(const char *pathname,
@@ -511,7 +511,7 @@
DIR *d;
d = opendir(pathname);
- if (d == NULL) {
+ if (d == nullptr) {
if (ignore_if_missing && (errno == ENOENT)) {
return 0;
}
@@ -540,12 +540,12 @@
return -1;
}
d = fdopendir(fd);
- if (d == NULL) {
+ if (d == nullptr) {
ALOGE("Couldn't fdopendir %s: %s\n", name, strerror(errno));
close(fd);
return -1;
}
- res = _delete_dir_contents(d, 0);
+ res = _delete_dir_contents(d, nullptr);
closedir(d);
return res;
}
@@ -573,7 +573,7 @@
}
DIR *ds = fdopendir(sdfd);
- if (ds == NULL) {
+ if (ds == nullptr) {
ALOGE("Couldn't fdopendir: %s\n", strerror(errno));
return -1;
}
@@ -619,18 +619,18 @@
uid_t group)
{
int res = 0;
- DIR *ds = NULL;
- DIR *dd = NULL;
+ DIR *ds = nullptr;
+ DIR *dd = nullptr;
ds = opendir(srcname);
- if (ds == NULL) {
+ if (ds == nullptr) {
ALOGE("Couldn't opendir %s: %s\n", srcname, strerror(errno));
return -errno;
}
mkdir(dstname, 0600);
dd = opendir(dstname);
- if (dd == NULL) {
+ if (dd == nullptr) {
ALOGE("Couldn't opendir %s: %s\n", dstname, strerror(errno));
closedir(ds);
return -errno;
@@ -964,11 +964,11 @@
FTS *fts;
FTSENT *p;
char *argv[] = { (char*) path.c_str(), nullptr };
- if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) {
+ if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, nullptr))) {
PLOG(ERROR) << "Failed to fts_open " << path;
return -1;
}
- while ((p = fts_read(fts)) != NULL) {
+ while ((p = fts_read(fts)) != nullptr) {
switch (p->fts_info) {
case FTS_DP:
if (chmod(p->fts_path, target_mode) != 0) {
@@ -1037,7 +1037,7 @@
}
DIR* subdir = fdopendir(subdir_fd);
- if (subdir == NULL) {
+ if (subdir == nullptr) {
PLOG(WARNING) << "Could not open dir path " << local_path;
result = false;
continue;
@@ -1055,7 +1055,7 @@
bool collect_profiles(std::vector<std::string>* profiles_paths) {
DIR* d = opendir(android_profiles_dir.c_str());
- if (d == NULL) {
+ if (d == nullptr) {
return false;
} else {
return collect_profiles(d, android_profiles_dir, profiles_paths);