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

Function rbuf_read_str

ccan/ccan/rbuf/rbuf.c:71–106  ·  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 /* memchr(NULL, ..., 0) is illegal. FML. */
78 while (membuf_num_elems(&rbuf->m) == prev
79 || !(p = memchr(membuf_elems(&rbuf->m) + prev,
80 term,
81 membuf_num_elems(&rbuf->m) - prev))) {
82 prev += r;
83 r = get_more(rbuf);
84 if (r < 0)
85 return NULL;
86 /* EOF with no term. */
87 if (r == 0) {
88 char *ret;
89 size_t len = rbuf_len(rbuf);
90
91 /* Nothing read at all? */
92 if (!len && term) {
93 errno = 0;
94 return NULL;
95 }
96
97 /* Put term after input (get_more made room). */
98 assert(membuf_num_space(&rbuf->m) > 0);
99 ret = membuf_consume(&rbuf->m, len);
100 ret[len] = '\0';
101 return ret;
102 }
103 }
104 *p = '\0';
105 return membuf_consume(&rbuf->m, p + 1 - (char *)rbuf_start(rbuf));
106}

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