616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
bool |
620 |
|
file_contains_keyword (const struct file_info *finfo) |
621 |
|
{ |
622 |
|
FILE *fp; |
623 |
|
bool result; |
624 |
|
struct stat st; |
625 |
|
char *content; |
626 |
|
|
627 |
|
fp = CVS_FOPEN (finfo->file, "r"); |
628 |
|
if (fp == NULL) |
629 |
|
error (1, errno, "cannot open %s", finfo->fullname); |
630 |
|
if (fstat (fileno (fp), &st)) |
631 |
|
error (1, errno, "cannot fstat `%s'", finfo->fullname); |
632 |
|
content = xmalloc (st.st_size); |
633 |
|
if (fread (content, sizeof *content, st.st_size, fp) < st.st_size) |
634 |
|
error (1, errno, "Failed to read from `%s'", finfo->fullname); |
635 |
|
result = contains_keyword (content, st.st_size); |
636 |
|
if (fclose (fp) < 0) |
637 |
|
error (0, errno, "cannot close %s", finfo->fullname); |
638 |
|
free (content); |
639 |
|
return result; |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
|
|
644 |
/* Read the entire contents of the file NAME into *BUF. |
/* Read the entire contents of the file NAME into *BUF. |
645 |
If NAME is NULL, read from stdin. *BUF |
If NAME is NULL, read from stdin. *BUF |
646 |
is a pointer returned from malloc (or NULL), pointing to *BUFSIZE |
is a pointer returned from malloc (or NULL), pointing to *BUFSIZE |