Extract base path from a pathname in C

Question

How do you extract the base path from pathname in C?

Are there any functions built into the C language or the C-Runtime Library to extract the base path from a pathname in C?

I'm asking basically the opposite of this question.

NOTE: I prefer a cross-platform solution, but I'm working in Windows so if there is a Windows API call that does this, I'd still like to know.

Examples

Input              | Output
---------------------------------
C:\path\to\file   -> C:\path\to\
C:\path\to\file.c -> C:\path\to\
C:\file           -> C:\
.\file            -> .\
.\                -> .\
\                 -> \

References

6
задан Community 23 May 2017 в 12:02
поделиться