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

Function get_packet_data

pkt-line.c:339–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339static int get_packet_data(int fd, char **src_buf, size_t *src_size,
340 void *dst, size_t size, int options)
341{
342 size_t bytes_read;
343
344 if (fd >= 0 && src_buf && *src_buf)
345 BUG("multiple sources given to packet_read");
346
347 /* Read up to "size" bytes from our source, whatever it is. */
348 if (src_buf && *src_buf) {
349 bytes_read = size < *src_size ? size : *src_size;
350 memcpy(dst, *src_buf, bytes_read);
351 *src_buf += bytes_read;
352 *src_size -= bytes_read;
353 } else {
354 ssize_t ret = read_in_full(fd, dst, size);
355 if (ret < 0) {
356 if (options & PACKET_READ_GENTLE_ON_READ_ERROR)
357 return error_errno(_("read error"));
358 die_errno(_("read error"));
359 }
360
361 bytes_read = (size_t) ret;
362 }
363
364 /* And complain if we didn't get enough bytes to satisfy the read. */
365 if (bytes_read != size) {
366 if (options & PACKET_READ_GENTLE_ON_EOF)
367 return -1;
368
369 if (options & PACKET_READ_GENTLE_ON_READ_ERROR)
370 return error(_("the remote end hung up unexpectedly"));
371 die(_("the remote end hung up unexpectedly"));
372 }
373
374 return 0;
375}
376
377int packet_length(const char lenbuf_hex[4], size_t size)
378{

Callers 1

packet_read_with_statusFunction · 0.85

Calls 5

read_in_fullFunction · 0.85
error_errnoFunction · 0.85
die_errnoFunction · 0.85
errorFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected