=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cvs/entries.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- src/usr.bin/cvs/entries.c 2004/08/06 20:10:02 1.11 +++ src/usr.bin/cvs/entries.c 2004/08/12 18:33:47 1.12 @@ -1,4 +1,4 @@ -/* $OpenBSD: entries.c,v 1.11 2004/08/06 20:10:02 jfb Exp $ */ +/* $OpenBSD: entries.c,v 1.12 2004/08/12 18:33:47 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -42,10 +42,6 @@ -static struct cvs_ent* cvs_ent_clone (const struct cvs_ent *); - - - /* * cvs_ent_open() * @@ -58,12 +54,14 @@ cvs_ent_open(const char *dir, int flags) { size_t len; + int exists; char entpath[MAXPATHLEN], ebuf[128], mode[4]; FILE *fp; struct stat st; struct cvs_ent *ent; CVSENTRIES *ep; + exists = 0; memset(mode, 0, sizeof(mode)); snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir); @@ -81,10 +79,11 @@ } /* we can use 'r' if the file already exists */ - if (stat(entpath, &st) == 0) + if (stat(entpath, &st) == 0) { + exists = 1; mode[0] = 'r'; + } - fp = fopen(entpath, mode); if (fp == NULL) { cvs_log(LP_ERRNO, "cannot open %s for %s", entpath, @@ -111,8 +110,6 @@ ep->cef_cur = NULL; TAILQ_INIT(&(ep->cef_ent)); - rewind(fp); - while (fgets(ebuf, sizeof(ebuf), fp) != NULL) { len = strlen(ebuf); if ((len > 0) && (ebuf[len - 1] == '\n')) @@ -125,6 +122,10 @@ TAILQ_INSERT_TAIL(&(ep->cef_ent), ent, ce_list); } + if (ferror(fp)) { + cvs_ent_close(ep); + return (NULL); + } /* only keep a pointer to the open file if we're in writing mode */ if ((flags & O_WRONLY) || (flags & O_RDWR)) { @@ -134,7 +135,9 @@ else (void)fclose(fp); - ep->cef_flags |= CVS_ENTF_SYNC; + if (exists) + ep->cef_flags |= CVS_ENTF_SYNC; + return (ep); }