1 /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
2 file accompanying popt source distributions, available from
3 ftp://ftp.redhat.com/pub/code/popt */
8 static void configLine(poptContext con, char * line) {
9 int nameLength = strlen(con->appName);
11 struct poptAlias alias;
13 char * longName = NULL;
14 char shortName = '\0';
16 if (strncmp(line, con->appName, nameLength)) return;
18 if (!*line || !isspace(*line)) return;
19 while (*line && isspace(*line)) line++;
22 while (!*line || !isspace(*line)) line++;
24 while (*line && isspace(*line)) line++;
28 while (!*line || !isspace(*line)) line++;
30 while (*line && isspace(*line)) line++;
33 if (opt[0] == '-' && opt[1] == '-')
35 else if (opt[0] == '-' && !opt[2])
38 if (!strcmp(entryType, "alias")) {
39 if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;
40 alias.longName = longName, alias.shortName = shortName;
41 poptAddAlias(con, alias, 0);
42 } else if (!strcmp(entryType, "exec")) {
43 con->execs = realloc(con->execs,
44 sizeof(*con->execs) * (con->numExecs + 1));
46 con->execs[con->numExecs].longName = xstrdup(longName);
48 con->execs[con->numExecs].longName = NULL;
50 con->execs[con->numExecs].shortName = shortName;
51 con->execs[con->numExecs].script = xstrdup(line);
57 int poptReadConfigFile(poptContext con, const char * fn) {
58 char * file=NULL, * chptr, * end;
59 char * buf=NULL, * dst;
63 fd = open(fn, O_RDONLY);
68 return POPT_ERROR_ERRNO;
71 fileLength = lseek(fd, 0, SEEK_END);
72 (void) lseek(fd, 0, 0);
74 file = malloc(fileLength + 1);
75 if (read(fd, file, fileLength) != fileLength) {
80 return POPT_ERROR_ERRNO;
84 dst = buf = malloc(fileLength + 1);
87 end = (file + fileLength);
93 while (*dst && isspace(*dst)) dst++;
94 if (*dst && *dst != '#') {
104 /* \ at the end of a line does not insert a \n */
121 int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) {
125 if (!con->appName) return 0;
127 rc = poptReadConfigFile(con, "/etc/popt");
129 if (getuid() != geteuid()) return 0;
131 if ((home = getenv("HOME"))) {
132 fn = malloc(strlen(home) + 20);
134 strcat(fn, "/.popt");
135 rc = poptReadConfigFile(con, fn);