mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:12:43 +00:00 
			
		
		
		
	LibCore: Add find_executable_in_path.
This commit is contained in:
		
							parent
							
								
									d55e3c4642
								
							
						
					
					
						commit
						3283f5bb5d
					
				
					 2 changed files with 22 additions and 0 deletions
				
			
		|  | @ -25,6 +25,7 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibCore/DirIterator.h> | ||||
| #include <AK/Vector.h> | ||||
| #include <errno.h> | ||||
| 
 | ||||
| namespace Core { | ||||
|  | @ -98,4 +99,23 @@ String DirIterator::next_full_path() | |||
|     return String::format("%s/%s", m_path.characters(), next_path().characters()); | ||||
| } | ||||
| 
 | ||||
| String find_executable_in_path(String filename) | ||||
| { | ||||
|     if (filename.starts_with('/')) { | ||||
|         if (access(filename.characters(), X_OK) == 0) | ||||
|             return filename; | ||||
| 
 | ||||
|         return {}; | ||||
|     } | ||||
| 
 | ||||
|     for (auto directory : StringView { getenv("PATH") }.split_view(':')) { | ||||
|         auto fullpath = String::format("%s/%s", directory, filename); | ||||
| 
 | ||||
|         if (access(fullpath.characters(), X_OK) == 0) | ||||
|             return fullpath; | ||||
|     } | ||||
| 
 | ||||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 asynts
						asynts