Wolfenstein 3D:

- Now it searches for resources only in the directory where the binary itself is located.

git-svn-id: svn://kolibrios.org@8664 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2021-04-03 00:16:38 +00:00
parent 9aefaa6765
commit db56f2e024
2 changed files with 66 additions and 0 deletions

View File

@ -1,6 +1,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "../../kolibri-libc/source/include/ksys.h" #include "../../kolibri-libc/source/include/ksys.h"
#include <string.h>
void *memrchr(const void *m, int c, size_t n)
{
const unsigned char *s = (const unsigned char*)m;
c = (unsigned char)c;
while (n--) if (s[n]==c) return (void *)(s+n);
return 0;
}
void kolibri_set_win_center() void kolibri_set_win_center()
{ {
@ -19,3 +28,54 @@ int mkdir(const char * path, unsigned)
return _ksys_mkdir(path); return _ksys_mkdir(path);
} }
char *dirname (char *path)
{
static const char dot[] = ".";
char *last_slash;
/* Find last '/'. */
last_slash = path != NULL ? strrchr (path, '/') : NULL;
if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
{
/* Determine whether all remaining characters are slashes. */
char *runp;
for (runp = last_slash; runp != path; --runp)
if (runp[-1] != '/')
break;
/* The '/' is the last character, we have to look further. */
if (runp != path)
last_slash = (char*)memrchr((void*)path, '/', runp - path);
}
if (last_slash != NULL)
{
/* Determine whether all remaining characters are slashes. */
char *runp;
for (runp = last_slash; runp != path; --runp)
if (runp[-1] != '/')
break;
/* Terminate the path. */
if (runp == path)
{
/* The last slash is the first character in the string. We have to
return "/". As a special case we have to return "//" if there
are exactly two slashes at the beginning of the string. See
XBD 4.10 Path Name Resolution for more information. */
if (last_slash == path + 1)
++last_slash;
else
last_slash = path + 1;
}
else
last_slash = runp;
last_slash[0] = '\0';
}
else
/* This assignment is ill-designed but the XPG specs require to
return a string containing "." in any case no directory part is
found and so a static and constant string is required. */
path = (char *) dot;
return path;
}
void setcwd(char* path){
_ksys_setcwd(path);
}

View File

@ -25,6 +25,8 @@
extern byte signon[]; extern byte signon[];
extern void kolibri_set_win_center(); extern void kolibri_set_win_center();
extern char* dirname(char* path);
extern void setcwd(char* path);
/* /*
============================================================================= =============================================================================
@ -1959,6 +1961,10 @@ void CheckParameters(int argc, char *argv[])
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
#ifdef _KOLIBRI
setcwd(dirname(argv[0]));
#endif
#if defined(_arch_dreamcast) #if defined(_arch_dreamcast)
DC_Init(); DC_Init();
#else #else