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

Function buffer_gets

imap-send.c:415–462  ·  view source on GitHub ↗

simple line buffering */

Source from the content-addressed store, hash-verified

413
414/* simple line buffering */
415static int buffer_gets(struct imap_buffer *b, char **s)
416{
417 int n;
418 int start = b->offset;
419
420 *s = b->buf + start;
421
422 for (;;) {
423 /* make sure we have enough data to read the \r\n sequence */
424 if (b->offset + 1 >= b->bytes) {
425 if (start) {
426 /* shift down used bytes */
427 *s = b->buf;
428
429 assert(start <= b->bytes);
430 n = b->bytes - start;
431
432 if (n)
433 memmove(b->buf, b->buf + start, n);
434 b->offset -= start;
435 b->bytes = n;
436 start = 0;
437 }
438
439 n = socket_read(&b->sock, b->buf + b->bytes,
440 sizeof(b->buf) - b->bytes);
441
442 if (n <= 0)
443 return -1;
444
445 b->bytes += n;
446 }
447
448 if (b->buf[b->offset] == '\r') {
449 assert(b->offset + 1 < b->bytes);
450 if (b->buf[b->offset + 1] == '\n') {
451 b->buf[b->offset] = 0; /* terminate the string */
452 b->offset += 2; /* next line */
453 if ((0 < verbosity) || (list_folders && strstr(*s, "* LIST")))
454 puts(*s);
455 return 0;
456 }
457 }
458
459 b->offset++;
460 }
461 /* not reached */
462}
463
464__attribute__((format (printf, 1, 2)))
465static void imap_info(const char *msg, ...)

Callers 2

get_cmd_resultFunction · 0.85
imap_open_storeFunction · 0.85

Calls 1

socket_readFunction · 0.85

Tested by

no test coverage detected