Fixes r727 not compiling on windows,

Fixes an old issue on Linux where the program couldn't be run from a symbolic to the executable.


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@743 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-04-07 21:53:20 +00:00
parent 19ac89a38f
commit c98bfafb76
5 changed files with 86 additions and 69 deletions

View File

@ -23,13 +23,13 @@ $(OBJDIR)/init.o: init.c const.h struct.h global.h graph.h buttons.h palette.h \
windows.h sdlscreen.h mountlist.h loadsave.h
$(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h sdlscreen.h \
windows.h errors.h misc.h input.h
$(OBJDIR)/io.o: io.c struct.h const.h io.h
$(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.h
$(OBJDIR)/keyboard.o: keyboard.c global.h struct.h const.h
$(OBJDIR)/loadsave.o: loadsave.c const.h struct.h global.h misc.h pages.h op_c.h \
buttons.h errors.h io.h sdlscreen.h windows.h loadsave.h
$(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h errors.h global.h io.h \
loadsave.h misc.h op_c.h pages.h palette.h sdlscreen.h windows.h
$(OBJDIR)/main.o: main.c const.h struct.h global.h graph.h misc.h init.h buttons.h \
engine.h pages.h loadsave.h sdlscreen.h errors.h readini.h saveini.h \
io.h text.h setup.h windows.h brush.h palette.h
io.h text.h setup.h windows.h brush.h palette.h realpath.h
$(OBJDIR)/misc.o: misc.c struct.h const.h sdlscreen.h global.h errors.h buttons.h \
engine.h misc.h keyboard.h windows.h palette.h input.h
$(OBJDIR)/mountlist.o: mountlist.c
@ -58,7 +58,8 @@ $(OBJDIR)/setup.o: setup.c struct.h const.h io.h
$(OBJDIR)/shade.o: shade.c global.h struct.h const.h graph.h engine.h misc.h \
readline.h help.h sdlscreen.h windows.h input.h
$(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h
$(OBJDIR)/text.o: text.c SFont.h struct.h const.h global.h sdlscreen.h io.h
$(OBJDIR)/text.o: text.c SFont.h struct.h const.h global.h sdlscreen.h io.h \
errors.h
$(OBJDIR)/version.o: version.c
$(OBJDIR)/windows.o: windows.c windows.h struct.h const.h global.h graph.h engine.h \
misc.h sdlscreen.h errors.h

3
io.c
View File

@ -39,6 +39,7 @@
#include "struct.h"
#include "io.h"
#include "realpath.h"
word Endian_magic16(word x)
{
@ -196,7 +197,7 @@ void Extract_path(char *dest, const char *source)
{
char * position=NULL;
realpath(source,dest);
Realpath(source,dest);
position = Find_last_slash(dest);
if (position)
*(position+1) = '\0';

10
main.c
View File

@ -51,6 +51,7 @@
#include "windows.h"
#include "brush.h"
#include "palette.h"
#include "realpath.h"
#if defined(__WIN32__)
#include <windows.h>
@ -61,10 +62,9 @@
#import <sys/param.h>
#elif defined(__FreeBSD__)
#import <sys/param.h>
#elif defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__)
#include "realpath.h"
#endif
#if defined (__WIN32__)
// On Windows, SDL_putenv is not present in any compilable header.
// It can be linked anyway, this declaration only avoids
@ -271,11 +271,7 @@ void Analyze_command_line(int argc,char * argv[])
// On récupère le chemin complet du paramètre
// Et on découpe ce chemin en répertoire(path) + fichier(.ext)
#if defined(__WIN32__)
buffer=_fullpath(NULL,argv[index],MAX_PATH_CHARACTERS);
#else
buffer=realpath(argv[index],NULL);
#endif
buffer=Realpath(argv[index],NULL);
Extract_path(Main_file_directory, buffer);
Extract_filename(Main_filename, buffer);
free(buffer);

View File

@ -1,7 +1,3 @@
/* Found in:
http://amiga.sourceforge.net/amigadevhelp/FUNCTIONS/GeekGadgets/realpath/ex02_realpath.c
*/
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
@ -9,83 +5,91 @@
#include <string.h>
#include <unistd.h>
#if defined(__GP2X__)
// This is a random default value ...
#define PATH_MAX 32768
#endif
#if defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__)
// These platforms don't have realpath().
// We use the following implementation, found in:
// http://amiga.sourceforge.net/amigadevhelp/FUNCTIONS/GeekGadgets/realpath/ex02_realpath.c
//
// 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.
static char *sep(char *path)
{
#if defined(__GP2X__)
// This is a random default value ...
#define PATH_MAX 32768
#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;
c = tmp[1];
tmp[1] = 0;
if (chdir(path)) {
return NULL;
}
tmp[1] = c;
return tmp + 1;
return tmp + 1;
}
return path;
}
}
char *realpath(const char *_path, char *resolved_path)
{
char *Realpath(const char *_path, char *resolved_path)
{
int fd = open(".", O_RDONLY), l;
char current_dir_path[PATH_MAX];
char path[PATH_MAX], lnk[PATH_MAX], *tmp = (char *)"";
if (fd < 0) {
return NULL;
return NULL;
}
getcwd(current_dir_path,PATH_MAX);
strncpy(path, _path, PATH_MAX);
if (chdir(path)) {
if (errno == ENOTDIR) {
#if defined(__WIN32__) || defined(__MORPHOS__)
// 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 {
if (errno == ENOTDIR) {
#if defined(__WIN32__) || defined(__MORPHOS__)
// 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 );
resolved_path = (char*) malloc( PATH_MAX );
if (!getcwd(resolved_path, PATH_MAX)) {
resolved_path = NULL;
goto abort;
resolved_path = NULL;
goto abort;
}
if(strcmp(resolved_path, "/") && *tmp) {
strcat(resolved_path, "/");
strcat(resolved_path, "/");
}
strcat(resolved_path, tmp);
@ -93,5 +97,20 @@ char *realpath(const char *_path, char *resolved_path)
chdir(current_dir_path);
close(fd);
return resolved_path;
}
}
#elif defined (__WIN32__)
// Mingw has a working equivalent. It only has reversed arguments.
char *Realpath(const char *_path, char *resolved_path)
{
return _fullpath(resolved_path,_path,260);
}
#else
// Use the stdlib function.
char *Realpath(const char *_path, char *resolved_path)
{
return realpath(_path, resolved_path);
}
#endif

View File

@ -1,6 +1,6 @@
#ifndef _REALPATH_H
#define _REALPATH_H
char *realpath(const char *_path, char *resolved_path);
char *Realpath(const char *_path, char *resolved_path);
#endif