Fixed locale bug with MorphOS

This commit is contained in:
George Sokianos 2022-09-26 14:17:55 +01:00
parent 283f1d0837
commit 5d39b4ae68
3 changed files with 25 additions and 16 deletions

View File

@ -104,6 +104,8 @@ int main(int argc, char **argv) {
HINSTANCE lib = LoadLibrary("user32.dll"); HINSTANCE lib = LoadLibrary("user32.dll");
int (*SetProcessDPIAware)() = (void*) GetProcAddress(lib, "SetProcessDPIAware"); int (*SetProcessDPIAware)() = (void*) GetProcAddress(lib, "SetProcessDPIAware");
SetProcessDPIAware(); SetProcessDPIAware();
#elif defined(__morphos__)
setlocale(LC_ALL, "");
#else #else
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif #endif

View File

@ -6,29 +6,27 @@
#include "morphos.h" #include "morphos.h"
#define MAX_DOS_NAME FILENAME_MAX #define MAX_DOS_NAME FILENAME_MAX
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); BOOL success = GetCurrentDirName(result, sizeof(char) * MAX_DOS_NAME);
BOOL success = GetCurrentDirName(appPath, sizeof(char) * MAX_DOS_NAME);
if (!success) { if (!success) {
strncpy(appPath, "PROGDIR:", sizeof(char) * MAX_DOS_NAME); return TRUE;
} }
return appPath; return FALSE;
} }
char *_fullpath(const char *path) char *_fullpath(const char *path)
@ -46,16 +44,24 @@ 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; {
return result;
}
} }
strcpy(result, getFullPath(path)); if (getFullPath(path, result))
return result; {
return result;
}
return NULL;
} }

View File

@ -3,6 +3,7 @@
#include <proto/dos.h> #include <proto/dos.h>
#include <proto/exec.h> #include <proto/exec.h>
#include <locale.h>
char *_fullpath(const char *); char *_fullpath(const char *);