X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fxio.c;h=db5e2c3aa500e2378c711707b55b1b62e7e62327;hp=de51a15c0a8d4b6d30d4f7c77a1b284057671e7b;hb=a7f1a3f9ffe6c2effeec20809d89a9dcf4234495;hpb=4ea2edafb88ba0280b3bf4eba6c3a3402aaade76 diff --git a/support/nfs/xio.c b/support/nfs/xio.c index de51a15..db5e2c3 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; } @@ -92,7 +92,7 @@ xgettok(XFILE *xfp, char sepa, char *tok, int len) while (i < len && (c = xgetc(xfp)) != EOF && c != sepa && !isspace(c)) tok[i++] = c; if (c == '\n') - xungetc(c, xfp->x_fp); + xungetc(c, xfp); if (!i) return 0; if (i >= len || (sepa && c != sepa)) @@ -128,11 +128,12 @@ xgetc(XFILE *xfp) void xungetc(int c, XFILE *xfp) { - if (c != EOF) { - ungetc(c, xfp->x_fp); - if (c == '\n') - xfp->x_line--; - } + if (c == EOF) + return; + + ungetc(c, xfp->x_fp); + if (c == '\n') + xfp->x_line--; } void