| 691 | } |
| 692 | |
| 693 | static struct attr_stack *read_attr_from_file(const char *path, unsigned flags) |
| 694 | { |
| 695 | struct strbuf buf = STRBUF_INIT; |
| 696 | int fd; |
| 697 | FILE *fp; |
| 698 | struct attr_stack *res; |
| 699 | int lineno = 0; |
| 700 | struct stat st; |
| 701 | |
| 702 | if (flags & READ_ATTR_NOFOLLOW) |
| 703 | fd = open_nofollow(path, O_RDONLY); |
| 704 | else |
| 705 | fd = open(path, O_RDONLY); |
| 706 | |
| 707 | if (fd < 0) { |
| 708 | warn_on_fopen_errors(path); |
| 709 | return NULL; |
| 710 | } |
| 711 | fp = xfdopen(fd, "r"); |
| 712 | if (fstat(fd, &st)) { |
| 713 | warning_errno(_("cannot fstat gitattributes file '%s'"), path); |
| 714 | fclose(fp); |
| 715 | return NULL; |
| 716 | } |
| 717 | if (st.st_size >= ATTR_MAX_FILE_SIZE) { |
| 718 | warning(_("ignoring overly large gitattributes file '%s'"), path); |
| 719 | fclose(fp); |
| 720 | return NULL; |
| 721 | } |
| 722 | |
| 723 | CALLOC_ARRAY(res, 1); |
| 724 | while (strbuf_getline(&buf, fp) != EOF) { |
| 725 | if (!lineno && starts_with(buf.buf, utf8_bom)) |
| 726 | strbuf_remove(&buf, 0, strlen(utf8_bom)); |
| 727 | handle_attr_line(res, buf.buf, path, ++lineno, flags); |
| 728 | } |
| 729 | |
| 730 | fclose(fp); |
| 731 | strbuf_release(&buf); |
| 732 | return res; |
| 733 | } |
| 734 | |
| 735 | static struct attr_stack *read_attr_from_buf(char *buf, size_t length, |
| 736 | const char *path, unsigned flags) |
no test coverage detected