Annotation of src/usr.bin/cvs/config.c, Revision 1.4
1.4 ! joris 1: /* $OpenBSD: config.c,v 1.3 2006/05/28 15:45:31 joris Exp $ */
1.1 joris 2: /*
3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17:
18: #include "includes.h"
19:
20: #include "cvs.h"
21: #include "config.h"
22: #include "diff.h"
23: #include "log.h"
24:
25: void
26: cvs_parse_configfile(void)
27: {
28: int i;
29: FILE *fp;
30: size_t len;
1.3 joris 31: struct rlimit rl;
1.1 joris 32: const char *errstr;
1.2 joris 33: char *p, *buf, *lbuf, *opt, *val, fpath[MAXPATHLEN];
1.1 joris 34:
1.3 joris 35: cvs_log(LP_TRACE, "cvs_parse_configfile()");
36:
1.1 joris 37: i = snprintf(fpath, sizeof(fpath), "%s/%s", current_cvsroot->cr_dir,
38: CVS_PATH_CONFIG);
39: if (i == -1 || i >= (int)sizeof(fpath))
40: fatal("cvs_parse_configfile: overflow");
41:
42: if ((fp = fopen(fpath, "r")) == NULL)
43: fatal("cvs_config_parse: %s: %s",
44: CVS_PATH_CONFIG, strerror(errno));
45:
46: lbuf = NULL;
47: while ((buf = fgetln(fp, &len))) {
48: if (buf[len - 1] == '\n') {
49: buf[len - 1] = '\0';
50: } else {
51: lbuf = xmalloc(len + 1);
52: strlcpy(lbuf, buf, len);
53: buf = lbuf;
54: }
55:
1.2 joris 56: p = buf;
57: while (*p == ' ')
58: p++;
59:
60: if (p[0] == '#' || p[0] == '\0') {
61: if (lbuf != NULL)
62: xfree(lbuf);
63: continue;
64: }
65:
66: opt = p;
1.1 joris 67: if ((val = strrchr(opt, '=')) == NULL)
68: fatal("cvs_parse_configfile: bad option '%s'", opt);
69:
70: *(val++) = '\0';
71:
72: if (!strcmp(opt, "tag")) {
73: cvs_tagname = xstrdup(val);
74: } else if (!strcmp(opt, "umask")) {
75: cvs_umask = (int)strtonum(val, 0, INT_MAX, &errstr);
76: if (errstr != NULL)
77: fatal("cvs_parse_configfile: %s: %s", val,
78: errstr);
1.3 joris 79: } else if (!strcmp(opt, "dlimit")) {
80: if (getrlimit(RLIMIT_DATA, &rl) != -1) {
81: rl.rlim_cur = (int)strtonum(val, 0, INT_MAX,
82: &errstr);
83: if (errstr != NULL)
84: fatal("cvs_parse_configfile: %s: %s",
85: val, errstr);
86: rl.rlim_cur = rl.rlim_cur * 1024;
87: (void)setrlimit(RLIMIT_DATA, &rl);
88: }
1.1 joris 89: } else {
90: cvs_log(LP_ERR, "ignoring unknown option '%s'", opt);
91: }
92:
93: if (lbuf != NULL)
94: xfree(lbuf);
95: }
96:
97: (void)fclose(fp);
98: }