title: c++ - resolve all symbolic links defined in a file path
body: <h2>Short version</h2>
  
  <p>how do I get a resolved path from a path that one of its dirs are symbolic link:</p>
  
  <p>example:</p>
  
  <p>Say path = /x/y/d/f1 where y is a symbolic link to /a/b</p>
  
  <p>so the result of resolved file path would be:
  /x/a/b/d/f1</p>
  
  <h2>Long version</h2>
  
  <p>I'd like to write a c++ function that copy files from dir1 to dir2 (of course this is not the actual issue but a reduction of bigger and more complex problem). </p>
  
  <p>Prior to the copy process I'd like to remove all files in dir2 that are going to be copied from dir1.
  Say I have:</p>
  
  <ul>
  <li>Dir1 = /a/b/c/d</li>
  <li>Dir2 = /x/y/d/</li>
  </ul>
  
  <p>Assume I have file 'f1' in dir1 and file 'f1' in dir2, so my process would do:</p>
  
  <ol>
  <li>remove /x/y/d/f1</li>
  <li>copy /a/b/c/d/f1 to /x/y/d/f1</li>
  </ol>
  
  <p>My problem is the following:</p>
  
  <p>Say dir 'y' is a symbolic link to /a/b/c/. 
  Now when I remove /x/y/d/f1, I am actually removing /a/b/c/d/f1.
  (my example may have holes in it, but I hopw you get the idea)</p>
  
  <p>I'd like to avoid this, meaning, when I come to remove /x/y/d/f1 I want to be able to know that I'll be removing /x/y/d/f1 and skip that remove</p>
  
  <p>I tried using POSIX readlink() function but it only works when the file 'f1' itself is a symbolic link BUT does not work when one of its parent dirs is a symbolic link.</p>
  
  <p>Any ideas?</p>