1998-09-29 22:36:29 +00:00
|
|
|
/*
|
1998-10-21 14:43:47 +00:00
|
|
|
* Window Maker miscelaneous function library
|
2004-10-12 21:28:27 +00:00
|
|
|
*
|
2003-01-16 23:30:45 +00:00
|
|
|
* Copyright (c) 1997-2003 Alfredo K. Kojima
|
2004-10-12 21:28:27 +00:00
|
|
|
*
|
1998-09-29 22:36:29 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2013-01-07 21:51:05 +01:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
|
|
|
* MA 02110-1301, USA.
|
1998-09-29 22:36:29 +00:00
|
|
|
*/
|
|
|
|
|
|
2001-07-23 20:31:32 +00:00
|
|
|
#include "wconfig.h"
|
|
|
|
|
|
1998-09-29 22:36:29 +00:00
|
|
|
#include "WUtil.h"
|
|
|
|
|
|
2014-11-15 19:40:30 +01:00
|
|
|
#include <sys/types.h>
|
2012-01-15 05:54:34 +00:00
|
|
|
#include <sys/stat.h>
|
2014-11-15 19:40:30 +01:00
|
|
|
#include <fcntl.h>
|
2007-02-18 14:48:33 +01:00
|
|
|
#include <errno.h>
|
2012-01-15 05:54:34 +00:00
|
|
|
#include <stdio.h>
|
1998-09-29 22:36:29 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
|
|
|
2013-05-04 15:43:22 +02:00
|
|
|
char *wfindfileinarray(WMPropList *array, const char *file)
|
1999-03-14 22:35:50 +00:00
|
|
|
{
|
2009-08-20 00:59:40 +02:00
|
|
|
int i;
|
|
|
|
|
char *path;
|
|
|
|
|
int len, flen;
|
|
|
|
|
char *fullpath;
|
|
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (*file == '/' || *file == '~' || !array) {
|
|
|
|
|
if (access(file, F_OK) < 0) {
|
|
|
|
|
fullpath = wexpandpath(file);
|
|
|
|
|
if (!fullpath)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (access(fullpath, F_OK) < 0) {
|
|
|
|
|
wfree(fullpath);
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
|
|
|
|
return fullpath;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return wstrdup(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flen = strlen(file);
|
|
|
|
|
for (i = 0; i < WMGetPropListItemCount(array); i++) {
|
|
|
|
|
WMPropList *prop;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
prop = WMGetFromPLArray(array, i);
|
|
|
|
|
if (!prop)
|
|
|
|
|
continue;
|
|
|
|
|
p = WMGetFromPLString(prop);
|
|
|
|
|
|
|
|
|
|
len = strlen(p);
|
|
|
|
|
path = wmalloc(len + flen + 2);
|
|
|
|
|
path = memcpy(path, p, len);
|
|
|
|
|
path[len] = 0;
|
2010-09-28 22:25:44 +02:00
|
|
|
if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
|
|
|
|
|
wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
|
|
|
|
|
wfree(path);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2009-08-20 00:59:40 +02:00
|
|
|
/* expand tilde */
|
|
|
|
|
fullpath = wexpandpath(path);
|
|
|
|
|
wfree(path);
|
|
|
|
|
if (fullpath) {
|
|
|
|
|
/* check if file exists */
|
|
|
|
|
if (access(fullpath, F_OK) == 0) {
|
|
|
|
|
return fullpath;
|
|
|
|
|
}
|
|
|
|
|
wfree(fullpath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
1999-03-14 22:35:50 +00:00
|
|
|
}
|