Relative path to absolute

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlannY
    New Member
    • Jan 2009
    • 4

    Relative path to absolute

    Hi there.

    I'm writing a program under Linux. I need a function that convert relative path to absolute (or full path). Under Windows, I have a GetFullPathName function in WinAPI. But now, I need function for Linux (glibc may be).

    Can someone help me?

    P.S. Googling, googling... nothing found ;-(
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    yes....
    you are after "realpath". ..
    Code:
    #include <limits.h>
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
            char resolved_path[100];
            realpath("../../", resolved_path);
            printf("\n%s\n",resolved_path);
            return 0;
    }

    Comment

    • mac11
      Contributor
      • Apr 2007
      • 256

      #3
      Another option, if you're using c++ anyway, is to use boost::filesyst em. It provides portable file system stl-like objects.

      Boost C++ Libraries

      Comment

      Working...