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

Function odb_source_loose_map_object

odb/source-loose.c:249–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249static void *odb_source_loose_map_object(struct odb_source_loose *loose,
250 const struct object_id *oid,
251 unsigned long *size)
252{
253 const char *p;
254 int fd = open_loose_object(loose, oid, &p);
255 void *map = NULL;
256 struct stat st;
257
258 if (fd < 0)
259 return NULL;
260
261 if (!fstat(fd, &st)) {
262 *size = xsize_t(st.st_size);
263 if (!*size) {
264 /* mmap() is forbidden on empty files */
265 error(_("object file %s is empty"), p);
266 goto out;
267 }
268
269 map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
270 }
271
272out:
273 close(fd);
274 return map;
275}
276
277struct odb_loose_read_stream {
278 struct odb_read_stream base;

Callers 1

Calls 4

open_loose_objectFunction · 0.85
xsize_tFunction · 0.85
errorFunction · 0.85
xmmapFunction · 0.85

Tested by

no test coverage detected