Revert "usbd - Do not start moused by default when a usb mouse is connected"
[dragonfly.git] / contrib / sendmail-8.14 / libsm / cf.c
blobd2178753ceda17c26a0506b2cef054f32a58835a
1 /*
2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 */
11 #include <sm/gen.h>
12 SM_RCSID("@(#)$Id: cf.c,v 1.6 2001/09/11 04:04:47 gshapiro Exp $")
14 #include <ctype.h>
15 #include <errno.h>
17 #include <sm/cf.h>
18 #include <sm/io.h>
19 #include <sm/string.h>
20 #include <sm/heap.h>
23 ** SM_CF_GETOPT -- look up option values in the sendmail.cf file
25 ** Open the sendmail.cf file and parse all of the 'O' directives.
26 ** Each time one of the options named in the option vector optv
27 ** is found, store a malloced copy of the option value in optv.
29 ** Parameters:
30 ** path -- pathname of sendmail.cf file
31 ** optc -- size of option vector
32 ** optv -- pointer to option vector
34 ** Results:
35 ** 0 on success, or an errno value on failure.
36 ** An exception is raised on malloc failure.
39 int
40 sm_cf_getopt(path, optc, optv)
41 char *path;
42 int optc;
43 SM_CF_OPT_T *optv;
45 SM_FILE_T *cfp;
46 char buf[2048];
47 char *p;
48 char *id;
49 char *idend;
50 char *val;
51 int i;
53 cfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, path, SM_IO_RDONLY, NULL);
54 if (cfp == NULL)
55 return errno;
57 while (sm_io_fgets(cfp, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
59 p = strchr(buf, '\n');
60 if (p != NULL)
61 *p = '\0';
63 if (buf[0] != 'O' || buf[1] != ' ')
64 continue;
66 id = &buf[2];
67 val = strchr(id, '=');
68 if (val == NULL)
69 val = idend = id + strlen(id);
70 else
72 idend = val;
73 ++val;
74 while (*val == ' ')
75 ++val;
76 while (idend > id && idend[-1] == ' ')
77 --idend;
78 *idend = '\0';
81 for (i = 0; i < optc; ++i)
83 if (sm_strcasecmp(optv[i].opt_name, id) == 0)
85 optv[i].opt_val = sm_strdup_x(val);
86 break;
90 if (sm_io_error(cfp))
92 int save_errno = errno;
94 (void) sm_io_close(cfp, SM_TIME_DEFAULT);
95 errno = save_errno;
96 return errno;
98 (void) sm_io_close(cfp, SM_TIME_DEFAULT);
99 return 0;