version 1.11, 2004/08/06 20:10:02 |
version 1.12, 2004/08/12 18:33:47 |
|
|
|
|
|
|
|
|
static struct cvs_ent* cvs_ent_clone (const struct cvs_ent *); |
|
|
|
|
|
|
|
/* |
/* |
* cvs_ent_open() |
* cvs_ent_open() |
* |
* |
|
|
cvs_ent_open(const char *dir, int flags) |
cvs_ent_open(const char *dir, int flags) |
{ |
{ |
size_t len; |
size_t len; |
|
int exists; |
char entpath[MAXPATHLEN], ebuf[128], mode[4]; |
char entpath[MAXPATHLEN], ebuf[128], mode[4]; |
FILE *fp; |
FILE *fp; |
struct stat st; |
struct stat st; |
struct cvs_ent *ent; |
struct cvs_ent *ent; |
CVSENTRIES *ep; |
CVSENTRIES *ep; |
|
|
|
exists = 0; |
memset(mode, 0, sizeof(mode)); |
memset(mode, 0, sizeof(mode)); |
|
|
snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir); |
snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir); |
|
|
} |
} |
|
|
/* we can use 'r' if the file already exists */ |
/* we can use 'r' if the file already exists */ |
if (stat(entpath, &st) == 0) |
if (stat(entpath, &st) == 0) { |
|
exists = 1; |
mode[0] = 'r'; |
mode[0] = 'r'; |
|
} |
|
|
|
|
fp = fopen(entpath, mode); |
fp = fopen(entpath, mode); |
if (fp == NULL) { |
if (fp == NULL) { |
cvs_log(LP_ERRNO, "cannot open %s for %s", entpath, |
cvs_log(LP_ERRNO, "cannot open %s for %s", entpath, |
|
|
ep->cef_cur = NULL; |
ep->cef_cur = NULL; |
TAILQ_INIT(&(ep->cef_ent)); |
TAILQ_INIT(&(ep->cef_ent)); |
|
|
rewind(fp); |
|
|
|
while (fgets(ebuf, sizeof(ebuf), fp) != NULL) { |
while (fgets(ebuf, sizeof(ebuf), fp) != NULL) { |
len = strlen(ebuf); |
len = strlen(ebuf); |
if ((len > 0) && (ebuf[len - 1] == '\n')) |
if ((len > 0) && (ebuf[len - 1] == '\n')) |
|
|
|
|
TAILQ_INSERT_TAIL(&(ep->cef_ent), ent, ce_list); |
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 */ |
/* only keep a pointer to the open file if we're in writing mode */ |
if ((flags & O_WRONLY) || (flags & O_RDWR)) { |
if ((flags & O_WRONLY) || (flags & O_RDWR)) { |
|
|
else |
else |
(void)fclose(fp); |
(void)fclose(fp); |
|
|
ep->cef_flags |= CVS_ENTF_SYNC; |
if (exists) |
|
ep->cef_flags |= CVS_ENTF_SYNC; |
|
|
return (ep); |
return (ep); |
} |
} |
|
|