Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
730e8c5d
Commit
730e8c5d
authored
Mar 28, 2018
by
LEFEBVREJP email
Browse files
Adding search_env_path in radixcore/system.
parent
acb3f12d
Pipeline
#12768
passed with stages
in 8 minutes and 56 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixcore/system.cc
View file @
730e8c5d
...
...
@@ -366,6 +366,33 @@ bool remove_file(const std::string &path)
{
if
(
dir_exists
(
path
))
return
false
;
return
remove
(
path
.
c_str
())
==
0
;
}
// remove_file
}
std
::
string
search_env_path
(
const
std
::
string
&
filename
)
{
std
::
string
path_env
=
env
(
"PATH"
);
std
::
vector
<
std
::
string
>
list
=
split_string
(
":"
,
path_env
);
if
(
list
.
size
()
==
1
)
// we didn't split anything
{
// guess it was ':' separator, try ';'
list
=
split_string
(
";"
,
path_env
);
}
for
(
size_t
i
=
0
;
i
<
list
.
size
();
++
i
)
{
std
::
string
item
=
list
[
i
];
item
=
item
+
separator_char
();
radix_line
(
"Searching "
<<
item
<<
" for "
<<
filename
);
std
::
string
path
=
item
+
filename
;
if
(
file_exists
(
path
))
{
radix_line
(
"Found "
<<
path
);
return
path
;
}
}
radix_line
(
"Did not find "
<<
filename
<<
" on the PATH"
);
return
std
::
string
();
}
// remove_file
}
// namespace radix
radixcore/system.hh
View file @
730e8c5d
...
...
@@ -192,6 +192,13 @@ RADIX_PUBLIC bool remove_dir(const std::string &path);
*/
RADIX_PUBLIC
bool
remove_file
(
const
std
::
string
&
path
);
/**
* @brief search_env_path Search the environment variable PATH for the filename
* @param filename filename to search for
* @return The PATH prefix if the filename is found to exist or empty.
*/
RADIX_PUBLIC
std
::
string
search_env_path
(
const
std
::
string
&
filename
);
}
// namespace radix
#endif
/** RADIX_RADIXCORE_SYSTEM_HH_ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment