X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fxio.c;h=cfdb1d1256b2c6b16a80d7b0f4dcbf0a95250dcb;hp=1bcd41bc8b1a9eb46bc21af60f5168276ff5688f;hb=90685386b135529ed2738e0d1daab4dd2104b251;hpb=8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9 diff --git a/support/nfs/xio.c b/support/nfs/xio.c index 1bcd41b..cfdb1d1 100644 --- a/support/nfs/xio.c +++ b/support/nfs/xio.c @@ -29,7 +29,7 @@ xfopen(char *fname, char *type) return NULL; xfp = (XFILE *) xmalloc(sizeof(*xfp)); xfp->x_fp = fp; - xfp->x_line = 0; + xfp->x_line = 1; return xfp; } @@ -55,7 +55,7 @@ xflock(char *fname, char *type) struct flock fl = { readonly? F_RDLCK : F_WRLCK, SEEK_SET, 0, 0, 0 }; int fd; - if ((fd = open(fname, readonly? O_RDONLY : O_RDWR)) < 0) { + if ((fd = open(fname, readonly? O_RDONLY : (O_RDWR|O_CREAT))) < 0) { xlog(L_WARNING, "could not open %s for locking", fname); return -1; } @@ -87,12 +87,12 @@ int xgettok(XFILE *xfp, char sepa, char *tok, int len) { int i = 0; - char c = 0; + int c = 0; while (i < len && (c = xgetc(xfp)) != EOF && c != sepa && !isspace(c)) tok[i++] = c; if (c == '\n') - ungetc(c, xfp->x_fp); + xungetc(c, xfp); if (!i) return 0; if (i >= len || (sepa && c != sepa)) @@ -101,10 +101,10 @@ xgettok(XFILE *xfp, char sepa, char *tok, int len) return 1; } -char +int xgetc(XFILE *xfp) { - char c = getc(xfp->x_fp); + int c = getc(xfp->x_fp); if (c == EOF) return c; @@ -126,16 +126,20 @@ xgetc(XFILE *xfp) } void -xungetc(char c, XFILE *xfp) +xungetc(int c, XFILE *xfp) { - if (c != EOF) - ungetc(c, xfp->x_fp); + if (c == EOF) + return; + + ungetc(c, xfp->x_fp); + if (c == '\n') + xfp->x_line--; } void xskip(XFILE *xfp, char *str) { - char c; + int c; while ((c = xgetc(xfp)) != EOF && strchr(str, c)); ungetc(c, xfp->x_fp); @@ -144,7 +148,7 @@ xskip(XFILE *xfp, char *str) char xskipcomment(XFILE *xfp) { - char c; + int c; while ((c = getc(xfp->x_fp)) != EOF && c != '\n'); return c;