Annotation of src/usr.bin/cvs/config.c, Revision 1.8
1.8 ! xsa 1: /* $OpenBSD: config.c,v 1.7 2007/01/25 08:21:08 otto 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: FILE *fp;
29: size_t len;
1.3 joris 30: struct rlimit rl;
1.1 joris 31: const char *errstr;
1.2 joris 32: char *p, *buf, *lbuf, *opt, *val, fpath[MAXPATHLEN];
1.1 joris 33:
1.8 ! xsa 34: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
! 35: current_cvsroot->cr_dir, CVS_PATH_CONFIG);
1.6 xsa 36:
37: cvs_log(LP_TRACE, "cvs_parse_configfile(%s)", fpath);
1.1 joris 38:
39: if ((fp = fopen(fpath, "r")) == NULL)
40: fatal("cvs_config_parse: %s: %s",
41: CVS_PATH_CONFIG, strerror(errno));
42:
43: lbuf = NULL;
44: while ((buf = fgetln(fp, &len))) {
45: if (buf[len - 1] == '\n') {
46: buf[len - 1] = '\0';
47: } else {
48: lbuf = xmalloc(len + 1);
1.7 otto 49: memcpy(lbuf, buf, len);
50: lbuf[len] = '\0';
1.1 joris 51: buf = lbuf;
52: }
53:
1.2 joris 54: p = buf;
55: while (*p == ' ')
56: p++;
57:
58: if (p[0] == '#' || p[0] == '\0') {
59: if (lbuf != NULL)
60: xfree(lbuf);
61: continue;
62: }
63:
64: opt = p;
1.1 joris 65: if ((val = strrchr(opt, '=')) == NULL)
66: fatal("cvs_parse_configfile: bad option '%s'", opt);
67:
68: *(val++) = '\0';
69:
70: if (!strcmp(opt, "tag")) {
71: cvs_tagname = xstrdup(val);
72: } else if (!strcmp(opt, "umask")) {
73: cvs_umask = (int)strtonum(val, 0, INT_MAX, &errstr);
74: if (errstr != NULL)
75: fatal("cvs_parse_configfile: %s: %s", val,
76: errstr);
1.3 joris 77: } else if (!strcmp(opt, "dlimit")) {
78: if (getrlimit(RLIMIT_DATA, &rl) != -1) {
79: rl.rlim_cur = (int)strtonum(val, 0, INT_MAX,
80: &errstr);
81: if (errstr != NULL)
82: fatal("cvs_parse_configfile: %s: %s",
83: val, errstr);
84: rl.rlim_cur = rl.rlim_cur * 1024;
85: (void)setrlimit(RLIMIT_DATA, &rl);
86: }
1.1 joris 87: } else {
88: cvs_log(LP_ERR, "ignoring unknown option '%s'", opt);
89: }
90:
91: if (lbuf != NULL)
92: xfree(lbuf);
93: }
94:
95: (void)fclose(fp);
96: }