aboutsummaryrefslogtreecommitdiff
path: root/butl/process
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-22 12:51:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-22 12:51:24 +0200
commit4d79758a845d3cd64f0153d60abb88d3ae4c2a68 (patch)
treee87278e7c839e84de26b32b17f0fe4dca883be85 /butl/process
parent91a5ccf011c569dabc6cc79997ddd5f4e04592b1 (diff)
Extend process search with pre-search support, other minor improvements
Diffstat (limited to 'butl/process')
-rw-r--r--butl/process43
1 files changed, 41 insertions, 2 deletions
diff --git a/butl/process b/butl/process
index c967c44..7966309 100644
--- a/butl/process
+++ b/butl/process
@@ -75,6 +75,16 @@ namespace butl
path recall;
path effect;
+ // Handle empty recall/effect.
+ //
+ const char* recall_string () const;
+ const char* effect_string () const;
+
+ bool empty () const
+ {
+ return initial == nullptr && recall.empty () && effect.empty ();
+ }
+
// Moveable-only type.
//
process_path (process_path&&);
@@ -84,10 +94,11 @@ namespace butl
process_path& operator= (const process_path&) = delete;
process_path () = default;
- process_path (const char* i, const char** a0): initial (i), args0_ (a0) {}
- ~process_path () {if (args0_ != nullptr) *args0_ = initial;}
+ process_path (const char* i, path&& r, path&& e);
+ ~process_path ();
private:
+ friend class process;
const char** args0_ = nullptr;
};
@@ -215,6 +226,34 @@ namespace butl
static process_path
path_search (const char*& args0, const dir_path& fallback = dir_path ());
+ // This version is primarily useful when you want to pre-search the
+ // executable before creating the args[] array. In this case you will
+ // use the recall path for args[0].
+ //
+ // The init argument determines whether to initialize the initial path to
+ // the shallow copy of file. If it is true, then initial is the same as
+ // file and recall is either empty or contain a different path. If it is
+ // false then initial contains a shallow copy of recall, and recall is
+ // either a different path or a deep copy of file. Normally you don't care
+ // about initial once you got recall and the main reason to pass true to
+ // this argument is to save a copy (since initial and recall are usually
+ // the same).
+ //
+ static process_path
+ path_search (const char* file, bool init, const dir_path& = dir_path ());
+
+ static process_path
+ path_search (const std::string& f, bool i, const dir_path& fb = dir_path ())
+ {
+ return path_search (f.c_str (), i, fb);
+ }
+
+ static process_path
+ path_search (const path& f, bool i, const dir_path& fb = dir_path ())
+ {
+ return path_search (f.string ().c_str (), i, fb);
+ }
+
public:
#ifndef _WIN32
using handle_type = pid_t;