mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
73fdbba59c
This was a workaround to be able to build on case-insensitive file systems where it might get confused about <string.h> vs <String.h>. Let's just not support building that way, so String.h can have an objectively nicer name. :^)
29 lines
642 B
C++
29 lines
642 B
C++
#include <AK/String.h>
|
|
#include <AK/Vector.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if (argc < 2) {
|
|
printf("usage: which <executable>\n");
|
|
return 0;
|
|
}
|
|
|
|
char* filename = argv[1];
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|