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

Function rbuf_read_str

ccan/ccan/rbuf/rbuf.c:77–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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