Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_splitpath in Linux

Is there a Linux equivalent of the Win32 API _splitpath function?
Details:

void _splitpath (
   const char *path,  // Path Input
   char *drive,       // Drive     : Output
   char *dir,         // Directory : Output
   char *fname,       // Filename  : Output
   char *ext          // Extension : Output
);

It takes full path as input and gives drive, directory, filename and extension as output.

like image 565
Alphaneo Avatar asked Mar 05 '09 08:03

Alphaneo


2 Answers

dirname() and basename()

like image 95
vartec Avatar answered Oct 19 '22 16:10

vartec


Not that I'm aware, no. What I'd do is:

  • Run the path through realpath(), to make it canonical
  • Just split it on the directory separator, i.e. the / character
like image 23
unwind Avatar answered Oct 19 '22 17:10

unwind