MCPcopy Create free account
hub / github.com/git/git / read_attr_from_file

Function read_attr_from_file

attr.c:693–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

691}
692
693static 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
735static struct attr_stack *read_attr_from_buf(char *buf, size_t length,
736 const char *path, unsigned flags)

Callers 2

read_attrFunction · 0.85
bootstrap_attr_stackFunction · 0.85

Calls 10

open_nofollowFunction · 0.85
warn_on_fopen_errorsFunction · 0.85
xfdopenFunction · 0.85
warning_errnoFunction · 0.85
warningFunction · 0.85
strbuf_getlineFunction · 0.85
starts_withFunction · 0.85
strbuf_removeFunction · 0.85
handle_attr_lineFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected