From 8c7c882b90646f7647e124586345eb9bad58ac59 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 12 Oct 2015 15:50:58 -0400 Subject: [PATCH] C++11: Made use of nullptr --- src/FS.cpp | 28 ++++++++++++++-------------- src/text.cpp | 2 +- src/utf8.cpp | 2 +- src/util.cpp | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/FS.cpp b/src/FS.cpp index 1d79aa7..fb39977 100644 --- a/src/FS.cpp +++ b/src/FS.cpp @@ -25,6 +25,7 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -40,7 +41,6 @@ #include #include #include -#include #if defined SOLARIS || defined NETBSD || defined FREEBSD #include @@ -246,7 +246,7 @@ std::string Path::expand (const std::string& in) if (tilde != std::string::npos) { const char *home = getenv("HOME"); - if (home == NULL) + if (home == nullptr) { struct passwd* pw = getpwuid (getuid ()); home = pw->pw_dir; @@ -296,9 +296,9 @@ std::vector Path::glob (const std::string& pattern) glob_t g; #ifdef SOLARIS - if (!::glob (pattern.c_str (), GLOB_ERR, NULL, &g)) + if (!::glob (pattern.c_str (), GLOB_ERR, nullptr, &g)) #else - if (!::glob (pattern.c_str (), GLOB_ERR | GLOB_BRACE | GLOB_TILDE, NULL, &g)) + if (!::glob (pattern.c_str (), GLOB_ERR | GLOB_BRACE | GLOB_TILDE, nullptr, &g)) #endif for (int i = 0; i < (int) g.gl_pathc; ++i) results.push_back (g.gl_pathv[i]); @@ -310,7 +310,7 @@ std::vector Path::glob (const std::string& pattern) //////////////////////////////////////////////////////////////////////////////// File::File () : Path::Path () -, _fh (NULL) +, _fh (nullptr) , _h (-1) , _locked (false) { @@ -319,7 +319,7 @@ File::File () //////////////////////////////////////////////////////////////////////////////// File::File (const Path& other) : Path::Path (other) -, _fh (NULL) +, _fh (nullptr) , _h (-1) , _locked (false) { @@ -328,7 +328,7 @@ File::File (const Path& other) //////////////////////////////////////////////////////////////////////////////// File::File (const File& other) : Path::Path (other) -, _fh (NULL) +, _fh (nullptr) , _h (-1) , _locked (false) { @@ -337,7 +337,7 @@ File::File (const File& other) //////////////////////////////////////////////////////////////////////////////// File::File (const std::string& in) : Path::Path (in) -, _fh (NULL) +, _fh (nullptr) , _h (-1) , _locked (false) { @@ -421,7 +421,7 @@ void File::close () unlock (); fclose (_fh); - _fh = NULL; + _fh = nullptr; _h = -1; _locked = false; } @@ -848,10 +848,10 @@ bool Directory::remove () const bool Directory::remove_directory (const std::string& dir) const { DIR* dp = opendir (dir.c_str ()); - if (dp != NULL) + if (dp != nullptr) { struct dirent* de; - while ((de = readdir (dp)) != NULL) + while ((de = readdir (dp)) != nullptr) { if (!strcmp (de->d_name, ".") || !strcmp (de->d_name, "..")) @@ -906,7 +906,7 @@ std::string Directory::cwd () { #ifdef HAVE_GET_CURRENT_DIR_NAME char *buf = get_current_dir_name (); - if (buf == NULL) + if (buf == nullptr) throw std::bad_alloc (); std::string result (buf); free (buf); @@ -952,10 +952,10 @@ void Directory::list ( bool recursive) { DIR* dp = opendir (base.c_str ()); - if (dp != NULL) + if (dp != nullptr) { struct dirent* de; - while ((de = readdir (dp)) != NULL) + while ((de = readdir (dp)) != nullptr) { if (!strcmp (de->d_name, ".") || !strcmp (de->d_name, "..")) diff --git a/src/text.cpp b/src/text.cpp index 5673a10..a7bb68c 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -25,13 +25,13 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include #include #include #include #include #include -#include static void replace_positional (std::string&, const std::string&, const std::string&); diff --git a/src/utf8.cpp b/src/utf8.cpp index c2a5bac..026c4f9 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -25,8 +25,8 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include #include +#include //////////////////////////////////////////////////////////////////////////////// // Converts '0' -> 0 diff --git a/src/util.cpp b/src/util.cpp index 6507982..7e3da9d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -92,7 +92,7 @@ int execute ( for (unsigned int i = 0; i < args.size (); ++i) argv[i+1] = (char*) args[i].c_str (); - argv[args.size () + 1] = NULL; + argv[args.size () + 1] = nullptr; _exit (execvp (executable.c_str (), argv)); } @@ -126,7 +126,7 @@ int execute ( tv.tv_sec = 5; tv.tv_usec = 0; - select_retval = select (std::max (pout[0], pin[1]) + 1, &rfds, &wfds, NULL, &tv); + select_retval = select (std::max (pout[0], pin[1]) + 1, &rfds, &wfds, nullptr, &tv); if (select_retval == -1) throw std::string (std::strerror (errno));