Remove Realpath() unlicensed implementation
It is probably not usefull anyway
This commit is contained in:
parent
0fc6aa12f1
commit
b9806bfbf3
@ -74,11 +74,6 @@ Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
|
|||||||
|
|
||||||
GNU GPL version 2 or later.
|
GNU GPL version 2 or later.
|
||||||
|
|
||||||
realpath.c
|
|
||||||
==========
|
|
||||||
|
|
||||||
Portions from GeekGadgets for Amiga. Copyright and license unknown.
|
|
||||||
|
|
||||||
recoil.{c,h}
|
recoil.{c,h}
|
||||||
============
|
============
|
||||||
|
|
||||||
|
|||||||
8
src/io.c
8
src/io.c
@ -342,7 +342,7 @@ char * Extract_path(const char *source)
|
|||||||
char * position;
|
char * position;
|
||||||
char * path;
|
char * path;
|
||||||
|
|
||||||
path = Realpath(source, NULL);
|
path = Realpath(source);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
GFX2_Log(GFX2_ERROR, "Realpath(\"%s\") failed !\n", source);
|
GFX2_Log(GFX2_ERROR, "Realpath(\"%s\") failed !\n", source);
|
||||||
@ -603,7 +603,7 @@ void For_each_file(const char * directory_name, void Callback(const char *, cons
|
|||||||
char * search_string;
|
char * search_string;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
|
|
||||||
full_filename = Realpath(directory_name, NULL);
|
full_filename = Realpath(directory_name);
|
||||||
search_string = Filepath_append_to_dir((full_filename != NULL) ? full_filename : directory_name, "*");
|
search_string = Filepath_append_to_dir((full_filename != NULL) ? full_filename : directory_name, "*");
|
||||||
free(full_filename);
|
free(full_filename);
|
||||||
h = FindFirstFileA(search_string, &fd);
|
h = FindFirstFileA(search_string, &fd);
|
||||||
@ -1151,10 +1151,10 @@ char * Calculate_relative_path(const char * ref_path, const char * path)
|
|||||||
|
|
||||||
if (ref_path == NULL || path == NULL)
|
if (ref_path == NULL || path == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
real_ref_path = Realpath(ref_path, NULL);
|
real_ref_path = Realpath(ref_path);
|
||||||
if (real_ref_path == NULL)
|
if (real_ref_path == NULL)
|
||||||
real_ref_path = strdup(ref_path);
|
real_ref_path = strdup(ref_path);
|
||||||
real_path = Realpath(path, NULL);
|
real_path = Realpath(path);
|
||||||
if (real_path == NULL)
|
if (real_path == NULL)
|
||||||
real_path = strdup(path);
|
real_path = strdup(path);
|
||||||
#if defined(WIN32) || defined(__MINT__)
|
#if defined(WIN32) || defined(__MINT__)
|
||||||
|
|||||||
@ -536,7 +536,7 @@ int Analyze_command_line(int argc, char * argv[], char * filenames[], char * dir
|
|||||||
}
|
}
|
||||||
else if (File_exists(argv[index]))
|
else if (File_exists(argv[index]))
|
||||||
{
|
{
|
||||||
buffer = Realpath(argv[index], NULL);
|
buffer = Realpath(argv[index]);
|
||||||
filename = Find_last_separator(buffer);
|
filename = Find_last_separator(buffer);
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -998,7 +998,7 @@ int Load_INI(T_Config * conf)
|
|||||||
if (conf->Scripts_directory == NULL)
|
if (conf->Scripts_directory == NULL)
|
||||||
{
|
{
|
||||||
// Default when empty:
|
// Default when empty:
|
||||||
char * path = Realpath(Data_directory, NULL);
|
char * path = Realpath(Data_directory);
|
||||||
conf->Scripts_directory = Filepath_append_to_dir(path, SCRIPTS_SUBDIRECTORY);
|
conf->Scripts_directory = Filepath_append_to_dir(path, SCRIPTS_SUBDIRECTORY);
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|||||||
118
src/realpath.c
118
src/realpath.c
@ -17,115 +17,21 @@
|
|||||||
|
|
||||||
#if defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__) || defined(__WIZ__) || defined(__CAANOO__) || defined(__amigaos__) || defined(__SWITCH__)
|
#if defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__) || defined(__WIZ__) || defined(__CAANOO__) || defined(__amigaos__) || defined(__SWITCH__)
|
||||||
// These platforms don't have realpath().
|
// These platforms don't have realpath().
|
||||||
// We use the following implementation, found in:
|
char *Realpath(const char *_path)
|
||||||
// http://amiga.sourceforge.net/amigadevhelp/FUNCTIONS/GeekGadgets/realpath/ex02_realpath.c
|
{
|
||||||
//
|
return strdup(_path);
|
||||||
// When tested on Debian, this piece of code doesn't resolve
|
}
|
||||||
// symbolic link in the filename itself, only on the directories in
|
|
||||||
// the path. So this implementation is limited, it's really better to
|
|
||||||
// use realpath() if your platform has it.
|
|
||||||
|
|
||||||
#if !defined(PATH_MAX)
|
|
||||||
// This is a random default value ...
|
|
||||||
#define PATH_MAX 4096
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static char *sep(char *path)
|
|
||||||
{
|
|
||||||
char *tmp, c;
|
|
||||||
|
|
||||||
tmp = strrchr(path, '/');
|
|
||||||
if(tmp) {
|
|
||||||
c = tmp[1];
|
|
||||||
tmp[1] = 0;
|
|
||||||
if (chdir(path)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
tmp[1] = c;
|
|
||||||
|
|
||||||
return tmp + 1;
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the real path of _path by chdir to it and then getcwd.
|
|
||||||
// If resolved_path is null, it is allocated.
|
|
||||||
char *Realpath(const char *_path, char *resolved_path)
|
|
||||||
{
|
|
||||||
#if defined(__AROS__)
|
|
||||||
int fd = open("", O_RDONLY); // GrafX2 is compiled without Unix support
|
|
||||||
#else
|
|
||||||
int fd = open(".", O_RDONLY);
|
|
||||||
#endif
|
|
||||||
int l;
|
|
||||||
char current_dir_path[PATH_MAX];
|
|
||||||
char path[PATH_MAX], lnk[PATH_MAX], *tmp = (char *)"";
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
getcwd(current_dir_path,PATH_MAX);
|
|
||||||
strncpy(path, _path, PATH_MAX);
|
|
||||||
|
|
||||||
if (chdir(path)) {
|
|
||||||
if (errno == ENOTDIR) {
|
|
||||||
#if defined(__MORPHOS__) || defined(__amigaos__) || defined(__SWITCH__)
|
|
||||||
// No symbolic links and no readlink()
|
|
||||||
l = -1;
|
|
||||||
#else
|
|
||||||
l = readlink(path, lnk, PATH_MAX);
|
|
||||||
#endif
|
|
||||||
if (!(tmp = sep(path))) {
|
|
||||||
resolved_path = NULL;
|
|
||||||
goto abort;
|
|
||||||
}
|
|
||||||
if (l < 0) {
|
|
||||||
if (errno != EINVAL) {
|
|
||||||
resolved_path = NULL;
|
|
||||||
goto abort;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lnk[l] = 0;
|
|
||||||
if (!(tmp = sep(lnk))) {
|
|
||||||
resolved_path = NULL;
|
|
||||||
goto abort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolved_path = NULL;
|
|
||||||
goto abort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(resolved_path==NULL) // if we called realpath with null as a 2nd arg
|
|
||||||
resolved_path = (char*) malloc( PATH_MAX );
|
|
||||||
|
|
||||||
if (!getcwd(resolved_path, PATH_MAX)) {
|
|
||||||
resolved_path = NULL;
|
|
||||||
goto abort;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strcmp(resolved_path, "/") && *tmp) {
|
|
||||||
strcat(resolved_path, "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(resolved_path, tmp);
|
|
||||||
abort:
|
|
||||||
chdir(current_dir_path);
|
|
||||||
close(fd);
|
|
||||||
return resolved_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(__WIN32__) || defined(WIN32)
|
#elif defined(__WIN32__) || defined(WIN32)
|
||||||
// Mingw has a working equivalent. It only has reversed arguments.
|
// MSVC / Mingw has a working equivalent. It only has reversed arguments.
|
||||||
char *Realpath(const char *_path, char *resolved_path)
|
char *Realpath(const char *_path)
|
||||||
{
|
{
|
||||||
return _fullpath(resolved_path,_path,260);
|
return _fullpath(NULL, _path, 260);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Use the stdlib function.
|
// Use the stdlib function.
|
||||||
char *Realpath(const char *_path, char *resolved_path)
|
char *Realpath(const char *_path)
|
||||||
{
|
{
|
||||||
/// POSIX 2004 states :
|
/// POSIX 2004 states :
|
||||||
/// If resolved_name is a null pointer, the behavior of realpath()
|
/// If resolved_name is a null pointer, the behavior of realpath()
|
||||||
@ -139,14 +45,12 @@
|
|||||||
/// So we assume all platforms now support passing NULL.
|
/// So we assume all platforms now support passing NULL.
|
||||||
/// If you find a platform where this is not the case,
|
/// If you find a platform where this is not the case,
|
||||||
/// please add a new implementation with ifdef's.
|
/// please add a new implementation with ifdef's.
|
||||||
|
char * resolved_path = NULL;
|
||||||
#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
||||||
// realpath() accept NULL as 2nd argument since OSX 10.6
|
// realpath() accept NULL as 2nd argument since OSX 10.6
|
||||||
if (resolved_path == NULL)
|
|
||||||
{
|
|
||||||
resolved_path = GFX2_malloc(PATH_MAX);
|
resolved_path = GFX2_malloc(PATH_MAX);
|
||||||
if (resolved_path == NULL)
|
if (resolved_path == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
return realpath(_path, resolved_path);
|
return realpath(_path, resolved_path);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,6 @@
|
|||||||
/// @param _path Input path
|
/// @param _path Input path
|
||||||
/// @param resolved_path Output path, allocated by caller
|
/// @param resolved_path Output path, allocated by caller
|
||||||
/// @return (points to resolved_path)
|
/// @return (points to resolved_path)
|
||||||
char *Realpath(const char *_path, char *resolved_path);
|
char *Realpath(const char *_path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -308,7 +308,7 @@ int Test_Realpath(char * errmsg)
|
|||||||
{
|
{
|
||||||
char * path;
|
char * path;
|
||||||
|
|
||||||
path = Realpath(tmpdir, NULL);
|
path = Realpath(tmpdir);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
snprintf(errmsg, ERRMSG_LENGTH, "Realpath(\"%s\") returned NULL", tmpdir);
|
snprintf(errmsg, ERRMSG_LENGTH, "Realpath(\"%s\") returned NULL", tmpdir);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user