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++) {
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;
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;
402 return (errno == ENOENT ? 0 : rc);
403 if (b == NULL || nb == 0)
406 if ((t = malloc(nb + 1)) == NULL)
411 for (se = b; se < be; se++) {
417 if (*te && *te !=
'#')
424 if (se < be && *se !=
'\n') {
447 char * buf = (paths ?
xstrdup(paths) : NULL);
452 for (p = buf; p != NULL && *p !=
'\0'; p = pe) {
453 const char ** av = NULL;
460 if (pe != NULL && *pe ==
':')
463 pe = (
char *) (p + strlen(p));
468 for (i = 0; i < ac; i++) {
469 const char * fn = av[i];
473 if (p[0] ==
'@' && p[1] !=
'(') {
474 if (fn[0] ==
'@' && fn[1] !=
'(')
501 static const char _popt_sysconfdir[] = POPT_SYSCONFDIR
"/popt";
502 static const char _popt_etc[] =
"/etc/popt";
507 if (con->
appName == NULL)
goto exit;
509 if (strcmp(_popt_sysconfdir, _popt_etc)) {
517 #if defined(HAVE_GLOB_H) 518 if (!stat(
"/etc/popt.d", &sb) && S_ISDIR(sb.st_mode)) {
519 const char ** av = NULL;
523 if ((rc =
poptGlob(con,
"/etc/popt.d/*", &ac, &av)) == 0) {
524 for (i = 0; rc == 0 && i < ac; i++) {
525 const char * fn = av[i];
526 if (fn == NULL || strstr(fn,
".rpmnew") || strstr(fn,
".rpmsave"))
528 if (!stat(fn, &sb)) {
529 if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
543 if ((home = getenv(
"HOME"))) {
544 char * fn = malloc(strlen(home) + 20);
566 const struct poptOption * options,
const char * configPaths)
571 if (argv == NULL || argv[0] == NULL || options == NULL)
574 if ((argv0 = strrchr(argv[0],
'/')) != NULL) argv0++;
575 else argv0 = argv[0];
577 con =
poptGetContext(argv0, argc, (
const char **)argv, options, 0);
poptContext poptInit(int argc, const char **argv, const struct poptOption *options, const char *configPaths)
Initialize popt context (alternative implementation).
int poptParseArgvString(const char *s, int *argcPtr, const char ***argvPtr)
Parse a string into an argument array.
static char * stpcpy(char *dest, const char *src)
A popt alias or exec argument for poptAddItem().
static int configAppMatch(poptContext con, const char *s)
Check for application match.
int poptSaneFile(const char *fn)
Perform sanity checks on a file path.
#define POPT_ERROR_BADCONFIG
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
Initialize popt context.
poptContext poptFini(poptContext con)
Destroy context (alternative implementation).
int poptReadFile(const char *fn, char **bp, size_t *nbp, int flags)
Read a file into a buffer.
#define POPT_ARGFLAG_DOC_HIDDEN
int poptReadConfigFiles(poptContext con, const char *paths)
Read configuration file(s).
poptContext poptFreeContext(poptContext con)
Destroy context.
char * xstrdup(const char *str)
int poptReadConfigFile(poptContext con, const char *fn)
Read configuration file.
#define POPT_READFILE_TRIMNEWLINES
static int poptConfigLine(poptContext con, char *line)
int poptAddItem(poptContext con, poptItem newItem, int flags)
Add alias/exec item to context.
#define _isspaceptr(_chp)
static int poptGlob(poptContext con, const char *pattern, int *acp, const char ***avp)
Return path(s) from a glob pattern.
#define POPT_ERROR_MALLOC
int poptReadDefaultConfig(poptContext con, int useEnv)
Read default configuration from /etc/popt and $HOME/.popt.