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;
}
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))
}
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