mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 20:10:29 +01:00
WINGs: fix WMPathForResourceOfType to check for all the paths it claims to check
The "documentation" of the function claims to check for the resource in a number of path, but factually if the application did provide its argument list when creating the WINGs App structure (which is likely) then the search would stop before checking all paths. The code now continues as expectable if the resource was not found in the path. Took opportunity to avoid a temporary allocation that participated in memory fragmentation. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
4f050ebab9
commit
b80118fb41
@@ -131,11 +131,10 @@ error:
|
||||
|
||||
char *WMPathForResourceOfType(const char *resource, const char *ext)
|
||||
{
|
||||
char *path, *tmp, *appdir;
|
||||
int i;
|
||||
char *path, *appdir;
|
||||
size_t slen;
|
||||
|
||||
path = tmp = appdir = NULL;
|
||||
path = appdir = NULL;
|
||||
|
||||
/*
|
||||
* Paths are searched in this order:
|
||||
@@ -156,17 +155,19 @@ char *WMPathForResourceOfType(const char *resource, const char *ext)
|
||||
}
|
||||
|
||||
if (WMApplication.argv[0]) {
|
||||
tmp = wstrdup(WMApplication.argv[0]);
|
||||
i = strlen(tmp);
|
||||
while (i > 0 && tmp[i] != '/')
|
||||
i--;
|
||||
tmp[i] = 0;
|
||||
if (i > 0) {
|
||||
char *ptr_slash;
|
||||
|
||||
ptr_slash = strrchr(WMApplication.argv[0], '/');
|
||||
if (ptr_slash != NULL) {
|
||||
char tmp[ptr_slash - WMApplication.argv[0] + 1];
|
||||
|
||||
strncpy(tmp, WMApplication.argv[0], sizeof(tmp)-1);
|
||||
tmp[sizeof(tmp) - 1] = '\0';
|
||||
|
||||
path = checkFile(tmp, NULL, ext, resource);
|
||||
} else {
|
||||
path = NULL;
|
||||
if (path)
|
||||
goto out;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
slen = strlen(WMApplication.applicationName) + sizeof("Applications/.app");
|
||||
@@ -197,8 +198,6 @@ char *WMPathForResourceOfType(const char *resource, const char *ext)
|
||||
path = checkFile("/usr/GNUstep", appdir, ext, resource); /* falls through */
|
||||
|
||||
out:
|
||||
if (tmp)
|
||||
wfree(tmp);
|
||||
if (appdir)
|
||||
wfree(appdir);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user