aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-06 10:44:21 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-06 10:56:33 +0100
commit88c452d1603eb809358e509d5dca9c40c512cd20 (patch)
tree41d3162e57fbbd0d5e10e35eed84d4b2b5e9e936 /src/libutil
parent9ff4060d2691c1a7dc2f8be65d117f43c3335714 (diff)
parent35732a95bcdc0a4b4492845205e6283fcc88fd0d (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/args.cc13
-rw-r--r--src/libutil/args.hh4
-rw-r--r--src/libutil/util.cc6
3 files changed, 22 insertions, 1 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index ba15ea571..ad7a268fc 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -178,6 +178,19 @@ Strings argvToStrings(int argc, char * * argv)
return args;
}
+Strings editorFor(Pos pos)
+{
+ auto editor = getEnv("EDITOR", "cat");
+ auto args = tokenizeString<Strings>(editor);
+ if (pos.line > 0 && (
+ editor.find("emacs") != std::string::npos ||
+ editor.find("nano") != std::string::npos ||
+ editor.find("vim") != std::string::npos))
+ args.push_back(fmt("+%d", pos.line));
+ args.push_back(pos.file);
+ return args;
+}
+
std::string renderLabels(const Strings & labels)
{
std::string res;
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index b960a55a8..59d427ee6 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -5,6 +5,7 @@
#include <memory>
#include "util.hh"
+#include "nixexpr.hh"
namespace nix {
@@ -241,6 +242,9 @@ public:
Strings argvToStrings(int argc, char * * argv);
+/* Helper function to generate args that invoke $EDITOR on filename:lineno */
+Strings editorFor(Pos pos);
+
/* Helper function for rendering argument labels. */
std::string renderLabels(const Strings & labels);
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 747b31cff..0902c3783 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1572,7 +1572,11 @@ std::unique_ptr<InterruptCallback> createInterruptCallback(std::function<void()>
AutoCloseFD createUnixDomainSocket(const Path & path, mode_t mode)
{
- AutoCloseFD fdSocket = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ AutoCloseFD fdSocket = socket(PF_UNIX, SOCK_STREAM
+ #ifdef SOCK_CLOEXEC
+ | SOCK_CLOEXEC
+ #endif
+ , 0);
if (!fdSocket)
throw SysError("cannot create Unix domain socket");