From 9635692214cc6c3d19578bcadac4da68e0742740 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 25 Aug 2016 09:36:18 +0200 Subject: Add process::try_path_search() --- butl/process.cxx | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'butl/process.cxx') diff --git a/butl/process.cxx b/butl/process.cxx index 37e9f72..ed26eb9 100644 --- a/butl/process.cxx +++ b/butl/process.cxx @@ -32,6 +32,8 @@ # include #endif +#include + #include #include // size_t #include // strlen(), strchr() @@ -96,12 +98,24 @@ namespace butl process_path process:: path_search (const char* f, bool init, const dir_path& fb) { + process_path r (try_path_search (f, init, fb)); + + if (r.empty ()) + throw process_error (ENOENT, false); + + return r; + } + + process_path process:: + try_path_search (const char* f, bool init, const dir_path& fb) + { process_path r (butl::path_search (f, fb)); - path& rp (r.recall); - r.initial = init - ? f - : (rp.empty () ? (rp = path (f)) : rp).string ().c_str (); + if (!init && !r.empty ()) + { + path& rp (r.recall); + r.initial = (rp.empty () ? (rp = path (f)) : rp).string ().c_str (); + } return r; } @@ -117,7 +131,7 @@ namespace butl size_t fn (strlen (f)); - process_path r (nullptr, path (), path ()); + process_path r (f, path (), path ()); // Make sure it is not empty. path& rp (r.recall); path& ep (r.effect); @@ -190,7 +204,7 @@ namespace butl // Did not find anything. // - throw process_error (ENOENT, false); + return process_path (); } process:: @@ -378,7 +392,7 @@ namespace butl ext = (e == nullptr || casecmp (e, ".exe") != 0); } - process_path r (nullptr, path (), path ()); + process_path r (f, path (), path ()); // Make sure it is not empty. path& rp (r.recall); path& ep (r.effect); @@ -519,7 +533,7 @@ namespace butl // Did not find anything. // - throw process_error (ENOENT); + return process_path (); } class auto_handle -- cgit v1.1