mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Userland: Use find_executable_in_path in which.
This commit is contained in:
parent
3283f5bb5d
commit
c577f6e139
Notes:
sideshowbarker
2024-07-19 02:22:53 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/c577f6e1398 Pull-request: https://github.com/SerenityOS/serenity/pull/3511 Reviewed-by: https://github.com/nico
@ -24,11 +24,9 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@ -43,18 +41,12 @@ int main(int argc, char** argv)
|
||||
args_parser.add_positional_argument(filename, "Name of executable", "executable");
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
String path = getenv("PATH");
|
||||
if (path.is_empty())
|
||||
path = "/bin:/usr/bin";
|
||||
|
||||
auto parts = path.split(':');
|
||||
for (auto& part : parts) {
|
||||
auto candidate = String::format("%s/%s", part.characters(), filename);
|
||||
if(access(candidate.characters(), X_OK) == 0) {
|
||||
printf("%s\n", candidate.characters());
|
||||
return 0;
|
||||
}
|
||||
auto fullpath = Core::find_executable_in_path(filename);
|
||||
if (fullpath.is_null()) {
|
||||
printf("no '%s' in path\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
printf("%s\n", fullpath.characters());
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user