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.
11 #pragma ident "%Z%%M% %I% %E% SMI"
14 SM_RCSID("@(#)$Id: cf.c,v 1.4 2001/02/01 02:40:21 dmoen Exp $")
21 #include <sm/string.h>
25 ** SM_CF_GETOPT -- look up option values in the sendmail.cf file
27 ** Open the sendmail.cf file and parse all of the 'O' directives.
28 ** Each time one of the options named in the option vector optv
29 ** is found, store a malloced copy of the option value in optv.
32 ** path -- pathname of sendmail.cf file
33 ** optc -- size of option vector
34 ** optv -- pointer to option vector
37 ** 0 on success, or an errno value on failure.
38 ** An exception is raised on malloc failure.
42 sm_cf_getopt(path
, optc
, optv
)
55 cfp
= sm_io_open(SmFtStdio
, SM_TIME_DEFAULT
, path
, SM_IO_RDONLY
, NULL
);
59 while (sm_io_fgets(cfp
, SM_TIME_DEFAULT
, buf
, sizeof(buf
)) != NULL
)
61 p
= strchr(buf
, '\n');
65 if (buf
[0] != 'O' || buf
[1] != ' ')
69 val
= strchr(id
, '=');
71 val
= idend
= id
+ strlen(id
);
78 while (idend
> id
&& idend
[-1] == ' ')
83 for (i
= 0; i
< optc
; ++i
)
85 if (sm_strcasecmp(optv
[i
].opt_name
, id
) == 0)
87 optv
[i
].opt_val
= sm_strdup_x(val
);
94 int save_errno
= errno
;
96 (void) sm_io_close(cfp
, SM_TIME_DEFAULT
);
100 (void) sm_io_close(cfp
, SM_TIME_DEFAULT
);