Fixed non existing path crashes on OS4

This commit is contained in:
George Sokianos 2022-08-01 18:08:23 +01:00
parent 69bd81188b
commit 32eeb07c54
3 changed files with 29 additions and 16 deletions

1
.gitignore vendored
View File

@ -23,4 +23,5 @@ lite
*.lha *.lha
release_files release_files
*.o *.o
*.snalyzerinfo

View File

@ -195,6 +195,10 @@ https://git.walkero.gr/walkero/lite-xl/issues
# Changelog # Changelog
## [2.0.3r3] - future
### Fixed
- Fixed non existing path crashes on OS4
## [2.0.3r2] - 2022-06-18 ## [2.0.3r2] - 2022-06-18
### Added ### Added
- First public MorphOS version released - First public MorphOS version released

View File

@ -5,30 +5,29 @@
#include "amigaos4.h" #include "amigaos4.h"
static char *getFullPath(const char *path) static BOOL getFullPath(const char *path, char *result)
{ {
char *appPath = malloc(sizeof(char) * MAX_DOS_NAME);
BPTR pathLock = Lock(path, SHARED_LOCK); BPTR pathLock = Lock(path, SHARED_LOCK);
if (pathLock) if (pathLock)
{ {
NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME); NameFromLock(pathLock, result, sizeof(char) * MAX_DOS_NAME);
UnLock(pathLock); UnLock(pathLock);
return appPath; return TRUE;
} }
return NULL;
return FALSE;
} }
static char *getCurrentPath(void) static BOOL getCurrentPath(char *result)
{ {
char *appPath = malloc(sizeof(char) * MAX_DOS_NAME);
BPTR pathLock = GetCurrentDir(); BPTR pathLock = GetCurrentDir();
if (pathLock) if (pathLock)
{ {
NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME); NameFromLock(pathLock, result, sizeof(char) * MAX_DOS_NAME);
return appPath; return TRUE;
} }
return NULL; return FALSE;
} }
char *_fullpath(const char *path) char *_fullpath(const char *path)
@ -46,16 +45,25 @@ char *_fullpath(const char *path)
if (!strcmp(path, "./lite")) if (!strcmp(path, "./lite"))
{ {
// TODO: Add code to get the name of the executable // TODO: Add code to get the name of the executable
strcpy(result, getFullPath("PROGDIR:lite")); if (getFullPath("PROGDIR:lite", result))
return result; {
return result;
}
} }
if (!strcmp(path, ".")) if (!strcmp(path, "."))
{ {
strcpy(result, getCurrentPath()); if(getCurrentPath(result))
{
return result;
}
}
if (getFullPath(path, result))
{
return result; return result;
} }
strcpy(result, getFullPath(path)); return NULL;
return result;
} }