[cmds] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: I73a0a82e3e32001f8ffb0880250c7023dd8290d3
diff --git a/cmds/rawbu/backup.cpp b/cmds/rawbu/backup.cpp
index 0072281..8b20e3e 100644
--- a/cmds/rawbu/backup.cpp
+++ b/cmds/rawbu/backup.cpp
@@ -38,7 +38,7 @@
static struct stat statBuffer;
static char copyBuffer[8192];
-static char *backupFilePath = NULL;
+static char *backupFilePath = nullptr;
static uint32_t inputFileVersion;
@@ -58,7 +58,7 @@
{ "/data/system/batterystats.bin", SPECIAL_NO_TOUCH },
{ "/data/system/location", SPECIAL_NO_TOUCH },
{ "/data/dalvik-cache", SPECIAL_NO_BACKUP },
- { NULL, 0 },
+ { nullptr, 0 },
};
/* This is just copied from the shell's built-in wipe command. */
@@ -71,7 +71,7 @@
dir = opendir(path);
- if (dir == NULL) {
+ if (dir == nullptr) {
fprintf (stderr, "Error opendir'ing %s: %s\n",
path, strerror(errno));
return 0;
@@ -87,7 +87,7 @@
for (;;) {
de = readdir(dir);
- if (de == NULL) {
+ if (de == nullptr) {
break;
}
@@ -115,7 +115,7 @@
}
}
- if (!noBackup && SKIP_PATHS[i].path != NULL) {
+ if (!noBackup && SKIP_PATHS[i].path != nullptr) {
// This is a SPECIAL_NO_TOUCH directory.
continue;
}
@@ -203,7 +203,7 @@
int amt = size > (off_t)sizeof(copyBuffer) ? sizeof(copyBuffer) : (int)size;
int readLen = fread(copyBuffer, 1, amt, src);
if (readLen <= 0) {
- if (srcName != NULL) {
+ if (srcName != nullptr) {
fprintf(stderr, "unable to read source (%d of %ld bytes) file '%s': %s\n",
amt, origSize, srcName, errno != 0 ? strerror(errno) : "unexpected EOF");
} else {
@@ -214,7 +214,7 @@
}
int writeLen = fwrite(copyBuffer, 1, readLen, dest);
if (writeLen != readLen) {
- if (destName != NULL) {
+ if (destName != nullptr) {
fprintf(stderr, "unable to write file (%d of %d bytes) '%s': '%s'\n",
writeLen, readLen, destName, strerror(errno));
} else {
@@ -256,14 +256,14 @@
{
DIR *dir;
struct dirent *de;
- char* fullPath = NULL;
+ char* fullPath = nullptr;
int srcLen = strlen(srcPath);
int result = 1;
int i;
dir = opendir(srcPath);
- if (dir == NULL) {
+ if (dir == nullptr) {
fprintf (stderr, "error opendir'ing '%s': %s\n",
srcPath, strerror(errno));
return 0;
@@ -272,7 +272,7 @@
for (;;) {
de = readdir(dir);
- if (de == NULL) {
+ if (de == nullptr) {
break;
}
@@ -283,7 +283,7 @@
continue;
}
- if (fullPath != NULL) {
+ if (fullPath != nullptr) {
free(fullPath);
}
fullPath = (char*)malloc(srcLen + strlen(de->d_name) + 2);
@@ -298,7 +298,7 @@
break;
}
}
- if (SKIP_PATHS[i].path != NULL) {
+ if (SKIP_PATHS[i].path != nullptr) {
continue;
}
}
@@ -343,14 +343,14 @@
}
FILE* src = fopen(fullPath, "r");
- if (src == NULL) {
+ if (src == nullptr) {
fprintf(stderr, "unable to open source file '%s': %s\n",
fullPath, strerror(errno));
result = 0;
goto done;
}
- int copyres = copy_file(fh, src, size, NULL, fullPath);
+ int copyres = copy_file(fh, src, size, nullptr, fullPath);
fclose(src);
if (!copyres) {
result = 0;
@@ -360,7 +360,7 @@
}
done:
- if (fullPath != NULL) {
+ if (fullPath != nullptr) {
free(fullPath);
}
@@ -374,7 +374,7 @@
int res = -1;
FILE* fh = fopen(destPath, "w");
- if (fh == NULL) {
+ if (fh == nullptr) {
fprintf(stderr, "unable to open destination '%s': %s\n",
destPath, strerror(errno));
return -1;
@@ -504,7 +504,7 @@
int res = -1;
FILE* fh = fopen(srcPath, "r");
- if (fh == NULL) {
+ if (fh == nullptr) {
fprintf(stderr, "Unable to open source '%s': %s\n",
srcPath, strerror(errno));
return -1;
@@ -534,7 +534,7 @@
while (1) {
int type;
- char* path = NULL;
+ char* path = nullptr;
if (read_header(fh, &type, &path, &statBuffer) == 0) {
goto done;
}
@@ -570,14 +570,14 @@
printf("Restoring file %s...\n", path);
FILE* dest = fopen(path, "w");
- if (dest == NULL) {
+ if (dest == nullptr) {
fprintf(stderr, "unable to open destination file '%s': %s\n",
path, strerror(errno));
free(path);
goto done;
}
- int copyres = copy_file(dest, fh, size, path, NULL);
+ int copyres = copy_file(dest, fh, size, path, nullptr);
fclose(dest);
if (!copyres) {
free(path);