views:

939

answers:

3

Is there a linux equivalent of the win32 API _splitpath in linux?

Details added:

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 give drive, dir, fname and ext as output.

+4  A: 

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
unwind
+3  A: 

dirname() and basename()

vartec
A: 

Use dirname() and basename()