8
#if defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__) || defined(__amigaos__)
9
// These platforms don't have realpath().
10
// We use the following implementation, found in:
11
// http://amiga.sourceforge.net/amigadevhelp/FUNCTIONS/GeekGadgets/realpath/ex02_realpath.c
13
// When tested on Debian, this piece of code doesn't resolve
14
// symbolic link in the filename itself, only on the directories in
15
// the path. So this implementation is limited, it's really better to
16
// use realpath() if your platform has it.
19
// This is a random default value ...
20
#define PATH_MAX 32768
23
static char *sep(char *path)
27
tmp = strrchr(path, '/');
41
char *Realpath(const char *_path, char *resolved_path)
43
int fd = open(".", O_RDONLY), l;
44
char current_dir_path[PATH_MAX];
45
char path[PATH_MAX], lnk[PATH_MAX], *tmp = (char *)"";
50
getcwd(current_dir_path,PATH_MAX);
51
strncpy(path, _path, PATH_MAX);
54
if (errno == ENOTDIR) {
55
#if defined(__WIN32__) || defined(__MORPHOS__) || defined(__amigaos__)
56
// No symbolic links and no readlink()
59
l = readlink(path, lnk, PATH_MAX);
61
if (!(tmp = sep(path))) {
66
if (errno != EINVAL) {
72
if (!(tmp = sep(lnk))) {
83
if(resolved_path==NULL) // if we called realpath with null as a 2nd arg
84
resolved_path = (char*) malloc( PATH_MAX );
86
if (!getcwd(resolved_path, PATH_MAX)) {
91
if(strcmp(resolved_path, "/") && *tmp) {
92
strcat(resolved_path, "/");
95
strcat(resolved_path, tmp);
97
chdir(current_dir_path);
102
#elif defined (__WIN32__)
103
// Mingw has a working equivalent. It only has reversed arguments.
104
char *Realpath(const char *_path, char *resolved_path)
106
return _fullpath(resolved_path,_path,260);
109
// Use the stdlib function.
110
char *Realpath(const char *_path, char *resolved_path)
112
return realpath(_path, resolved_path);