2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
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.
12 SM_RCSID("@(#)$Id: cf.c,v 1.6 2001/09/11 04:04:47 gshapiro Exp $")
19 #include <sm/string.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.
30 ** path -- pathname of sendmail.cf file
31 ** optc -- size of option vector
32 ** optv -- pointer to option vector
35 ** 0 on success, or an errno value on failure.
36 ** An exception is raised on malloc failure.
40 sm_cf_getopt(path
, optc
, optv
)
53 cfp
= sm_io_open(SmFtStdio
, SM_TIME_DEFAULT
, path
, SM_IO_RDONLY
, NULL
);
57 while (sm_io_fgets(cfp
, SM_TIME_DEFAULT
, buf
, sizeof(buf
)) != NULL
)
59 p
= strchr(buf
, '\n');
63 if (buf
[0] != 'O' || buf
[1] != ' ')
67 val
= strchr(id
, '=');
69 val
= idend
= id
+ strlen(id
);
76 while (idend
> id
&& idend
[-1] == ' ')
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
);
92 int save_errno
= errno
;
94 (void) sm_io_close(cfp
, SM_TIME_DEFAULT
);
98 (void) sm_io_close(cfp
, SM_TIME_DEFAULT
);