[BACK]Return to config.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/config.c, Revision 1.9

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