MCPcopy Create free account
hub / github.com/ElementsProject/lightning / rbuf_read_str

Function rbuf_read_str

ccan/ccan/rbuf/rbuf.c:71–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71char *rbuf_read_str(struct rbuf *rbuf, char term)
72{
73 char *p;
74 ssize_t r = 0;
75 size_t prev = 0;
76
77 while (!(p = memchr(membuf_elems(&rbuf->m) + prev,
78 term,
79 membuf_num_elems(&rbuf->m) - prev))) {
80 prev += r;
81 r = get_more(rbuf);
82 if (r < 0)
83 return NULL;
84 /* EOF with no term. */
85 if (r == 0) {
86 char *ret;
87 size_t len = rbuf_len(rbuf);
88
89 /* Nothing read at all? */
90 if (!len && term) {
91 errno = 0;
92 return NULL;
93 }
94
95 /* Put term after input (get_more made room). */
96 assert(membuf_num_space(&rbuf->m) > 0);
97 ret = membuf_consume(&rbuf->m, len);
98 ret[len] = '\0';
99 return ret;
100 }
101 }
102 *p = '\0';
103 return membuf_consume(&rbuf->m, p + 1 - (char *)rbuf_start(rbuf));
104}

Callers 6

tor_response_line_wfailFunction · 0.85
tor_response_lineFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 3

get_moreFunction · 0.85
rbuf_lenFunction · 0.85
rbuf_startFunction · 0.85

Tested by 3

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68