diff options
author | Richard Kettlewell <rjk@greenend.org.uk> | 2015-11-07 15:52:20 +0000 |
---|---|---|
committer | Richard Kettlewell <rjk@greenend.org.uk> | 2015-11-07 15:52:20 +0000 |
commit | c4e1f5762e604ef37c0523ceb876a135f1377e2b (patch) | |
tree | 3519cba26953f8a8ace6ac189317d1f1ff9e6267 /src | |
parent | 7eb6a36cb8888bc649cb03633846f049e1480510 (diff) |
Adopt use of nullptr
Modern C++ practice.
Diffstat (limited to 'src')
-rw-r--r-- | src/Command.cc | 66 | ||||
-rw-r--r-- | src/Command.h | 6 | ||||
-rw-r--r-- | src/Conf.cc | 30 | ||||
-rw-r--r-- | src/Conf.h | 35 | ||||
-rw-r--r-- | src/Database.cc | 10 | ||||
-rw-r--r-- | src/Database.h | 4 | ||||
-rw-r--r-- | src/Date.cc | 2 | ||||
-rw-r--r-- | src/Directory.cc | 2 | ||||
-rw-r--r-- | src/Document.cc | 2 | ||||
-rw-r--r-- | src/Document.h | 2 | ||||
-rw-r--r-- | src/EventLoop.cc | 14 | ||||
-rw-r--r-- | src/HTML.cc | 30 | ||||
-rw-r--r-- | src/Host.cc | 4 | ||||
-rw-r--r-- | src/IO.cc | 2 | ||||
-rw-r--r-- | src/IO.h | 12 | ||||
-rw-r--r-- | src/MakeBackup.cc | 6 | ||||
-rw-r--r-- | src/Report.cc | 4 | ||||
-rw-r--r-- | src/RetireVolumes.cc | 2 | ||||
-rw-r--r-- | src/Store.cc | 2 | ||||
-rw-r--r-- | src/Store.h | 6 | ||||
-rw-r--r-- | src/Subprocess.cc | 14 | ||||
-rw-r--r-- | src/Unicode.cc | 2 | ||||
-rw-r--r-- | src/Volume.cc | 12 | ||||
-rw-r--r-- | src/rsbackup.cc | 2 | ||||
-rw-r--r-- | src/test-check.cc | 16 | ||||
-rw-r--r-- | src/test-command.cc | 50 |
26 files changed, 169 insertions, 168 deletions
diff --git a/src/Command.cc b/src/Command.cc index f031d8e..17ecb4d 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -37,35 +37,35 @@ enum { }; const struct option Command::options[] = { - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'V' }, - { "backup", no_argument, 0, 'b' }, - { "html", required_argument, 0, 'H' }, - { "text", required_argument, 0, 'T' }, - { "email", required_argument, 0, 'e' }, - { "prune", no_argument, 0, 'p' }, - { "prune-incomplete", no_argument, 0, 'P' }, - { "store", required_argument, 0, 's' }, - { "retire-device", no_argument, 0, RETIRE_DEVICE }, - { "retire", no_argument, 0, RETIRE }, - { "config", required_argument, 0, 'c' }, - { "wait", no_argument, 0, 'w' }, - { "force", no_argument, 0, 'f' }, - { "dry-run", no_argument, 0, 'n' }, - { "verbose", no_argument, 0, 'v' }, - { "warn-unknown", no_argument, 0, WARN_UNKNOWN }, - { "warn-store", no_argument, 0, WARN_STORE }, - { "warn-unreachable", no_argument, 0, WARN_UNREACHABLE }, - { "warn-partial", no_argument, 0, WARN_PARTIAL }, - { "no-warn-partial", no_argument, 0, NO_WARN_PARTIAL }, - { "errors", no_argument, 0, REPEAT_ERRORS }, - { "no-errors", no_argument, 0, NO_REPEAT_ERRORS }, - { "warn-all", no_argument, 0, 'W' }, - { "debug", no_argument, 0, 'd' }, - { "logs", required_argument, 0, LOG_VERBOSITY }, - { "dump-config", no_argument, 0, DUMP_CONFIG }, - { "database", required_argument, 0, 'D' }, - { 0, 0, 0, 0 } + { "help", no_argument, nullptr, 'h' }, + { "version", no_argument, nullptr, 'V' }, + { "backup", no_argument, nullptr, 'b' }, + { "html", required_argument, nullptr, 'H' }, + { "text", required_argument, nullptr, 'T' }, + { "email", required_argument, nullptr, 'e' }, + { "prune", no_argument, nullptr, 'p' }, + { "prune-incomplete", no_argument, nullptr, 'P' }, + { "store", required_argument, nullptr, 's' }, + { "retire-device", no_argument, nullptr, RETIRE_DEVICE }, + { "retire", no_argument, nullptr, RETIRE }, + { "config", required_argument, nullptr, 'c' }, + { "wait", no_argument, nullptr, 'w' }, + { "force", no_argument, nullptr, 'f' }, + { "dry-run", no_argument, nullptr, 'n' }, + { "verbose", no_argument, nullptr, 'v' }, + { "warn-unknown", no_argument, nullptr, WARN_UNKNOWN }, + { "warn-store", no_argument, nullptr, WARN_STORE }, + { "warn-unreachable", no_argument, nullptr, WARN_UNREACHABLE }, + { "warn-partial", no_argument, nullptr, WARN_PARTIAL }, + { "no-warn-partial", no_argument, nullptr, NO_WARN_PARTIAL }, + { "errors", no_argument, nullptr, REPEAT_ERRORS }, + { "no-errors", no_argument, nullptr, NO_REPEAT_ERRORS }, + { "warn-all", no_argument, nullptr, 'W' }, + { "debug", no_argument, nullptr, 'd' }, + { "logs", required_argument, nullptr, LOG_VERBOSITY }, + { "dump-config", no_argument, nullptr, DUMP_CONFIG }, + { "database", required_argument, nullptr, 'D' }, + { nullptr, 0, nullptr, 0 } }; Command::Command(): backup(false), @@ -74,9 +74,9 @@ Command::Command(): backup(false), retire(false), retireDevice(false), dumpConfig(false), - html(NULL), - text(NULL), - email(NULL), + html(nullptr), + text(nullptr), + email(nullptr), configPath(DEFAULT_CONFIG), wait(false), act(true), @@ -156,7 +156,7 @@ void Command::parse(int argc, const char *const *argv) { // Parse options optind = 1; while((n = getopt_long(argc, (char *const *)argv, - "+hVbH:T:e:pPs:c:wnfvdWD:", options, 0)) >= 0) { + "+hVbH:T:e:pPs:c:wnfvdWD:", options, nullptr)) >= 0) { switch(n) { case 'h': help(); case 'V': version(); diff --git a/src/Command.h b/src/Command.h index 79da9f3..34f9c8e 100644 --- a/src/Command.h +++ b/src/Command.h @@ -91,13 +91,13 @@ public: /** @brief @c --dump-config action */ bool dumpConfig; - /** @brief Output file for HTML report or @c NULL */ + /** @brief Output file for HTML report or null pointer */ std::string *html; - /** @brief Output file for text report or @c NULL */ + /** @brief Output file for text report or null pointer */ std::string *text; - /** @brief Address for email report or @c NULL */ + /** @brief Address for email report or null pointer */ std::string *email; /** @brief Explicitly specified stores */ diff --git a/src/Conf.cc b/src/Conf.cc index 565ae76..dee69e6 100644 --- a/src/Conf.cc +++ b/src/Conf.cc @@ -37,7 +37,7 @@ struct ConfContext { * @param conf_ Root configuration node */ ConfContext(Conf *conf_): - conf(conf_), context(conf_), host(NULL), volume(NULL) {} + conf(conf_), context(conf_), host(nullptr), volume(nullptr) {} /** @brief Root of configuration */ Conf *conf; @@ -124,7 +124,7 @@ struct HostOnlyDirective: public Directive { HostOnlyDirective(const char *name_, int min_=0, int max_=INT_MAX): Directive(name_, min_, max_) {} virtual void check(const ConfContext &cc) const { - if(cc.host == NULL) + if(cc.host == nullptr) throw SyntaxError("'" + name + "' command without 'host'"); Directive::check(cc); } @@ -141,7 +141,7 @@ struct VolumeOnlyDirective: public Directive { VolumeOnlyDirective(const char *name_, int min_=0, int max_=INT_MAX): Directive(name_, min_, max_) {} virtual void check(const ConfContext &cc) const { - if(cc.volume == NULL) + if(cc.volume == nullptr) throw SyntaxError("'" + name + "' command without 'volume'"); Directive::check(cc); } @@ -397,7 +397,7 @@ static const struct HostDirective: public Directive { if(cc.conf->hosts.find(cc.bits[1]) != cc.conf->hosts.end()) throw SyntaxError("duplicate host"); cc.context = cc.host = new Host(cc.conf, cc.bits[1]); - cc.volume = NULL; + cc.volume = nullptr; cc.host->hostname = cc.bits[1]; } } host_directive; @@ -641,20 +641,20 @@ void Conf::addHost(Host *h) { // Find a host by name Host *Conf::findHost(const std::string &hostName) const { auto it = hosts.find(hostName); - return it != hosts.end() ? it->second : NULL; + return it != hosts.end() ? it->second : nullptr; } // Find a volume by name Volume *Conf::findVolume(const std::string &hostName, const std::string &volumeName) const { Host *host = findHost(hostName); - return host ? host->findVolume(volumeName) : NULL; + return host ? host->findVolume(volumeName) : nullptr; } // Find a device by name Device *Conf::findDevice(const std::string &deviceName) const { auto it = devices.find(deviceName); - return it != devices.end() ? it->second : NULL; + return it != devices.end() ? it->second : nullptr; } // Read in logfiles @@ -714,7 +714,7 @@ void Conf::readState() { // Skip empty files if(contents.size() == 0) { if(progress) - progressBar(IO::err, NULL, 0, 0); + progressBar(IO::err, nullptr, 0, 0); warning("empty file: %s", files[n].c_str()); continue; } @@ -743,7 +743,7 @@ void Conf::readState() { if(command.act) { // addBackup might fail to set volume - if(backup.volume != NULL) { + if(backup.volume != nullptr) { if(upgraded.size() == 0) getdb()->begin(); try { @@ -755,7 +755,7 @@ void Conf::readState() { upgraded.push_back(files[n]); } else { if(progress) - progressBar(IO::err, NULL, 0, 0); + progressBar(IO::err, nullptr, 0, 0); warning("cannot upgrade %s", files[n].c_str()); } } @@ -775,7 +775,7 @@ void Conf::readState() { throw SystemError("could not remove old logfiles"); } if(progress) - progressBar(IO::err, NULL, 0, 0); + progressBar(IO::err, nullptr, 0, 0); } void Conf::addBackup(Backup &backup, @@ -792,7 +792,7 @@ void Conf::addBackup(Backup &backup, if(unknownDevices.find(backup.deviceName) == unknownDevices.end()) { if(command.warnUnknown || forceWarn) { if(progress) - progressBar(IO::err, NULL, 0, 0); + progressBar(IO::err, nullptr, 0, 0); warning("unknown device %s", backup.deviceName.c_str()); } unknownDevices.insert(backup.deviceName); @@ -807,7 +807,7 @@ void Conf::addBackup(Backup &backup, if(unknownHosts.find(hostName) == unknownHosts.end()) { if(command.warnUnknown || forceWarn) { if(progress) - progressBar(IO::err, NULL, 0, 0); + progressBar(IO::err, nullptr, 0, 0); warning("unknown host %s", hostName.c_str()); } unknownHosts.insert(hostName); @@ -820,7 +820,7 @@ void Conf::addBackup(Backup &backup, if(host->unknownVolumes.find(volumeName) == host->unknownVolumes.end()) { if(command.warnUnknown || forceWarn) { if(progress) - progressBar(IO::err, NULL, 0, 0); + progressBar(IO::err, nullptr, 0, 0); warning("unknown volume %s:%s", hostName.c_str(), volumeName.c_str()); } @@ -910,7 +910,7 @@ void Conf::createTables() { } ConfBase *Conf::getParent() const { - return NULL; + return nullptr; } // Regexp for parsing log filenames @@ -109,7 +109,7 @@ public: virtual void write(std::ostream &os, int step = 0) const; /** @brief Return the parent of this configuration node - * @return Parent node or NULL + * @return Parent node or null pointer */ virtual ConfBase *getParent() const = 0; @@ -172,7 +172,7 @@ public: unknownObjects(0), logsRead(false), devicesIdentified(false), - db(NULL) { } + db(nullptr) { } /** @brief Map of host names to configuration */ hosts_type hosts; @@ -258,21 +258,21 @@ public: /** @brief Find a host by name * @param hostName Host to find - * @return Host, or NULL + * @return Host, or null pointer */ Host *findHost(const std::string &hostName) const; /** @brief Find a volume by name * @param hostName Name of host containing volume * @param volumeName Name of volume to find - * @return Volume, or NULL + * @return Volume, or null pointer */ Volume *findVolume(const std::string &hostName, const std::string &volumeName) const; /** @brief Find a device by name * @param deviceName Name of device to find - * @return Device, or NULL + * @return Device, or null pointer */ Device *findDevice(const std::string &deviceName) const; @@ -401,12 +401,12 @@ public: /** @brief Constructor * @param name_ Name of device */ - Device(const std::string &name_): name(name_), store(NULL) {} + Device(const std::string &name_): name(name_), store(nullptr) {} /** @brief Name of device */ std::string name; - /** @brief Store for this device, or NULL + /** @brief Store for this device, or null pointer * * Set by Store::identify(). */ @@ -485,7 +485,7 @@ public: /** @brief Find a volume by name * @param volumeName Name of volume to find - * @return Volume or NULL + * @return Volume or null pointer */ Volume *findVolume(const std::string &volumeName) const; @@ -511,7 +511,7 @@ public: static bool valid(const std::string &n); /** @brief Invoke a command on the host and return its exit status - * @param capture Where to put capture stdout, or NULL + * @param capture Where to put capture stdout, or null pointer * @param cmd Command to invoke * @param ... Arguments to command, terminatd by a null pointer * @return Exit status @@ -603,7 +603,7 @@ public: /** @brief Return containing device * - * TODO could this be NULL if device has been retired? + * TODO could this be null pointer if device has been retired? */ Device *getDevice() const; @@ -625,7 +625,8 @@ public: void remove(Database *db) const; /** @brief Constructor */ - inline Backup(): status(UNKNOWN), rc(0), time(0), pruned(0), volume(NULL) {} + inline Backup(): status(UNKNOWN), rc(0), time(0), pruned(0), volume(nullptr) { + } /** @brief Retrieve status of this backup */ inline int getStatus() const { @@ -755,16 +756,16 @@ public: bool removeBackup(const Backup *backup); /** @brief Find the most recent backup - * @param device If not NULL, only consider backups from this device - * @return Most recent backup or NULL + * @param device If not null pointer, only consider backups from this device + * @return Most recent backup or null pointer */ - const Backup *mostRecentBackup(const Device *device = NULL) const; + const Backup *mostRecentBackup(const Device *device = nullptr) const; /** @brief Find the most recent failedbackup - * @param device If not NULL, only consider backups from this device - * @return Most recent failed backup or NULL + * @param device If not null pointer, only consider backups from this device + * @return Most recent failed backup or null pointer */ - const Backup *mostRecentFailedBackup(const Device *device = NULL) const; + const Backup *mostRecentFailedBackup(const Device *device = nullptr) const; virtual ConfBase *getParent() const; diff --git a/src/Database.cc b/src/Database.cc index f0328f7..bf9d6f1 100644 --- a/src/Database.cc +++ b/src/Database.cc @@ -23,7 +23,7 @@ Database::Database(const std::string &path, bool rw) { &db, rw ? SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE : SQLITE_OPEN_READONLY, - NULL); + nullptr); if(rc != SQLITE_OK) error("sqlite3_open_v2 " + path, rc); } @@ -69,7 +69,7 @@ void Database::rollback() { Database::~Database() { // Really want sqlite3_close_v2 but not available in wheezy int rc = sqlite3_close(db); - db = NULL; + db = nullptr; if(rc != SQLITE_OK) error("sqlite3_close", rc); } @@ -77,7 +77,7 @@ Database::~Database() { // Database::Statement -------------------------------------------------------- Database::Statement::Statement(Database *d, const char *cmd, ...): - stmt(NULL), db(d->db), param(0) { + stmt(nullptr), db(d->db), param(0) { va_list ap; va_start(ap, cmd); try { @@ -90,7 +90,7 @@ Database::Statement::Statement(Database *d, const char *cmd, ...): } Database::Statement::Statement(Database &d, const char *cmd, ...): - stmt(NULL), db(d.db), param(0) { + stmt(nullptr), db(d.db), param(0) { va_list ap; va_start(ap, cmd); try { @@ -129,7 +129,7 @@ void Database::Statement::vprepare(const char *cmd, va_list ap) { vbind(ap); } catch(std::runtime_error &e) { sqlite3_finalize(stmt); - stmt = NULL; + stmt = nullptr; throw; } } diff --git a/src/Database.h b/src/Database.h index 073ef84..e0e2100 100644 --- a/src/Database.h +++ b/src/Database.h @@ -51,13 +51,13 @@ public: * @param d Database * @throw DatabaseError if an error occurs */ - inline Statement(Database *d): stmt(NULL), db(d->db), param(0) {} + inline Statement(Database *d): stmt(nullptr), db(d->db), param(0) {} /** @brief Create a statement * @param d Database * @throw DatabaseError if an error occurs */ - inline Statement(Database &d): stmt(NULL), db(d.db), param(0) {} + inline Statement(Database &d): stmt(nullptr), db(d.db), param(0) {} /** @brief Create a statement, prepare it with a command and bind data it * @param d Database diff --git a/src/Date.cc b/src/Date.cc index f482339..a3f53e3 100644 --- a/src/Date.cc +++ b/src/Date.cc @@ -130,7 +130,7 @@ time_t Date::now() { const char *override = getenv("RSBACKUP_TODAY"); if(override) return Date(override).toTime(); - return time(NULL); + return time(nullptr); } int Date::monthLength(int y, int m) { diff --git a/src/Directory.cc b/src/Directory.cc index e0df6a0..ce962cf 100644 --- a/src/Directory.cc +++ b/src/Directory.cc @@ -35,7 +35,7 @@ void Directory::close() { if(!dp) throw std::logic_error("Directory::close on closed directory"); closedir(dp); - dp = NULL; + dp = nullptr; path.clear(); } diff --git a/src/Document.cc b/src/Document.cc index a943625..c838d55 100644 --- a/src/Document.cc +++ b/src/Document.cc @@ -93,6 +93,6 @@ Document::Cell *Document::Table::occupied(int x, int y) const { && y >= cell->y && y < cell->y + cell->h) return cell; } - return NULL; + return nullptr; } diff --git a/src/Document.h b/src/Document.h index b2d6cf3..f278152 100644 --- a/src/Document.h +++ b/src/Document.h @@ -428,7 +428,7 @@ public: /** @brief Find the cell at a position * @param x X position * @param y Y position - * @return @p cell or NULL + * @return @p cell or null pointer */ Cell *occupied(int x, int y) const; diff --git a/src/EventLoop.cc b/src/EventLoop.cc index c8c5607..f6e3a44 100644 --- a/src/EventLoop.cc +++ b/src/EventLoop.cc @@ -53,12 +53,12 @@ EventLoop::EventLoop() { sigset_t ss; sigemptyset(&ss); sigaddset(&ss, SIGCHLD); - if(sigprocmask(SIG_BLOCK, &ss, NULL) < 0) + if(sigprocmask(SIG_BLOCK, &ss, nullptr) < 0) throw SystemError("sigprocmask", errno); sa.sa_handler = EventLoop::signalled; sigfillset(&sa.sa_mask); sa.sa_flags = SA_RESTART; - if(sigaction(SIGCHLD, &sa, NULL) < 0) + if(sigaction(SIGCHLD, &sa, nullptr) < 0) throw SystemError("sigaction", errno); if(pipe(sigpipe) < 0) throw SystemError("pipe", errno); @@ -72,7 +72,7 @@ EventLoop::~EventLoop() { signal(SIGCHLD, SIG_DFL); sigemptyset(&ss); sigaddset(&ss, SIGCHLD); - if(sigprocmask(SIG_UNBLOCK, &ss, NULL) < 0) + if(sigprocmask(SIG_UNBLOCK, &ss, nullptr) < 0) throw SystemError("sigprocmask", errno); close(sigpipe[0]); close(sigpipe[1]); @@ -120,7 +120,7 @@ void EventLoop::whenWaited(pid_t pid, Reactor *r) { void EventLoop::wait() { sigset_t ss; - if(sigprocmask(SIG_SETMASK, NULL, &ss) < 0) + if(sigprocmask(SIG_SETMASK, nullptr, &ss) < 0) throw SystemError("sigprocmask", errno); sigdelset(&ss, SIGCHLD); while(readers.size() > 1 || writers.size() > 0 || waiters.size() > 0) { @@ -142,7 +142,7 @@ void EventLoop::wait() { ts.tv_sec = 10; tsp = &ts; } else - tsp = NULL; + tsp = nullptr; FD_ZERO(&rfds); FD_ZERO(&wfds); for(auto it = readers.begin(); it != readers.end(); ++it) { @@ -153,7 +153,7 @@ void EventLoop::wait() { FD_SET(it->first, &wfds); maxfd = std::max(maxfd, it->first); } - n = pselect(maxfd + 1, &rfds, &wfds, NULL, tsp, &ss); + n = pselect(maxfd + 1, &rfds, &wfds, nullptr, tsp, &ss); if(n < 0) { if(errno != EINTR) throw IOError("pselect", errno); @@ -211,7 +211,7 @@ void EventLoop::getTimestamp(struct timespec &now) { throw IOError("clock_gettime", errno); #else struct timeval tv; - if(gettimeofday(&tv, NULL) < 0) + if(gettimeofday(&tv, nullptr) < 0) throw IOError("gettimeofday", errno); now.tv_sec = tv.tv_sec; now.tv_nsec = tv.tv_sec * 1000; diff --git a/src/HTML.cc b/src/HTML.cc index ac9161f..725747a 100644 --- a/src/HTML.cc +++ b/src/HTML.cc @@ -90,27 +90,27 @@ void Document::String::renderHtml(std::ostream &os) const { } void Document::LinearContainer::renderHtml(std::ostream &os) const { - renderHtmlOpenTag(os, "div", (char *)0); + renderHtmlOpenTag(os, "div", (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, "div"); } void Document::Paragraph::renderHtml(std::ostream &os) const { - renderHtmlOpenTag(os, "p", (char *)0); + renderHtmlOpenTag(os, "p", (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, "p"); } void Document::Verbatim::renderHtml(std::ostream &os) const { - renderHtmlOpenTag(os, "pre", (char *)0); + renderHtmlOpenTag(os, "pre", (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, "pre"); } void Document::List::renderHtml(std::ostream &os) const { switch(type) { - case OrderedList: renderHtmlOpenTag(os, "ol", (char *)0); break; - case UnorderedList: renderHtmlOpenTag(os, "ul", (char *)0); break; + case OrderedList: renderHtmlOpenTag(os, "ol", (char *)nullptr); break; + case UnorderedList: renderHtmlOpenTag(os, "ul", (char *)nullptr); break; } renderHtmlContents(os); switch(type) { @@ -120,7 +120,7 @@ void Document::List::renderHtml(std::ostream &os) const { } void Document::ListEntry::renderHtml(std::ostream &os) const { - renderHtmlOpenTag(os, "li", (char *)0); + renderHtmlOpenTag(os, "li", (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, "li"); } @@ -130,7 +130,7 @@ void Document::Heading::renderHtml(std::ostream &os) const { throw std::runtime_error("heading level too high"); char tag[64]; snprintf(tag, sizeof tag, "h%d", level); - renderHtmlOpenTag(os, tag, (char *)0); + renderHtmlOpenTag(os, tag, (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, tag); } @@ -141,22 +141,22 @@ void Document::Cell::renderHtml(std::ostream &os) const { snprintf(ws, sizeof ws, "%d", w); snprintf(hs, sizeof hs, "%d", h); if(w > 1 && h > 1) - renderHtmlOpenTag(os, tag, "colspan", ws, "rowspan", hs, (char *)0); + renderHtmlOpenTag(os, tag, "colspan", ws, "rowspan", hs, (char *)nullptr); else if(w > 1) - renderHtmlOpenTag(os, tag, "colspan", ws, (char *)0); + renderHtmlOpenTag(os, tag, "colspan", ws, (char *)nullptr); else if(h > 1) - renderHtmlOpenTag(os, tag, "rowspan", hs, (char *)0); + renderHtmlOpenTag(os, tag, "rowspan", hs, (char *)nullptr); else - renderHtmlOpenTag(os, tag, (char *)0); + renderHtmlOpenTag(os, tag, (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, tag); } void Document::Table::renderHtml(std::ostream &os) const { - renderHtmlOpenTag(os, "table", (char *)0); + renderHtmlOpenTag(os, "table", (char *)nullptr); const int w = width(), h = height(); for(int row = 0; row < h; ++row) { - renderHtmlOpenTag(os, "tr", (char *)0); + renderHtmlOpenTag(os, "tr", (char *)nullptr); for(int col = 0; col < w;) { int skip = 0; for(size_t n = 0; n < cells.size(); ++n) { @@ -169,7 +169,7 @@ void Document::Table::renderHtml(std::ostream &os) const { } if(!skip) { if(!occupied(col, row)) { - renderHtmlOpenTag(os, "td", (char *)0); + renderHtmlOpenTag(os, "td", (char *)nullptr); renderHtmlCloseTag(os, "td"); } skip = 1; @@ -182,7 +182,7 @@ void Document::Table::renderHtml(std::ostream &os) const { } void Document::RootContainer::renderHtml(std::ostream &os) const { - renderHtmlOpenTag(os, "body", (char *)0); + renderHtmlOpenTag(os, "body", (char *)nullptr); renderHtmlContents(os); renderHtmlCloseTag(os, "body"); } diff --git a/src/Host.cc b/src/Host.cc index 4017789..33e5128 100644 --- a/src/Host.cc +++ b/src/Host.cc @@ -47,7 +47,7 @@ void Host::addVolume(Volume *v) { Volume *Host::findVolume(const std::string &volumeName) const { auto it = volumes.find(volumeName); - return it != volumes.end() ? it->second : NULL; + return it != volumes.end() ? it->second : nullptr; } std::string Host::userAndHost() const { @@ -65,7 +65,7 @@ bool Host::available() const { // localhost is always available if(hostname == "localhost") return true; - return invoke(NULL, "true", (const char *)NULL) == 0; + return invoke(nullptr, "true", (const char *)nullptr) == 0; } void Host::write(std::ostream &os, int step) const { @@ -67,7 +67,7 @@ void IO::popen(const std::vector<std::string> &command, int IO::close(bool checkStatus) { FILE *fpSave = fp; - fp = NULL; + fp = nullptr; if(fclose(fpSave) < 0) { if(abortOnError) abort(); @@ -48,8 +48,8 @@ class Subprocess; class IO { public: /** @brief Constructor */ - IO(): fp(NULL), - subprocess(NULL), + IO(): fp(nullptr), + subprocess(nullptr), closeFile(false), abortOnError(false) {} @@ -60,7 +60,7 @@ public: IO(FILE *fp_, const std::string &path_): fp(fp_), path(path_), - subprocess(NULL), + subprocess(nullptr), closeFile(false), abortOnError(false) {} @@ -159,7 +159,7 @@ private: const std::string &path_, bool abortOnError_): fp(fp_), path(path_), - subprocess(NULL), + subprocess(nullptr), closeFile(false), abortOnError(abortOnError_) {} @@ -169,7 +169,7 @@ private: /** @brief Path to open file */ std::string path; - /** @brief Subprocess handler or @c NULL + /** @brief Subprocess handler or null pointer * * Used by @ref popen(). */ @@ -195,7 +195,7 @@ private: class Directory { public: /** @brief Constructor */ - Directory(): dp(NULL) {} + Directory(): dp(nullptr) {} /** @brief Destructor * diff --git a/src/MakeBackup.cc b/src/MakeBackup.cc index 5f1a57a..890c1f9 100644 --- a/src/MakeBackup.cc +++ b/src/MakeBackup.cc @@ -129,7 +129,7 @@ MakeBackup::MakeBackup(Volume *volume_, Device *device_): incompletePath(backupPath + ".incomplete"), sourcePath(volume->path), what("pending"), - outcome(NULL) { + outcome(nullptr) { } MakeBackup::~MakeBackup() { @@ -156,7 +156,7 @@ const Backup *MakeBackup::getLastBackup() { return backup; } // Otherwise there is nothing to link to. - return NULL; + return nullptr; } void MakeBackup::hookEnvironment(Subprocess &sp) { @@ -240,7 +240,7 @@ int MakeBackup::rsyncBackup() { for(size_t n = 0; n < volume->exclude.size(); ++n) cmd.push_back("--exclude=" + volume->exclude[n]); const Backup *lastBackup = getLastBackup(); - if(lastBackup != NULL) + if(lastBackup != nullptr) cmd.push_back("--link-dest=" + lastBackup->backupPath()); // Source cmd.push_back(host->sshPrefix() + sourcePath + "/."); diff --git a/src/Report.cc b/src/Report.cc index e5a44c0..aafbc7b 100644 --- a/src/Report.cc +++ b/src/Report.cc @@ -178,7 +178,7 @@ Document::Table *Report::reportSummary() { t->addCell(new Document::Cell(new Document::String(perDevice.count))) ->style = perDevice.count ? "good" : "bad"; // Look for the most recent attempt at this device - const Backup *most_recent_backup = NULL; + const Backup *most_recent_backup = nullptr; for(backups_type::const_reverse_iterator bit = volume->backups.rbegin(); bit != volume->backups.rend(); ++bit) { @@ -234,7 +234,7 @@ bool Report::suitableLog(const Volume *volume, const Backup *backup) { // Generate the report of backup logfiles for a volume void Report::reportLogs(const Volume *volume) { - Document::LinearContainer *lc = NULL; + Document::LinearContainer *lc = nullptr; Host *host = volume->parent; // Backups for a volume are ordered primarily by date and secondarily by // device. The most recent backups are the most interesting so they are diff --git a/src/RetireVolumes.cc b/src/RetireVolumes.cc index 1f49921..22df63d 100644 --- a/src/RetireVolumes.cc +++ b/src/RetireVolumes.cc @@ -56,7 +56,7 @@ struct Retirable { * @param i Backup ID */ inline Retirable(const std::string &h, const std::string &v, Device *d, std::string i): - hostName(h), volumeName(v), device(d), id(i), b(NULL) { + hostName(h), volumeName(v), device(d), id(i), b(nullptr) { } /** @brief Destructor */ diff --git a/src/Store.cc b/src/Store.cc index b421a7b..b303b33 100644 --- a/src/Store.cc +++ b/src/Store.cc @@ -23,7 +23,7 @@ // Identify the device on this store, if any void Store::identify() { - IO *f = NULL; + IO *f = nullptr; try { struct stat sb; diff --git a/src/Store.h b/src/Store.h index f14d53d..1c6ba3e 100644 --- a/src/Store.h +++ b/src/Store.h @@ -33,7 +33,7 @@ public: * @param path_ Location of store */ Store(const std::string &path_): path(path_), - device(NULL), + device(nullptr), state(Enabled) { } @@ -51,9 +51,9 @@ public: /** @param Device mounted at this store * - * Set to NULL before checking, or if no device is mounted here + * Set to null pointer before checking, or if no device is mounted here */ - Device *device; // device for this, or NULL + Device *device; /** @brief State of this store */ State state; diff --git a/src/Subprocess.cc b/src/Subprocess.cc index 3a2c22a..7c4125f 100644 --- a/src/Subprocess.cc +++ b/src/Subprocess.cc @@ -31,8 +31,8 @@ Subprocess::Subprocess(): pid(-1), timeout(0), status(-1), - actionlist(NULL), - eventloop(NULL) { + actionlist(nullptr), + eventloop(nullptr) { } Subprocess::Subprocess(const std::vector<std::string> &cmd_): @@ -40,8 +40,8 @@ Subprocess::Subprocess(const std::vector<std::string> &cmd_): cmd(cmd_), timeout(0), status(-1), - actionlist(NULL), - eventloop(NULL) { + actionlist(nullptr), + eventloop(nullptr) { } Subprocess::~Subprocess() { @@ -91,7 +91,7 @@ pid_t Subprocess::launch(EventLoop *e) { std::vector<const char *> args; for(size_t n = 0; n < cmd.size(); ++n) args.push_back(cmd[n].c_str()); - args.push_back(NULL); + args.push_back(nullptr); // Start the subprocess switch(pid = fork()) { case -1: @@ -202,7 +202,7 @@ int Subprocess::wait(bool checkStatus) { setup(eventloop); eventloop->wait(); delete eventloop; - eventloop = NULL; + eventloop = nullptr; pid = -1; if(checkStatus && status) { if(WIFSIGNALED(status) && WTERMSIG(status) == SIGPIPE) @@ -240,7 +240,7 @@ void Subprocess::getTimestamp(struct timespec &now) { throw IOError("clock_gettime", errno); #else struct timeval tv; - if(gettimeofday(&tv, NULL) < 0) + if(gettimeofday(&tv, nullptr) < 0) throw IOError("gettimeofday", errno); now.tv_sec = tv.tv_sec; now.tv_nsec = tv.tv_sec * 1000; diff --git a/src/Unicode.cc b/src/Unicode.cc index 566c410..0d9a130 100644 --- a/src/Unicode.cc +++ b/src/Unicode.cc @@ -31,7 +31,7 @@ void toUnicode(std::wstring &u, const std::string &mbs) { static iconv_t cd; - if(cd == 0) { + if(cd == nullptr) { char *mbsEncoding = nl_langinfo(CODESET); cd = iconv_open(ENCODING, mbsEncoding); if(!cd) diff --git a/src/Volume.cc b/src/Volume.cc index 12c5352..ae86f9c 100644 --- a/src/Volume.cc +++ b/src/Volume.cc @@ -83,7 +83,7 @@ bool Volume::removeBackup(const Backup *backup) { } const Backup *Volume::mostRecentBackup(const Device *device) const { - const Backup *result = NULL; + const Backup *result = nullptr; for(auto it = backups.begin(); it != backups.end(); ++it) { const Backup *b = *it; if(!device || b->getDevice() == device) { @@ -95,7 +95,7 @@ const Backup *Volume::mostRecentBackup(const Device *device) const { } const Backup *Volume::mostRecentFailedBackup(const Device *device) const { - const Backup *result = NULL; + const Backup *result = nullptr; for(auto it = backups.begin(); it != backups.end(); ++it) { const Backup *b = *it; if(!device || b->getDevice() == device) { @@ -114,7 +114,7 @@ bool Volume::available() const { const char *option; // Guess which version of stat to use based on uname. if(parent->invoke(&os, - "uname", "-s", (const char *)NULL) != 0) + "uname", "-s", (const char *)nullptr) != 0) return false; if(os == "Darwin" || (os.size() >= 3 @@ -129,7 +129,7 @@ bool Volume::available() const { "stat", option, "%d", path.c_str(), parent_directory.c_str(), - (const char *)NULL)) + (const char *)nullptr)) return false; // Split output into lines std::vector<std::string> lines; @@ -146,8 +146,8 @@ bool Volume::available() const { std::string file = (checkFile[0] == '/' ? checkFile : path + "/" + checkFile); - if(parent->invoke(NULL, - "test", "-e", file.c_str(), (const char *)NULL) != 0) + if(parent->invoke(nullptr, + "test", "-e", file.c_str(), (const char *)nullptr) != 0) return false; } return true; diff --git a/src/rsbackup.cc b/src/rsbackup.cc index 09dd1d1..8f6cf12 100644 --- a/src/rsbackup.cc +++ b/src/rsbackup.cc @@ -35,7 +35,7 @@ int main(int argc, char **argv) { try { - if(setlocale(LC_CTYPE, "") == NULL) + if(setlocale(LC_CTYPE, "") == nullptr) throw std::runtime_error(std::string("setlocale: ") + strerror(errno)); // Parse command line diff --git a/src/test-check.cc b/src/test-check.cc index f62d175..2e750b3 100644 --- a/src/test-check.cc +++ b/src/test-check.cc @@ -27,7 +27,7 @@ static bool result; static void *background(void *) { result = check("%s", "spong"); - return NULL; + return nullptr; } /* We can't use stdio here because reading from an unbuffered file causes a @@ -58,14 +58,14 @@ static char *fd_fgets(char buffer[], size_t bufsize, int fd) { break; } buffer[index] = 0; - return ch < 0 ? NULL : buffer; + return ch < 0 ? nullptr : buffer; } static void test(const char *typed, const char *typed2, bool expect) { pthread_t tid; char buffer[1024]; - assert(pthread_create(&tid, NULL, background, NULL) == 0); + assert(pthread_create(&tid, nullptr, background, nullptr) == 0); assert(fd_fgets(buffer, sizeof buffer, output)); assert(std::string(buffer) == "spong\n"); assert(fd_getc(output) == 'y'); @@ -96,7 +96,7 @@ static void test(const char *typed, const char *typed2, bool expect) { assert(fflush(input) >= 0); } - assert(pthread_join(tid, NULL) == 0); + assert(pthread_join(tid, nullptr) == 0); assert(result == expect); } @@ -104,8 +104,8 @@ static void test_force(void) { pthread_t tid; command.force = true; - assert(pthread_create(&tid, NULL, background, NULL) == 0); - assert(pthread_join(tid, NULL) == 0); + assert(pthread_create(&tid, nullptr, background, nullptr) == 0); + assert(pthread_join(tid, nullptr) == 0); assert(result == true); command.force = false; } @@ -122,8 +122,8 @@ int main() { assert((input = fdopen(i[1], "w"))); output = o[0]; - test("yes", NULL, true); - test("no", NULL, false); + test("yes", nullptr, true); + test("no", nullptr, false); test("", "yes", true); test("whatever", "yes", true); test_force(); diff --git a/src/test-command.cc b/src/test-command.cc index b97fdc4..760dca6 100644 --- a/src/test-command.cc +++ b/src/test-command.cc @@ -20,7 +20,7 @@ #include <cassert> static void test_action_backup(void) { - static const char *argv[] = { "rsbackup", "--backup", NULL }; + static const char *argv[] = { "rsbackup", "--backup", nullptr }; Command c; assert(c.backup == false); c.parse(2, argv); @@ -28,34 +28,34 @@ static void test_action_backup(void) { } static void test_action_html(void) { - static const char *argv[] = { "rsbackup", "--html", "PATH", NULL }; + static const char *argv[] = { "rsbackup", "--html", "PATH", nullptr }; Command c; - assert(c.html == NULL); + assert(c.html == nullptr); c.parse(3, argv); - assert(c.html != NULL); + assert(c.html != nullptr); assert(*c.html == "PATH"); } static void test_action_text(void) { - static const char *argv[] = { "rsbackup", "--text", "PATH", NULL }; + static const char *argv[] = { "rsbackup", "--text", "PATH", nullptr }; Command c; - assert(c.text == NULL); + assert(c.text == nullptr); c.parse(3, argv); - assert(c.text != NULL); + assert(c.text != nullptr); assert(*c.text == "PATH"); } static void test_action_email(void) { - static const char *argv[] = { "rsbackup", "--email", "user@domain", NULL }; + static const char *argv[] = { "rsbackup", "--email", "user@domain", nullptr }; Command c; - assert(c.email == NULL); + assert(c.email == nullptr); c.parse(3, argv); - assert(c.email != NULL); + assert(c.email != nullptr); assert(*c.email == "user@domain"); } static void test_action_prune(void) { - static const char *argv[] = { "rsbackup", "--prune", NULL }; + static const char *argv[] = { "rsbackup", "--prune", nullptr }; Command c; assert(c.prune == false); c.parse(2, argv); @@ -63,7 +63,7 @@ static void test_action_prune(void) { } static void test_action_prune_incomplete(void) { - static const char *argv[] = { "rsbackup", "--prune-incomplete", NULL }; + static const char *argv[] = { "rsbackup", "--prune-incomplete", nullptr }; Command c; assert(c.pruneIncomplete == false); c.parse(2, argv); @@ -71,7 +71,7 @@ static void test_action_prune_incomplete(void) { } static void test_action_retire(void) { - static const char *argv[] = { "rsbackup", "--retire", "VOLUME", NULL }; + static const char *argv[] = { "rsbackup", "--retire", "VOLUME", nullptr }; Command c; assert(c.retire == false); c.parse(3, argv); @@ -88,7 +88,7 @@ static void test_action_retire(void) { } static void test_action_retire_device(void) { - static const char *argv[] = { "rsbackup", "--retire-device", "DEVICE", NULL }; + static const char *argv[] = { "rsbackup", "--retire-device", "DEVICE", nullptr }; Command c; assert(c.retireDevice == false); c.parse(3, argv); @@ -106,7 +106,7 @@ static void test_action_retire_device(void) { } static void test_action_dump_config(void) { - static const char *argv[] = { "rsbackup", "--dump-config", "JUNK", NULL }; + static const char *argv[] = { "rsbackup", "--dump-config", "JUNK", nullptr }; Command c; assert(c.dumpConfig == false); c.parse(2, argv); @@ -122,7 +122,7 @@ static void test_action_dump_config(void) { } static void test_action_none(void) { - static const char *argv[] = { "rsbackup", NULL }; + static const char *argv[] = { "rsbackup", nullptr }; Command c; try { c.parse(1, argv); @@ -133,7 +133,7 @@ static void test_action_none(void) { static void test_action_incompatible(void) { try { - static const char *argv[] = { "rsbackup", "--retire", "--retire-device", "XYZ", NULL }; + static const char *argv[] = { "rsbackup", "--retire", "--retire-device", "XYZ", nullptr }; Command c; c.parse(4, argv); assert(!"unexpectedly succeeded"); @@ -142,7 +142,7 @@ static void test_action_incompatible(void) { != std::string::npos); } try { - static const char *argv[] = { "rsbackup", "--retire", "--backup", "XYZ", NULL }; + static const char *argv[] = { "rsbackup", "--retire", "--backup", "XYZ", nullptr }; Command c; c.parse(4, argv); assert(!"unexpectedly succeeded"); @@ -151,7 +151,7 @@ static void test_action_incompatible(void) { != std::string::npos); } try { - static const char *argv[] = { "rsbackup", "--retire-device", "--backup", "XYZ", NULL }; + static const char *argv[] = { "rsbackup", "--retire-device", "--backup", "XYZ", nullptr }; Command c; c.parse(4, argv); assert(!"unexpectedly succeeded"); @@ -160,7 +160,7 @@ static void test_action_incompatible(void) { != std::string::npos); } try { - static const char *argv[] = { "rsbackup", "--dump-config", "--backup", "XYZ", NULL }; + static const char *argv[] = { "rsbackup", "--dump-config", "--backup", "XYZ", nullptr }; Command c; c.parse(4, argv); assert(!"unexpectedly succeeded"); @@ -174,7 +174,7 @@ static void test_action_incompatible(void) { static void test_selection(void) { { static const char *argv[] = { "rsbackup", "--backup", "A", "-A:B", "!C", - NULL }; + nullptr }; Command c; c.parse(5, argv); assert(c.backup == true); @@ -192,7 +192,7 @@ static void test_selection(void) { try { static const char *argv[] = { "rsbackup", "--backup", "~A", - NULL }; + nullptr }; Command c; c.parse(3, argv); assert(!"unexpectedly succeeded"); @@ -201,7 +201,7 @@ static void test_selection(void) { try { static const char *argv[] = { "rsbackup", "--backup", "A:~", - NULL }; + nullptr }; Command c; c.parse(3, argv); assert(!"unexpectedly succeeded"); @@ -210,7 +210,7 @@ static void test_selection(void) { try { static const char *argv[] = { "rsbackup", "--backup", "A:B:C", - NULL }; + nullptr }; Command c; c.parse(3, argv); assert(!"unexpectedly succeeded"); @@ -219,7 +219,7 @@ static void test_selection(void) { try { static const char *argv[] = { "rsbackup", "--backup", "*:C", - NULL }; + nullptr }; Command c; c.parse(3, argv); assert(!"unexpectedly succeeded"); |