8

Is there any standard (or widely used) simple POSIX path manipulation library for C (path join, filename stripping, etc.) ?

Actually, because I'm mostly working under Windows, I currently use 'shlwapi' path functions.

Is there any equivalent set of functions available for POSIX paths?

Matt
  • 14,906
  • 27
  • 99
  • 149
rotoglup
  • 5,223
  • 25
  • 37
  • 2
    Offhand: Since multiple `/` don't hurt anything, and there is no such thing as an “extension” in POSIX systems, a lot of those methods aren't significant… you can usually get by with string manipulation, and `realpath` or `glob`. Not technically an answer to what you were asking, though… :-) – BRPocock Jan 17 '12 at 20:10
  • 3
    @BRPocock: Multiple `/`es aren't always safe - eg in [kpathsea](http://tug.org/texinfohtml/kpathsea.html), `/foo//` expands to all subdirectories under `/foo` (which can be extremely difficult to track down, if you're passing a path to something that uses kpathsea internally - such as latex). – Timothy Jones Jan 18 '12 at 00:43
  • @timothy Jones ... true, although in my world relatively rare ... but realpath does correct that, as well as symlinks... as does, in its way, glob. – BRPocock Jan 18 '12 at 06:18

1 Answers1

11
  • path join - snprintf()
  • filename stripping - dirname()
  • etc. - basename(), realpath(), readlink(), glob(), fnmatch()...
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Thanks, this is the kind of functions I had in mind. Do you happen to know an online list of those, like an equivalent of the msdn page I linked ? – rotoglup Jan 18 '12 at 07:18
  • Just asking, I already tried to google this, but failed to find any synthetic information ; the noise/signal ratio is quite high as these function also exist in PHP, Ruby, etc. Anyways... – rotoglup Jan 19 '12 at 13:33
  • Thanks for the link, it seems that some functions such as 'basename()' are in this manual in the section 'Finding Tokens in a String'... – rotoglup Jan 19 '12 at 16:18
  • @rotoglup "man snprintf" should have all the information you need. :) – WhyNotHugo Apr 04 '12 at 21:07