* @ingroup pbuf * Get part of a pbuf's payload as contiguous memory. The returned memory is * either a pointer into the pbuf's payload or, if split over multiple pbufs, * a copy into the user-supplied buffer. * * @param p the pbuf from which to copy data * @param buffer the application supplied buffer * @param bufsize size of the application supplied buffer * @param len length of data to c
| 1071 | * @return the number of bytes copied, or 0 on failure |
| 1072 | */ |
| 1073 | void * |
| 1074 | pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset) |
| 1075 | { |
| 1076 | const struct pbuf *q; |
| 1077 | u16_t out_offset; |
| 1078 | |
| 1079 | LWIP_ERROR("pbuf_get_contiguous: invalid buf", (p != NULL), return NULL;); |
| 1080 | LWIP_ERROR("pbuf_get_contiguous: invalid dataptr", (buffer != NULL), return NULL;); |
| 1081 | LWIP_ERROR("pbuf_get_contiguous: invalid dataptr", (bufsize >= len), return NULL;); |
| 1082 | |
| 1083 | q = pbuf_skip_const(p, offset, &out_offset); |
| 1084 | if (q != NULL) { |
| 1085 | if (q->len >= (out_offset + len)) { |
| 1086 | /* all data in this pbuf, return zero-copy */ |
| 1087 | return (u8_t *)q->payload + out_offset; |
| 1088 | } |
| 1089 | /* need to copy */ |
| 1090 | if (pbuf_copy_partial(q, buffer, len, out_offset) != len) { |
| 1091 | /* copying failed: pbuf is too short */ |
| 1092 | return NULL; |
| 1093 | } |
| 1094 | return buffer; |
| 1095 | } |
| 1096 | /* pbuf is too short (offset does not fit in) */ |
| 1097 | return NULL; |
| 1098 | } |
| 1099 | |
| 1100 | #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE |
| 1101 | /** |
no test coverage detected