Annotation of src/usr.bin/cvs/config.c, Revision 1.1
1.1 ! joris 1: /* $OpenBSD$ */
! 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: #include "proto.h"
! 25:
! 26: void
! 27: cvs_parse_configfile(void)
! 28: {
! 29: int i;
! 30: FILE *fp;
! 31: size_t len;
! 32: const char *errstr;
! 33: char *buf, *lbuf, *opt, *val, fpath[MAXPATHLEN];
! 34:
! 35: i = snprintf(fpath, sizeof(fpath), "%s/%s", current_cvsroot->cr_dir,
! 36: CVS_PATH_CONFIG);
! 37: if (i == -1 || i >= (int)sizeof(fpath))
! 38: fatal("cvs_parse_configfile: overflow");
! 39:
! 40: if ((fp = fopen(fpath, "r")) == NULL)
! 41: fatal("cvs_config_parse: %s: %s",
! 42: CVS_PATH_CONFIG, strerror(errno));
! 43:
! 44: lbuf = NULL;
! 45: while ((buf = fgetln(fp, &len))) {
! 46: if (buf[len - 1] == '\n') {
! 47: buf[len - 1] = '\0';
! 48: } else {
! 49: lbuf = xmalloc(len + 1);
! 50: strlcpy(lbuf, buf, len);
! 51: buf = lbuf;
! 52: }
! 53:
! 54: opt = buf;
! 55: if ((val = strrchr(opt, '=')) == NULL)
! 56: fatal("cvs_parse_configfile: bad option '%s'", opt);
! 57:
! 58: *(val++) = '\0';
! 59:
! 60: if (!strcmp(opt, "tag")) {
! 61: cvs_tagname = xstrdup(val);
! 62: } else if (!strcmp(opt, "umask")) {
! 63: cvs_umask = (int)strtonum(val, 0, INT_MAX, &errstr);
! 64: if (errstr != NULL)
! 65: fatal("cvs_parse_configfile: %s: %s", val,
! 66: errstr);
! 67: } else {
! 68: cvs_log(LP_ERR, "ignoring unknown option '%s'", opt);
! 69: }
! 70:
! 71: if (lbuf != NULL)
! 72: xfree(lbuf);
! 73: }
! 74:
! 75: (void)fclose(fp);
! 76: }