13 #if defined(HAVE_FNMATCH_H)
16 #if defined(__LCLINT__)
18 extern int fnmatch (
const char *__pattern,
const char *__name,
int __flags)
24 #if defined(HAVE_GLOB_H)
27 #if defined(__LCLINT__)
29 extern int glob (
const char *__pattern,
int __flags,
30 int (*__errfunc) (
const char *,
int),
36 extern void globfree ( glob_t *__pglob)
40 extern int glob_pattern_p (
const char *__pattern,
int __quote)
45 #if !defined(__GLIBC__)
49 glob_pattern_p (
const char * pattern,
int quote)
55 for (p = pattern; *p !=
'\0'; ++p)
62 if (quote && p[1] !=
'\0')
78 static int poptGlobFlags = 0;
80 static int poptGlob_error(
UNUSED(
const char * epath),
97 int * acp,
const char *** avp)
100 const char * pat = pattern;
104 if (pat[0] ==
'@' && pat[1] !=
'(')
107 #if defined(HAVE_GLOB_H)
108 if (glob_pattern_p(pat, 0)) {
109 glob_t _g, *pglob = &_g;
111 if (!glob(pat, poptGlobFlags, poptGlob_error, pglob)) {
113 *acp = (int) pglob->gl_pathc;
118 *avp = (
const char **) pglob->gl_pathv;
120 pglob->gl_pathv = NULL;
132 if (avp && (*avp = calloc((
size_t)(1 + 1),
sizeof (**avp))) != NULL)
144 uid_t uid = getuid();
146 if (stat(fn, &sb) == -1)
148 if ((uid_t)sb.st_uid != uid)
150 if (!S_ISREG(sb.st_mode))
153 if (sb.st_mode & (S_IWGRP|S_IWOTH))
167 fdno = open(fn, O_RDONLY);
171 if ((nb = lseek(fdno, 0, SEEK_END)) == (off_t)-1
172 || lseek(fdno, 0, SEEK_SET) == (off_t)-1
173 || (b = calloc(
sizeof(*b), (
size_t)nb + 1)) == NULL
174 || read(fdno, (
char *)b, (
size_t)nb) != (ssize_t)nb)
181 if (close(fdno) == -1)
194 for (t = b, s = b, se = b + nb; *s && s < se; s++) {
244 if (con == NULL || con->
appName == NULL)
247 #if defined(HAVE_GLOB_H) && defined(HAVE_FNMATCH_H)
248 if (glob_pattern_p(s, 1)) {
250 static int flags = FNM_PATHNAME | FNM_PERIOD;
252 flags |= FNM_EXTMATCH;
255 rc = fnmatch(s, con->
appName, flags);
270 const char * appName;
271 const char * entryType;
278 if (con == NULL || con->
appName == NULL)
281 memset(item, 0,
sizeof(*item));
295 if (*se !=
'\0') *se++ =
'\0';
298 if (*se ==
'\0')
goto exit;
301 if (opt[0] ==
'-' && *se ==
'\0')
goto exit;
302 if (*se !=
'\0') *se++ =
'\0';
305 if (opt[0] ==
'-' && *se ==
'\0')
goto exit;
308 if (opt[0] ==
'-' && opt[1] ==
'-')
309 item->option.longName = opt + 2;
310 else if (opt[0] ==
'-' && opt[2] ==
'\0')
311 item->option.shortName = opt[1];
313 const char * fn = opt;
318 if (b == NULL || nb == 0)
323 size_t nse = strlen(se) + 1;
324 if ((b = realloc(b, (nb + nse))) == NULL)
332 {
const char * longName = strrchr(fn,
'/');
333 if (longName != NULL)
337 if (longName == NULL)
340 if (longName[1] !=
'\0')
341 item->option.longName = longName;
343 item->option.shortName = longName[0];
352 for (i = 0, j = 0; i < item->argc; i++, j++) {
354 if (!strncmp(item->argv[i],
"--POPTdesc=",
sizeof(
"--POPTdesc=")-1)) {
355 f = item->argv[i] +
sizeof(
"--POPTdesc=");
356 if (f[0] ==
'$' && f[1] ==
'"') f++;
357 item->option.descrip = f;
361 if (!strncmp(item->argv[i],
"--POPTargs=",
sizeof(
"--POPTargs=")-1)) {
362 f = item->argv[i] +
sizeof(
"--POPTargs=");
363 if (f[0] ==
'$' && f[1] ==
'"') f++;
364 item->option.argDescrip = f;
370 item->argv[j] = item->argv[i];
373 item->argv[j] = NULL;
379 if (!strcmp(entryType,
"alias"))
381 else if (!strcmp(entryType,
"exec"))
394 char * b = NULL, *be;
404 return (errno == ENOENT ? 0 : rc);
405 if (b == NULL || nb == 0)
408 if ((t = malloc(nb + 1)) == NULL)
413 for (se = b; se < be; se++) {
419 if (*te && *te !=
'#')
426 if (se < be && *se !=
'\n') {
449 char * buf = (paths ?
xstrdup(paths) : NULL);
454 for (p = buf; p != NULL && *p !=
'\0'; p = pe) {
455 const char ** av = NULL;
462 if (pe != NULL && *pe ==
':')
465 pe = (
char *) (p + strlen(p));
470 for (i = 0; i < ac; i++) {
471 const char * fn = av[i];
475 if (p[0] ==
'@' && p[1] !=
'(') {
476 if (fn[0] ==
'@' && fn[1] !=
'(')
503 static const char _popt_sysconfdir[] = POPT_SYSCONFDIR
"/popt";
504 static const char _popt_etc[] =
"/etc/popt";
509 if (con == NULL || con->
appName == NULL)
goto exit;
511 if (strcmp(_popt_sysconfdir, _popt_etc)) {
519 #if defined(HAVE_GLOB_H)
520 if (!stat(
"/etc/popt.d", &sb) && S_ISDIR(sb.st_mode)) {
521 const char ** av = NULL;
525 if ((rc =
poptGlob(con,
"/etc/popt.d/*", &ac, &av)) == 0) {
526 for (i = 0; rc == 0 && i < ac; i++) {
527 const char * fn = av[i];
528 if (fn == NULL || strstr(fn,
".rpmnew") || strstr(fn,
".rpmsave"))
530 if (!stat(fn, &sb)) {
531 if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
545 if ((home = getenv(
"HOME"))) {
546 char * fn = malloc(strlen(home) + 20);
568 const struct poptOption * options,
const char * configPaths)
573 if (argv == NULL || argv[0] == NULL || options == NULL)
576 if ((argv0 = strrchr(argv[0],
'/')) != NULL) argv0++;
577 else argv0 = argv[0];
579 con =
poptGetContext(argv0, argc, (
const char **)argv, options, 0);