diff options
author | Yi Kong <yikong@google.com> | 2018-08-02 16:17:51 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-08-02 16:17:51 -0700 |
commit | 9ead54bed65d486fe435793cbe98ed8b4786f7be (patch) | |
tree | ef89a483eb9255d8fae304789dd0fbd4f0726088 | |
parent | 15f50dbea58f00b74dde1cf4ae5c266a36b45419 (diff) | |
parent | ad0f33eaf156e70d4990c83b08bf6630b7026de1 (diff) | |
download | native-9ead54bed65d486fe435793cbe98ed8b4786f7be.tar.gz |
Merge "[cmds] Modernize codebase by replacing NULL with nullptr"
am: ad0f33eaf1
Change-Id: I7d55285b2e0ee1b949df253c5703be874fa21f63
-rw-r--r-- | cmds/atrace/atrace.cpp | 52 | ||||
-rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 12 | ||||
-rw-r--r-- | cmds/dumpstate/utils.cpp | 12 | ||||
-rw-r--r-- | cmds/flatland/GLHelper.cpp | 30 | ||||
-rw-r--r-- | cmds/flatland/Main.cpp | 20 | ||||
-rw-r--r-- | cmds/lshal/ListCommand.cpp | 4 | ||||
-rw-r--r-- | cmds/lshal/PipeRelay.cpp | 2 | ||||
-rw-r--r-- | cmds/lshal/Timeout.h | 6 | ||||
-rw-r--r-- | cmds/rawbu/backup.cpp | 40 | ||||
-rw-r--r-- | cmds/service/service.cpp | 32 | ||||
-rw-r--r-- | cmds/surfacereplayer/replayer/Main.cpp | 2 |
11 files changed, 106 insertions, 106 deletions
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp index ffe931d6f4..94dbebc4c0 100644 --- a/cmds/atrace/atrace.cpp +++ b/cmds/atrace/atrace.cpp @@ -230,8 +230,8 @@ static int g_traceBufferSizeKB = 2048; static bool g_compress = false; static bool g_nohup = false; static int g_initialSleepSecs = 0; -static const char* g_categoriesFile = NULL; -static const char* g_kernelTraceFuncs = NULL; +static const char* g_categoriesFile = nullptr; +static const char* g_kernelTraceFuncs = nullptr; static const char* g_debugAppCmdLine = ""; static const char* g_outputFile = nullptr; @@ -407,7 +407,7 @@ static bool isCategorySupported(const TracingCategory& category) for (int i = 0; i < MAX_SYS_FILES; i++) { const char* path = category.sysfiles[i].path; bool req = category.sysfiles[i].required == REQ; - if (path != NULL) { + if (path != nullptr) { if (req) { if (!fileIsWritable(path)) { return false; @@ -432,7 +432,7 @@ static bool isCategorySupportedForRoot(const TracingCategory& category) for (int i = 0; i < MAX_SYS_FILES; i++) { const char* path = category.sysfiles[i].path; bool req = category.sysfiles[i].required == REQ; - if (path != NULL) { + if (path != nullptr) { if (req) { if (!fileExists(path)) { return false; @@ -548,10 +548,10 @@ static bool pokeBinderServices() Vector<String16> services = sm->listServices(); for (size_t i = 0; i < services.size(); i++) { sp<IBinder> obj = sm->checkService(services[i]); - if (obj != NULL) { + if (obj != nullptr) { Parcel data; if (obj->transact(IBinder::SYSPROPS_TRANSACTION, data, - NULL, 0) != OK) { + nullptr, 0) != OK) { if (false) { // XXX: For some reason this fails on tablets trying to // poke the "phone" service. It's not clear whether some @@ -641,9 +641,9 @@ static bool setAppCmdlineProperty(char* cmdline) { int i = 0; char* start = cmdline; - while (start != NULL) { + while (start != nullptr) { char* end = strchr(start, ','); - if (end != NULL) { + if (end != nullptr) { *end = '\0'; end++; } @@ -673,7 +673,7 @@ static bool disableKernelTraceEvents() { const TracingCategory &c = k_categories[i]; for (int j = 0; j < MAX_SYS_FILES; j++) { const char* path = c.sysfiles[j].path; - if (path != NULL && fileIsWritable(path)) { + if (path != nullptr && fileIsWritable(path)) { ok &= setKernelOptionEnable(path, false); } } @@ -709,7 +709,7 @@ static bool verifyKernelTraceFuncs(const char* funcs) ok = false; } } - func = strtok(NULL, ","); + func = strtok(nullptr, ","); } free(myFuncs); return ok; @@ -720,7 +720,7 @@ static bool setKernelTraceFuncs(const char* funcs) { bool ok = true; - if (funcs == NULL || funcs[0] == '\0') { + if (funcs == nullptr || funcs[0] == '\0') { // Disable kernel function tracing. if (fileIsWritable(k_currentTracerPath)) { ok &= writeStr(k_currentTracerPath, "nop"); @@ -742,7 +742,7 @@ static bool setKernelTraceFuncs(const char* funcs) char* func = strtok(myFuncs, ","); while (func) { ok &= appendStr(k_ftraceFilterPath, func); - func = strtok(NULL, ","); + func = strtok(nullptr, ","); } free(myFuncs); @@ -784,7 +784,7 @@ static bool setCategoriesEnableFromFile(const char* categories_file) if (!categories_file) { return true; } - Tokenizer* tokenizer = NULL; + Tokenizer* tokenizer = nullptr; if (Tokenizer::open(String8(categories_file), &tokenizer) != NO_ERROR) { return false; } @@ -886,7 +886,7 @@ static bool setUpKernelTracing() for (int j = 0; j < MAX_SYS_FILES; j++) { const char* path = c.sysfiles[j].path; bool required = c.sysfiles[j].required == REQ; - if (path != NULL) { + if (path != nullptr) { if (fileIsWritable(path)) { ok &= setKernelOptionEnable(path, true); } else if (required) { @@ -911,7 +911,7 @@ static void cleanUpKernelTracing() setTraceOverwriteEnable(true); setTraceBufferSizeKB(1); setPrintTgidEnableIfPresent(false); - setKernelTraceFuncs(NULL); + setKernelTraceFuncs(nullptr); setUserInitiatedTraceProperty(false); } @@ -1069,10 +1069,10 @@ static void registerSigHandler() sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = handleSignal; - sigaction(SIGHUP, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGQUIT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + sigaction(SIGHUP, &sa, nullptr); + sigaction(SIGINT, &sa, nullptr); + sigaction(SIGQUIT, &sa, nullptr); + sigaction(SIGTERM, &sa, nullptr); } static void listSupportedCategories() @@ -1162,13 +1162,13 @@ int main(int argc, char **argv) int ret; int option_index = 0; static struct option long_options[] = { - {"async_start", no_argument, 0, 0 }, - {"async_stop", no_argument, 0, 0 }, - {"async_dump", no_argument, 0, 0 }, - {"only_userspace", no_argument, 0, 0 }, - {"list_categories", no_argument, 0, 0 }, - {"stream", no_argument, 0, 0 }, - { 0, 0, 0, 0 } + {"async_start", no_argument, nullptr, 0 }, + {"async_stop", no_argument, nullptr, 0 }, + {"async_dump", no_argument, nullptr, 0 }, + {"only_userspace", no_argument, nullptr, 0 }, + {"list_categories", no_argument, nullptr, 0 }, + {"stream", no_argument, nullptr, 0 }, + {nullptr, 0, nullptr, 0 } }; ret = getopt_long(argc, argv, "a:b:cf:k:ns:t:zo:", diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index e85274a1ef..30c5b6a6e6 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -90,7 +90,7 @@ using android::os::dumpstate::PropertiesHelper; /* read before root is shed */ static char cmdline_buf[16384] = "(unknown)"; -static const char *dump_traces_path = NULL; +static const char *dump_traces_path = nullptr; // TODO: variables and functions below should be part of dumpstate object @@ -295,7 +295,7 @@ static void dump_dev_files(const char *title, const char *driverpath, const char char path[PATH_MAX]; d = opendir(driverpath); - if (d == NULL) { + if (d == nullptr) { return; } @@ -587,7 +587,7 @@ unsigned long worst_write_perf = 20000; /* in KB/s */ static int dump_stat_from_fd(const char *title __unused, const char *path, int fd) { unsigned long long fields[__STAT_NUMBER_FIELD]; bool z; - char *cp, *buffer = NULL; + char *cp, *buffer = nullptr; size_t i = 0; FILE *fp = fdopen(dup(fd), "rb"); getline(&buffer, &i, fp); @@ -1686,7 +1686,7 @@ static std::string SHA256_file_hash(const std::string& filepath) { | O_CLOEXEC | O_NOFOLLOW))); if (fd == -1) { MYLOGE("open(%s): %s\n", filepath.c_str(), strerror(errno)); - return NULL; + return nullptr; } SHA256_CTX ctx; @@ -1699,7 +1699,7 @@ static std::string SHA256_file_hash(const std::string& filepath) { break; } else if (bytes_read == -1) { MYLOGE("read(%s): %s\n", filepath.c_str(), strerror(errno)); - return NULL; + return nullptr; } SHA256_Update(&ctx, buffer.data(), bytes_read); @@ -1748,7 +1748,7 @@ int run_main(int argc, char* argv[]) { int do_add_date = 0; int do_zip_file = 0; int do_vibrate = 1; - char* use_outfile = 0; + char* use_outfile = nullptr; int use_socket = 0; int use_control_socket = 0; int do_fb = 0; diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp index 9beff989df..77f09b7459 100644 --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@ -525,13 +525,13 @@ void do_dmesg() { if (PropertiesHelper::IsDryRun()) return; /* Get size of kernel buffer */ - int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0); + int size = klogctl(KLOG_SIZE_BUFFER, nullptr, 0); if (size <= 0) { printf("Unexpected klogctl return value: %d\n\n", size); return; } char *buf = (char *) malloc(size + 1); - if (buf == NULL) { + if (buf == nullptr) { printf("memory allocation failed\n\n"); return; } @@ -598,7 +598,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha DurationReporter duration_reporter(title); DIR *dirp; struct dirent *d; - char *newpath = NULL; + char *newpath = nullptr; const char *slash = "/"; int retval = 0; @@ -611,7 +611,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha ++slash; } dirp = opendir(dir); - if (dirp == NULL) { + if (dirp == nullptr) { retval = -errno; MYLOGE("%s: %s\n", dir, strerror(errno)); return retval; @@ -620,7 +620,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha if (!dump_from_fd) { dump_from_fd = dump_file_from_fd; } - for (; ((d = readdir(dirp))); free(newpath), newpath = NULL) { + for (; ((d = readdir(dirp))); free(newpath), newpath = nullptr) { if ((d->d_name[0] == '.') && (((d->d_name[1] == '.') && (d->d_name[2] == '\0')) || (d->d_name[1] == '\0'))) { @@ -648,7 +648,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha printf("*** %s: %s\n", newpath, strerror(errno)); continue; } - (*dump_from_fd)(NULL, newpath, fd.get()); + (*dump_from_fd)(nullptr, newpath, fd.get()); } closedir(dirp); if (!title.empty()) { diff --git a/cmds/flatland/GLHelper.cpp b/cmds/flatland/GLHelper.cpp index d5b3372f96..62d2fa1548 100644 --- a/cmds/flatland/GLHelper.cpp +++ b/cmds/flatland/GLHelper.cpp @@ -29,7 +29,7 @@ GLHelper::GLHelper() : mContext(EGL_NO_CONTEXT), mDummySurface(EGL_NO_SURFACE), mConfig(0), - mShaderPrograms(NULL), + mShaderPrograms(nullptr), mDitherTexture(0) { } @@ -101,12 +101,12 @@ bool GLHelper::setUp(const ShaderDesc* shaderDescs, size_t numShaders) { } void GLHelper::tearDown() { - if (mShaderPrograms != NULL) { + if (mShaderPrograms != nullptr) { delete[] mShaderPrograms; - mShaderPrograms = NULL; + mShaderPrograms = nullptr; } - if (mSurfaceComposerClient != NULL) { + if (mSurfaceComposerClient != nullptr) { mSurfaceComposerClient->dispose(); mSurfaceComposerClient.clear(); } @@ -210,7 +210,7 @@ bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, glc->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER); sp<ANativeWindow> anw = new Surface(producer); - EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), NULL); + EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), nullptr); if (s == EGL_NO_SURFACE) { fprintf(stderr, "eglCreateWindowSurface error: %#x\n", eglGetError()); return false; @@ -223,7 +223,7 @@ bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, bool GLHelper::computeWindowScale(uint32_t w, uint32_t h, float* scale) { sp<IBinder> dpy = mSurfaceComposerClient->getBuiltInDisplay(0); - if (dpy == NULL) { + if (dpy == nullptr) { fprintf(stderr, "SurfaceComposer::getBuiltInDisplay failed.\n"); return false; } @@ -247,7 +247,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h, bool result; status_t err; - if (mSurfaceComposerClient == NULL) { + if (mSurfaceComposerClient == nullptr) { mSurfaceComposerClient = new SurfaceComposerClient; } err = mSurfaceComposerClient->initCheck(); @@ -258,7 +258,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h, sp<SurfaceControl> sc = mSurfaceComposerClient->createSurface( String8("Benchmark"), w, h, PIXEL_FORMAT_RGBA_8888, 0); - if (sc == NULL || !sc->isValid()) { + if (sc == nullptr || !sc->isValid()) { fprintf(stderr, "Failed to create SurfaceControl.\n"); return false; } @@ -275,7 +275,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h, .apply(); sp<ANativeWindow> anw = sc->getSurface(); - EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), NULL); + EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), nullptr); if (s == EGL_NO_SURFACE) { fprintf(stderr, "eglCreateWindowSurface error: %#x\n", eglGetError()); return false; @@ -294,7 +294,7 @@ static bool compileShader(GLenum shaderType, const char* src, return false; } - glShaderSource(shader, 1, &src, NULL); + glShaderSource(shader, 1, &src, nullptr); glCompileShader(shader); GLint compiled = 0; @@ -305,7 +305,7 @@ static bool compileShader(GLenum shaderType, const char* src, if (infoLen) { char* buf = new char[infoLen]; if (buf) { - glGetShaderInfoLog(shader, infoLen, NULL, buf); + glGetShaderInfoLog(shader, infoLen, nullptr, buf); fprintf(stderr, "Shader compile log:\n%s\n", buf); delete[] buf; } @@ -318,21 +318,21 @@ static bool compileShader(GLenum shaderType, const char* src, } static void printShaderSource(const char* const* src) { - for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != NULL; i++) { + for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != nullptr; i++) { fprintf(stderr, "%3zu: %s\n", i+1, src[i]); } } static const char* makeShaderString(const char* const* src) { size_t len = 0; - for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != NULL; i++) { + for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != nullptr; i++) { // The +1 is for the '\n' that will be added. len += strlen(src[i]) + 1; } char* result = new char[len+1]; char* end = result; - for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != NULL; i++) { + for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != nullptr; i++) { strcpy(end, src[i]); end += strlen(src[i]); *end = '\n'; @@ -376,7 +376,7 @@ static bool linkShaderProgram(GLuint vs, GLuint fs, GLuint* outPgm) { if (bufLength) { char* buf = new char[bufLength]; if (buf) { - glGetProgramInfoLog(program, bufLength, NULL, buf); + glGetProgramInfoLog(program, bufLength, nullptr, buf); fprintf(stderr, "Program link log:\n%s\n", buf); delete[] buf; } diff --git a/cmds/flatland/Main.cpp b/cmds/flatland/Main.cpp index 3d7cac0bb3..7ceb397032 100644 --- a/cmds/flatland/Main.cpp +++ b/cmds/flatland/Main.cpp @@ -284,7 +284,7 @@ class Layer { public: Layer() : - mGLHelper(NULL), + mGLHelper(nullptr), mSurface(EGL_NO_SURFACE) { } @@ -316,23 +316,23 @@ public: } void tearDown() { - if (mComposer != NULL) { + if (mComposer != nullptr) { mComposer->tearDown(); delete mComposer; - mComposer = NULL; + mComposer = nullptr; } - if (mRenderer != NULL) { + if (mRenderer != nullptr) { mRenderer->tearDown(); delete mRenderer; - mRenderer = NULL; + mRenderer = nullptr; } if (mSurface != EGL_NO_SURFACE) { mGLHelper->destroySurface(&mSurface); mGLConsumer->abandon(); } - mGLHelper = NULL; + mGLHelper = nullptr; mGLConsumer.clear(); } @@ -377,7 +377,7 @@ public: mDesc(desc), mInstance(instance), mNumLayers(countLayers(desc)), - mGLHelper(NULL), + mGLHelper(nullptr), mSurface(EGL_NO_SURFACE), mWindowSurface(EGL_NO_SURFACE) { } @@ -443,7 +443,7 @@ public: mLayers[i].tearDown(); } - if (mGLHelper != NULL) { + if (mGLHelper != nullptr) { if (mWindowSurface != EGL_NO_SURFACE) { mGLHelper->destroySurface(&mWindowSurface); } @@ -453,7 +453,7 @@ public: mSurfaceControl.clear(); mGLHelper->tearDown(); delete mGLHelper; - mGLHelper = NULL; + mGLHelper = nullptr; } } @@ -553,7 +553,7 @@ private: static size_t countLayers(const BenchmarkDesc& desc) { size_t i; for (i = 0; i < MAX_NUM_LAYERS; i++) { - if (desc.layers[i].rendererFactory == NULL) { + if (desc.layers[i].rendererFactory == nullptr) { break; } } diff --git a/cmds/lshal/ListCommand.cpp b/cmds/lshal/ListCommand.cpp index 09eeaa8851..8d5f0d2e7c 100644 --- a/cmds/lshal/ListCommand.cpp +++ b/cmds/lshal/ListCommand.cpp @@ -1073,9 +1073,9 @@ static std::unique_ptr<struct option[]> getLongOptions( i++; } // getopt_long last option has all zeros - ret[i].name = NULL; + ret[i].name = nullptr; ret[i].has_arg = 0; - ret[i].flag = NULL; + ret[i].flag = nullptr; ret[i].val = 0; return ret; diff --git a/cmds/lshal/PipeRelay.cpp b/cmds/lshal/PipeRelay.cpp index 3828bbf27f..87d75ac2d4 100644 --- a/cmds/lshal/PipeRelay.cpp +++ b/cmds/lshal/PipeRelay.cpp @@ -78,7 +78,7 @@ void PipeRelay::CloseFd(int *fd) { PipeRelay::~PipeRelay() { CloseFd(&mFds[1]); - if (mThread != NULL) { + if (mThread != nullptr) { mThread->join(); mThread.clear(); } diff --git a/cmds/lshal/Timeout.h b/cmds/lshal/Timeout.h index c940404200..58119a6fcf 100644 --- a/cmds/lshal/Timeout.h +++ b/cmds/lshal/Timeout.h @@ -57,7 +57,7 @@ void *callAndNotify(void *data) { BackgroundTaskState &state = *static_cast<BackgroundTaskState *>(data); state(); state.notify(); - return NULL; + return nullptr; } template<class R, class P> @@ -65,7 +65,7 @@ bool timeout(std::chrono::duration<R, P> delay, std::function<void(void)> &&func auto now = std::chrono::system_clock::now(); BackgroundTaskState state{std::forward<decltype(func)>(func)}; pthread_t thread; - if (pthread_create(&thread, NULL, callAndNotify, &state)) { + if (pthread_create(&thread, nullptr, callAndNotify, &state)) { std::cerr << "FATAL: could not create background thread." << std::endl; return false; } @@ -73,7 +73,7 @@ bool timeout(std::chrono::duration<R, P> delay, std::function<void(void)> &&func if (!success) { pthread_kill(thread, SIGINT); } - pthread_join(thread, NULL); + pthread_join(thread, nullptr); return success; } diff --git a/cmds/rawbu/backup.cpp b/cmds/rawbu/backup.cpp index 0072281d4d..8b20e3e5ff 100644 --- a/cmds/rawbu/backup.cpp +++ b/cmds/rawbu/backup.cpp @@ -38,7 +38,7 @@ static char nameBuffer[PATH_MAX]; static struct stat statBuffer; static char copyBuffer[8192]; -static char *backupFilePath = NULL; +static char *backupFilePath = nullptr; static uint32_t inputFileVersion; @@ -58,7 +58,7 @@ static const struct special_dir SKIP_PATHS[] = { { "/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 @@ static int wipe (const char *path) 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 @@ static int wipe (const char *path) for (;;) { de = readdir(dir); - if (de == NULL) { + if (de == nullptr) { break; } @@ -115,7 +115,7 @@ static int wipe (const char *path) } } - 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 @@ static int copy_file(FILE* dest, FILE* src, off_t size, const char* destName, 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 @@ static int copy_file(FILE* dest, FILE* src, off_t size, const char* destName, } 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 @@ static int backup_dir(FILE* fh, const char* srcPath) { 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 @@ static int backup_dir(FILE* fh, const char* srcPath) for (;;) { de = readdir(dir); - if (de == NULL) { + if (de == nullptr) { break; } @@ -283,7 +283,7 @@ static int backup_dir(FILE* fh, const char* srcPath) continue; } - if (fullPath != NULL) { + if (fullPath != nullptr) { free(fullPath); } fullPath = (char*)malloc(srcLen + strlen(de->d_name) + 2); @@ -298,7 +298,7 @@ static int backup_dir(FILE* fh, const char* srcPath) break; } } - if (SKIP_PATHS[i].path != NULL) { + if (SKIP_PATHS[i].path != nullptr) { continue; } } @@ -343,14 +343,14 @@ static int backup_dir(FILE* fh, const char* srcPath) } 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 @@ static int backup_dir(FILE* fh, const char* srcPath) } done: - if (fullPath != NULL) { + if (fullPath != nullptr) { free(fullPath); } @@ -374,7 +374,7 @@ static int backup_data(const char* destPath) 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 @@ static int restore_data(const char* srcPath) 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 @@ static int restore_data(const char* srcPath) while (1) { int type; - char* path = NULL; + char* path = nullptr; if (read_header(fh, &type, &path, &statBuffer) == 0) { goto done; } @@ -570,14 +570,14 @@ static int restore_data(const char* srcPath) 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); diff --git a/cmds/service/service.cpp b/cmds/service/service.cpp index bc11256a73..34a3fdc420 100644 --- a/cmds/service/service.cpp +++ b/cmds/service/service.cpp @@ -30,7 +30,7 @@ using namespace android; void writeString16(Parcel& parcel, const char* string) { - if (string != NULL) + if (string != nullptr) { parcel.writeString16(String16(string)); } @@ -43,7 +43,7 @@ void writeString16(Parcel& parcel, const char* string) // get the name of the generic interface we hold a reference to static String16 get_interface_name(sp<IBinder> service) { - if (service != NULL) { + if (service != nullptr) { Parcel data, reply; status_t err = service->transact(IBinder::INTERFACE_TRANSACTION, data, &reply); if (err == NO_ERROR) { @@ -93,7 +93,7 @@ int main(int argc, char* const argv[]) #endif sp<IServiceManager> sm = defaultServiceManager(); fflush(stdout); - if (sm == NULL) { + if (sm == nullptr) { aerr << "service: Unable to get default service manager!" << endl; return 20; } @@ -106,7 +106,7 @@ int main(int argc, char* const argv[]) if (optind < argc) { sp<IBinder> service = sm->checkService(String16(argv[optind])); aout << "Service " << argv[optind] << - (service == NULL ? ": not found" : ": found") << endl; + (service == nullptr ? ": not found" : ": found") << endl; } else { aerr << "service: No service specified for check" << endl; wantsUsage = true; @@ -131,7 +131,7 @@ int main(int argc, char* const argv[]) sp<IBinder> service = sm->checkService(String16(argv[optind++])); String16 ifName = get_interface_name(service); int32_t code = atoi(argv[optind++]); - if (service != NULL && ifName.size() > 0) { + if (service != nullptr && ifName.size() > 0) { Parcel data, reply; // the interface name is first @@ -186,28 +186,28 @@ int main(int argc, char* const argv[]) data.writeDouble(atof(argv[optind++])); } else if (strcmp(argv[optind], "null") == 0) { optind++; - data.writeStrongBinder(NULL); + data.writeStrongBinder(nullptr); } else if (strcmp(argv[optind], "intent") == 0) { - char* action = NULL; - char* dataArg = NULL; - char* type = NULL; + char* action = nullptr; + char* dataArg = nullptr; + char* type = nullptr; int launchFlags = 0; - char* component = NULL; + char* component = nullptr; int categoryCount = 0; char* categories[16]; - char* context1 = NULL; + char* context1 = nullptr; optind++; while (optind < argc) { char* key = strtok_r(argv[optind], "=", &context1); - char* value = strtok_r(NULL, "=", &context1); + char* value = strtok_r(nullptr, "=", &context1); // we have reached the end of the XXX=XXX args. - if (key == NULL) break; + if (key == nullptr) break; if (strcmp(key, "action") == 0) { @@ -231,14 +231,14 @@ int main(int argc, char* const argv[]) } else if (strcmp(key, "categories") == 0) { - char* context2 = NULL; + char* context2 = nullptr; int categoryCount = 0; categories[categoryCount] = strtok_r(value, ",", &context2); - while (categories[categoryCount] != NULL) + while (categories[categoryCount] != nullptr) { categoryCount++; - categories[categoryCount] = strtok_r(NULL, ",", &context2); + categories[categoryCount] = strtok_r(nullptr, ",", &context2); } } diff --git a/cmds/surfacereplayer/replayer/Main.cpp b/cmds/surfacereplayer/replayer/Main.cpp index 7090bdb503..fbfcacf1aa 100644 --- a/cmds/surfacereplayer/replayer/Main.cpp +++ b/cmds/surfacereplayer/replayer/Main.cpp @@ -94,7 +94,7 @@ int main(int argc, char** argv) { } char** input = argv + optind; - if (input[0] == NULL) { + if (input[0] == nullptr) { std::cerr << "No trace file provided...exiting" << std::endl; abort(); } |