about summary refs log tree commit diff
path: root/third_party/nix/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/libutil')
-rw-r--r--third_party/nix/src/libutil/archive.cc16
-rw-r--r--third_party/nix/src/libutil/compression.cc12
-rw-r--r--third_party/nix/src/libutil/config.cc15
-rw-r--r--third_party/nix/src/libutil/config.hh4
-rw-r--r--third_party/nix/src/libutil/serialise.cc5
-rw-r--r--third_party/nix/src/libutil/util.cc24
-rw-r--r--third_party/nix/src/libutil/util.hh2
-rw-r--r--third_party/nix/src/libutil/xml-writer.cc5
8 files changed, 43 insertions, 40 deletions
diff --git a/third_party/nix/src/libutil/archive.cc b/third_party/nix/src/libutil/archive.cc
index 855a3c465838..a316336ec73f 100644
--- a/third_party/nix/src/libutil/archive.cc
+++ b/third_party/nix/src/libutil/archive.cc
@@ -199,7 +199,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) {
 
   std::map<Path, int, CaseInsensitiveCompare> names;
 
-  while (1) {
+  while (true) {
     checkInterrupt();
 
     s = readString(source);
@@ -254,7 +254,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) {
         throw badArchive("expected open tag");
       }
 
-      while (1) {
+      while (true) {
         checkInterrupt();
 
         s = readString(source);
@@ -323,14 +323,14 @@ struct RestoreSink : ParseSink {
   Path dstPath;
   AutoCloseFD fd;
 
-  void createDirectory(const Path& path) {
+  void createDirectory(const Path& path) override {
     Path p = dstPath + path;
     if (mkdir(p.c_str(), 0777) == -1) {
       throw SysError(format("creating directory '%1%'") % p);
     }
   };
 
-  void createRegularFile(const Path& path) {
+  void createRegularFile(const Path& path) override {
     Path p = dstPath + path;
     fd = open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666);
     if (!fd) {
@@ -338,7 +338,7 @@ struct RestoreSink : ParseSink {
     }
   }
 
-  void isExecutable() {
+  void isExecutable() override {
     struct stat st;
     if (fstat(fd.get(), &st) == -1) {
       throw SysError("fstat");
@@ -348,7 +348,7 @@ struct RestoreSink : ParseSink {
     }
   }
 
-  void preallocateContents(unsigned long long len) {
+  void preallocateContents(unsigned long long len) override {
 #if HAVE_POSIX_FALLOCATE
     if (len) {
       errno = posix_fallocate(fd.get(), 0, len);
@@ -363,11 +363,11 @@ struct RestoreSink : ParseSink {
 #endif
   }
 
-  void receiveContents(unsigned char* data, unsigned int len) {
+  void receiveContents(unsigned char* data, unsigned int len) override {
     writeFull(fd.get(), data, len);
   }
 
-  void createSymlink(const Path& path, const string& target) {
+  void createSymlink(const Path& path, const string& target) override {
     Path p = dstPath + path;
     nix::createSymlink(target, p);
   }
diff --git a/third_party/nix/src/libutil/compression.cc b/third_party/nix/src/libutil/compression.cc
index 93e2360bd58c..851a7f817994 100644
--- a/third_party/nix/src/libutil/compression.cc
+++ b/third_party/nix/src/libutil/compression.cc
@@ -57,7 +57,7 @@ struct XzDecompressionSink : CompressionSink {
     strm.avail_out = sizeof(outbuf);
   }
 
-  ~XzDecompressionSink() { lzma_end(&strm); }
+  ~XzDecompressionSink() override { lzma_end(&strm); }
 
   void finish() override {
     CompressionSink::flush();
@@ -103,7 +103,7 @@ struct BzipDecompressionSink : ChunkedCompressionSink {
     strm.avail_out = sizeof(outbuf);
   }
 
-  ~BzipDecompressionSink() { BZ2_bzDecompressEnd(&strm); }
+  ~BzipDecompressionSink() override { BZ2_bzDecompressEnd(&strm); }
 
   void finish() override {
     flush();
@@ -147,7 +147,7 @@ struct BrotliDecompressionSink : ChunkedCompressionSink {
     }
   }
 
-  ~BrotliDecompressionSink() { BrotliDecoderDestroyInstance(state); }
+  ~BrotliDecompressionSink() override { BrotliDecoderDestroyInstance(state); }
 
   void finish() override {
     flush();
@@ -249,7 +249,7 @@ struct XzCompressionSink : CompressionSink {
     strm.avail_out = sizeof(outbuf);
   }
 
-  ~XzCompressionSink() { lzma_end(&strm); }
+  ~XzCompressionSink() override { lzma_end(&strm); }
 
   void finish() override {
     CompressionSink::flush();
@@ -295,7 +295,7 @@ struct BzipCompressionSink : ChunkedCompressionSink {
     strm.avail_out = sizeof(outbuf);
   }
 
-  ~BzipCompressionSink() { BZ2_bzCompressEnd(&strm); }
+  ~BzipCompressionSink() override { BZ2_bzCompressEnd(&strm); }
 
   void finish() override {
     flush();
@@ -340,7 +340,7 @@ struct BrotliCompressionSink : ChunkedCompressionSink {
     }
   }
 
-  ~BrotliCompressionSink() { BrotliEncoderDestroyInstance(state); }
+  ~BrotliCompressionSink() override { BrotliEncoderDestroyInstance(state); }
 
   void finish() override {
     flush();
diff --git a/third_party/nix/src/libutil/config.cc b/third_party/nix/src/libutil/config.cc
index 9c8c6cf4b255..56f0c8c3e7cd 100644
--- a/third_party/nix/src/libutil/config.cc
+++ b/third_party/nix/src/libutil/config.cc
@@ -1,6 +1,8 @@
 #define GOOGLE_STRIP_LOG 0
 #include "config.hh"
 
+#include <utility>
+
 #include <glog/logging.h>
 
 #include "args.hh"
@@ -96,7 +98,7 @@ void AbstractConfig::applyConfigFile(const Path& path) {
         line = string(line, 0, hash);
       }
 
-      vector<string> tokens = tokenizeString<vector<string> >(line);
+      auto tokens = tokenizeString<vector<string> >(line);
       if (tokens.empty()) {
         continue;
       }
@@ -136,7 +138,7 @@ void AbstractConfig::applyConfigFile(const Path& path) {
 
       string name = tokens[0];
 
-      vector<string>::iterator i = tokens.begin();
+      auto i = tokens.begin();
       advance(i, 2);
 
       set(name,
@@ -171,10 +173,11 @@ void Config::convertToArgs(Args& args, const std::string& category) {
   }
 }
 
-AbstractSetting::AbstractSetting(const std::string& name,
-                                 const std::string& description,
-                                 const std::set<std::string>& aliases)
-    : name(name), description(description), aliases(aliases) {}
+AbstractSetting::AbstractSetting(std::string name, std::string description,
+                                 std::set<std::string> aliases)
+    : name(std::move(name)),
+      description(std::move(description)),
+      aliases(std::move(aliases)) {}
 
 void AbstractSetting::toJSON(JSONPlaceholder& out) { out.write(to_string()); }
 
diff --git a/third_party/nix/src/libutil/config.hh b/third_party/nix/src/libutil/config.hh
index 9735569d1084..f8055d4d3690 100644
--- a/third_party/nix/src/libutil/config.hh
+++ b/third_party/nix/src/libutil/config.hh
@@ -103,8 +103,8 @@ class AbstractSetting {
   bool overriden = false;
 
  protected:
-  AbstractSetting(const std::string& name, const std::string& description,
-                  const std::set<std::string>& aliases);
+  AbstractSetting(std::string name, std::string description,
+                  std::set<std::string> aliases);
 
   virtual ~AbstractSetting() {
     // Check against a gcc miscompilation causing our constructor
diff --git a/third_party/nix/src/libutil/serialise.cc b/third_party/nix/src/libutil/serialise.cc
index b51ed2105b4d..0d9b069a2887 100644
--- a/third_party/nix/src/libutil/serialise.cc
+++ b/third_party/nix/src/libutil/serialise.cc
@@ -4,6 +4,7 @@
 #include <cerrno>
 #include <cstring>
 #include <memory>
+#include <utility>
 
 #include "glog/logging.h"
 #include "util.hh"
@@ -159,7 +160,7 @@ size_t StringSource::read(unsigned char* data, size_t len) {
 std::unique_ptr<Source> sinkToSource(std::function<void(Sink&)> fun,
                                      std::function<void()> eof) {
   struct SinkToSource : Source {
-    typedef boost::coroutines2::coroutine<std::string> coro_t;
+    using coro_t = boost::coroutines2::coroutine<std::string>;
 
     std::function<void(Sink&)> fun;
     std::function<void()> eof;
@@ -167,7 +168,7 @@ std::unique_ptr<Source> sinkToSource(std::function<void(Sink&)> fun,
     bool started = false;
 
     SinkToSource(std::function<void(Sink&)> fun, std::function<void()> eof)
-        : fun(fun), eof(eof) {}
+        : fun(std::move(fun)), eof(std::move(eof)) {}
 
     std::string cur;
     size_t pos = 0;
diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc
index 213a9a0d6ab9..a4e382f12ebe 100644
--- a/third_party/nix/src/libutil/util.cc
+++ b/third_party/nix/src/libutil/util.cc
@@ -2,6 +2,7 @@
 
 #include <cctype>
 #include <cerrno>
+#include <climits>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -9,10 +10,10 @@
 #include <iostream>
 #include <sstream>
 #include <thread>
+#include <utility>
 
 #include <fcntl.h>
 #include <grp.h>
-#include <limits.h>
 #include <pwd.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
@@ -122,7 +123,7 @@ Path canonPath(const Path& path, bool resolveSymlinks) {
      arbitrary (but high) limit to prevent infinite loops. */
   unsigned int followCount = 0, maxFollow = 1024;
 
-  while (1) {
+  while (true) {
     /* Skip slashes. */
     while (i != end && *i == '/') {
       i++;
@@ -354,7 +355,7 @@ void writeFile(const Path& path, Source& source, mode_t mode) {
 
 string readLine(int fd) {
   string s;
-  while (1) {
+  while (true) {
     checkInterrupt();
     char ch;
     // FIXME: inefficient
@@ -446,7 +447,7 @@ Path createTempDir(const Path& tmpRoot, const Path& prefix, bool includePid,
   int localCounter = 0;
   int& counter(useGlobalCounter ? globalCounter : localCounter);
 
-  while (1) {
+  while (true) {
     checkInterrupt();
     Path tmpDir = tempName(tmpRoot, prefix, includePid, counter);
     if (mkdir(tmpDir.c_str(), mode) == 0) {
@@ -515,8 +516,7 @@ Path getConfigDir() {
 std::vector<Path> getConfigDirs() {
   Path configHome = getConfigDir();
   string configDirs = getEnv("XDG_CONFIG_DIRS");
-  std::vector<Path> result =
-      tokenizeString<std::vector<string>>(configDirs, ":");
+  auto result = tokenizeString<std::vector<string>>(configDirs, ":");
   result.insert(result.begin(), configHome);
   return result;
 }
@@ -648,7 +648,7 @@ void drainFD(int fd, Sink& sink, bool block) {
   }
 
   std::vector<unsigned char> buf(64 * 1024);
-  while (1) {
+  while (true) {
     checkInterrupt();
     ssize_t rd = read(fd, buf.data(), buf.size());
     if (rd == -1) {
@@ -670,7 +670,7 @@ void drainFD(int fd, Sink& sink, bool block) {
 
 AutoDelete::AutoDelete() : del{false} {}
 
-AutoDelete::AutoDelete(const string& p, bool recursive) : path(p) {
+AutoDelete::AutoDelete(string p, bool recursive) : path(std::move(p)) {
   del = true;
   this->recursive = recursive;
 }
@@ -759,7 +759,7 @@ void Pipe::create() {
 
 //////////////////////////////////////////////////////////////////////
 
-Pid::Pid() {}
+Pid::Pid() = default;
 
 Pid::Pid(pid_t pid) : pid(pid) {}
 
@@ -802,7 +802,7 @@ int Pid::kill() {
 
 int Pid::wait() {
   assert(pid != -1);
-  while (1) {
+  while (true) {
     int status;
     int res = waitpid(pid, &status, 0);
     if (res == pid) {
@@ -939,7 +939,7 @@ std::vector<char*> stringsToCharPtrs(const Strings& ss) {
   for (auto& s : ss) {
     res.push_back((char*)s.c_str());
   }
-  res.push_back(0);
+  res.push_back(nullptr);
   return res;
 }
 
@@ -1031,7 +1031,7 @@ void runProgram2(const RunOptions& options) {
           throw SysError("setgid failed");
         }
         /* Drop all other groups if we're setgid. */
-        if (options.gid && setgroups(0, 0) == -1) {
+        if (options.gid && setgroups(0, nullptr) == -1) {
           throw SysError("setgroups failed");
         }
         if (options.uid && setuid(*options.uid) == -1) {
diff --git a/third_party/nix/src/libutil/util.hh b/third_party/nix/src/libutil/util.hh
index a7e9b20fd560..2439b3da5373 100644
--- a/third_party/nix/src/libutil/util.hh
+++ b/third_party/nix/src/libutil/util.hh
@@ -173,7 +173,7 @@ class AutoDelete {
 
  public:
   AutoDelete();
-  AutoDelete(const Path& p, bool recursive = true);
+  AutoDelete(Path p, bool recursive = true);
   ~AutoDelete();
   void cancel();
   void reset(const Path& p, bool recursive = true);
diff --git a/third_party/nix/src/libutil/xml-writer.cc b/third_party/nix/src/libutil/xml-writer.cc
index ed41286cc1a3..11cd632399ad 100644
--- a/third_party/nix/src/libutil/xml-writer.cc
+++ b/third_party/nix/src/libutil/xml-writer.cc
@@ -1,6 +1,6 @@
 #include "xml-writer.hh"
 
-#include <assert.h>
+#include <cassert>
 
 namespace nix {
 
@@ -68,8 +68,7 @@ void XMLWriter::writeEmptyElement(const string& name, const XMLAttrs& attrs) {
 void XMLWriter::writeAttrs(const XMLAttrs& attrs) {
   for (auto& i : attrs) {
     output << " " << i.first << "=\"";
-    for (size_t j = 0; j < i.second.size(); ++j) {
-      char c = i.second[j];
+    for (char c : i.second) {
       if (c == '"') {
         output << "&quot;";
       } else if (c == '<') {