Is there a POSIX function that searches PATH
for an executable according to the POSIX spec's description of the PATH
environment variable and returns the absolute path to the executable?
If not, is there a simple, safe, standard, and reliable way to search PATH
?
Edit:
glibc's execvpe()
function does its own PATH
search, so I'm guessing there isn't a specific PATH
search function defined by the standard.
Edit 2: I don't want to copy someone else's code or implement the PATH
search myself for a few reasons:
PATH
is unset or is set to null, the path search is implementation-defined." I would like the behavior in these cases to be consistent with whatever the system does, but I can't do this if there's not a standard function I can call.Is there a POSIX function that searches PATH for an executable according to the POSIX spec's description of the PATH environment variable and returns the absolute path to the executable?
No.
If not, is there a simple, safe, standard, and reliable way to search PATH?
Yes and no. Yes, there is a standard for the format of PATH
, from which the correctness/reliability of implementations follow.
No, there is no standard function that does this. Copying code is your best bet.
If
PATH
is unset or is set to null, the path search is implementation-defined.
That means you can't always portably replicate what execvp
does, but searching /bin:/usr/bin
is a pretty safe bet. Alternatively, just raise an error in this case.
(I admit that it would have been nice if POSIX had had this function, but it just isn't there.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With