4 * Simple I/O functions for the parsing of /etc/exports and /etc/nfsclients.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
13 #include <sys/fcntl.h>
26 xfopen(char *fname, char *type)
31 if (!(fp = fopen(fname, type)))
33 xfp = (XFILE *) xmalloc(sizeof(*xfp));
48 xflock(char *fname, char *type)
50 int readonly = !strcmp(type, "r");
51 struct flock fl = { readonly? F_RDLCK : F_WRLCK, SEEK_SET, 0, 0, 0 };
55 fd = open(fname, (O_RDONLY|O_CREAT), 0600);
57 fd = open(fname, (O_RDWR|O_CREAT), 0600);
59 xlog(L_WARNING, "could not open %s for locking: errno %d (%s)",
60 fname, errno, strerror(errno));
64 if (fcntl(fd, F_SETLKW, &fl) < 0) {
65 xlog(L_WARNING, "failed to lock %s: errno %d (%s)",
66 fname, errno, strerror(errno));
80 #define isoctal(x) (isdigit(x) && ((x)<'8'))
82 xgettok(XFILE *xfp, char sepa, char *tok, int len)
88 while (i < len && (c = xgetc(xfp)) != EOF &&
89 (quoted || (c != sepa && !isspace(c)))) {
101 (c = strtol(tok+i-3,NULL, 8)) < 256)) {
110 if (i >= len || (sepa && c != sepa))
119 int c = getc(xfp->x_fp);
124 if ((c = getc(xfp->x_fp)) != '\n') {
125 ungetc(c, xfp->x_fp);
129 while ((c = getc(xfp->x_fp)) == ' ' || c == '\t');
130 ungetc(c, xfp->x_fp);
139 xungetc(int c, XFILE *xfp)
144 ungetc(c, xfp->x_fp);
150 xskip(XFILE *xfp, char *str)
154 while ((c = xgetc(xfp)) != EOF) {
156 c = xskipcomment(xfp);
157 if (strchr(str, c) == NULL)
164 xskipcomment(XFILE *xfp)
168 while ((c = getc(xfp->x_fp)) != EOF && c != '\n');