Read data out through the_reader and save it in a char buffer. */
| 912 | |
| 913 | /* Read data out through the_reader and save it in a char buffer. */ |
| 914 | char * |
| 915 | get_info_from_buffer(TSIOBufferReader the_reader) |
| 916 | { |
| 917 | char *info; |
| 918 | char *info_start; |
| 919 | |
| 920 | int64_t read_avail, read_done; |
| 921 | |
| 922 | if (!the_reader) { |
| 923 | return nullptr; |
| 924 | } |
| 925 | |
| 926 | read_avail = TSIOBufferReaderAvail(the_reader); |
| 927 | |
| 928 | info = static_cast<char *>(TSmalloc(sizeof(char) * read_avail)); |
| 929 | if (info == nullptr) { |
| 930 | return nullptr; |
| 931 | } |
| 932 | info_start = info; |
| 933 | |
| 934 | /* Read the data out of the reader */ |
| 935 | while (read_avail > 0) { |
| 936 | TSIOBufferBlock blk = TSIOBufferReaderStart(the_reader); |
| 937 | char *buf = const_cast<char *>(TSIOBufferBlockReadStart(blk, the_reader, &read_done)); |
| 938 | memcpy(info, buf, read_done); |
| 939 | if (read_done > 0) { |
| 940 | TSIOBufferReaderConsume(the_reader, read_done); |
| 941 | read_avail -= read_done; |
| 942 | info += read_done; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | return info_start; |
| 947 | } |
| 948 | |
| 949 | /* Check if the end token is in the char buffer. */ |
| 950 | int |
no test coverage detected