you can use: fcntl
's F_GETPATH
code:
#include <sys/syslimits.h>
#include <fcntl.h>
const char* curDir = "/private/var/mobile/Library/“;
int curDirFd = open(curDir, O_RDONLY);
// for debug: get file path from fd
char filePath[PATH_MAX];
int fcntlRet = fcntl(curDirFd, F_GETPATH, filePath);
const int FCNTL_FAILED = -1;
if (fcntlRet != FCNTL_FAILED){
NSLog(@"fcntl OK: curDirFd=%d -> filePath=%s", curDirFd, filePath);
} else {
NSLog(@"fcntl fail for curDirFd=%d", curDirFd);
}
output:
curDir=/private/./var/../var/mobile/Library/./ -> curDirFd=4
fcntl OK: curDirFd=4 -> filePath=/private/var/mobile/Library
refer: another post