MCPcopy Index your code
hub / github.com/git/git / grep_source_load_file

Function grep_source_load_file

grep.c:1946–1978  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1944}
1945
1946static int grep_source_load_file(struct grep_source *gs)
1947{
1948 const char *filename = gs->identifier;
1949 struct stat st;
1950 char *data;
1951 size_t size;
1952 int i;
1953
1954 if (lstat(filename, &st) < 0) {
1955 err_ret:
1956 if (errno != ENOENT)
1957 error_errno(_("failed to stat '%s'"), filename);
1958 return -1;
1959 }
1960 if (!S_ISREG(st.st_mode))
1961 return -1;
1962 size = xsize_t(st.st_size);
1963 i = open(filename, O_RDONLY);
1964 if (i < 0)
1965 goto err_ret;
1966 data = xmallocz(size);
1967 if (st.st_size != read_in_full(i, data, size)) {
1968 error_errno(_("'%s': short read"), filename);
1969 close(i);
1970 free(data);
1971 return -1;
1972 }
1973 close(i);
1974
1975 gs->buf = data;
1976 gs->size = size;
1977 return 0;
1978}
1979
1980static int grep_source_load(struct grep_source *gs)
1981{

Callers 1

grep_source_loadFunction · 0.85

Calls 4

error_errnoFunction · 0.85
xsize_tFunction · 0.85
xmalloczFunction · 0.85
read_in_fullFunction · 0.85

Tested by

no test coverage detected