Proposing PathFileSearch: like FileSeach, working correctly for $PATH
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
As explained in #19279 (closed), the FileSearch is not the correct way on Windows to search for files on $PATH. If the FileSearch cannot be modified, I propose to add a new function designed specifically for this :) (My reasoning for pushing this is that I think it's common to want to search on $PATH, so I would like to see a correct utility for this in RTL.)
I attach a simple implementation. This is based on FileSearch implementation, adding a small piece of code to remove double quotes around. (A shorter and cleaner implementation, preprocessing the path removing double quotes, and then calling FileSearch, is possible --- but it would be slower.)
Suggested place to put it is inside rtl/objpas/sysutils/sysutils.inc, right beside FileSearch implementation.
Note that there are some places in FPC RTL when we search the environment variable $PATH, using FileSearch (or ExeSearch, which is just a wrapper around FileSearch). They could be changed to use PathFileSearch for clarity. Although they are not for Windows platform --- so they may stay using FileSearch / ExeSearch as well.
./rtl/qnx/system.pp:165: fstr:=filesearch(strpas(argv[0]), getenv('PATH'));
./src/unix/process.inc:306: FoundName := ExeSearch(Pname,fpgetenv('PATH'));
There's also one place in Lazarus where they use FileSearchUTF8 in the same maner, I guess they should fix it the same way (by introducing PathFileSearchUTF8):
./components/datadict/reglazdatadict.pp:84: Result:=FileSearchUTF8(LazDataDesktop,GetEnvironmentVariableUTF8('PATH'));
Mantis conversion info:
- Mantis ID: 19282
- Fixed in version: 2.6.0
- Fixed in revision: 17717 (#6b42ee69).
- Target version: 2.6.0