* @ingroup netbuf * Allocate memory for a packet buffer for a given netbuf. * * @param buf the netbuf for which to allocate a packet buffer * @param size the size of the packet buffer to allocate * @return pointer to the allocated memory * NULL if no memory could be allocated */
| 99 | * NULL if no memory could be allocated |
| 100 | */ |
| 101 | void * |
| 102 | netbuf_alloc(struct netbuf *buf, u16_t size) |
| 103 | { |
| 104 | LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;); |
| 105 | |
| 106 | /* Deallocate any previously allocated memory. */ |
| 107 | if (buf->p != NULL) { |
| 108 | pbuf_free(buf->p); |
| 109 | } |
| 110 | buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM); |
| 111 | if (buf->p == NULL) { |
| 112 | return NULL; |
| 113 | } |
| 114 | LWIP_ASSERT("check that first pbuf can hold size", |
| 115 | (buf->p->len >= size)); |
| 116 | buf->ptr = buf->p; |
| 117 | return buf->p->payload; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @ingroup netbuf |
no test coverage detected