mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-01 04:12:07 +00:00
2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)
* api_lib.c: Use memcpy in netbuf_copy_partial.
This commit is contained in:
parent
205520c620
commit
de665f7cf9
@ -27,6 +27,9 @@ HISTORY
|
|||||||
|
|
||||||
++ New features:
|
++ New features:
|
||||||
|
|
||||||
|
2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)
|
||||||
|
* api_lib.c: Use memcpy in netbuf_copy_partial.
|
||||||
|
|
||||||
++ Bug fixes:
|
++ Bug fixes:
|
||||||
|
|
||||||
(STABLE-1.2.0)
|
(STABLE-1.2.0)
|
||||||
|
@ -150,7 +150,8 @@ void
|
|||||||
netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
|
netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
|
||||||
{
|
{
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
u16_t i, left;
|
u16_t left;
|
||||||
|
u16_t buf_copy_len;
|
||||||
|
|
||||||
left = 0;
|
left = 0;
|
||||||
|
|
||||||
@ -158,18 +159,20 @@ netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This implementation is bad. It should use bcopy
|
/* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
|
||||||
instead. */
|
for(p = buf->p; len != 0 && p != NULL; p = p->next) {
|
||||||
for(p = buf->p; left < len && p != NULL; p = p->next) {
|
|
||||||
if (offset != 0 && offset >= p->len) {
|
if (offset != 0 && offset >= p->len) {
|
||||||
|
/* don't copy from this buffer -> on to the next */
|
||||||
offset -= p->len;
|
offset -= p->len;
|
||||||
} else {
|
} else {
|
||||||
for(i = offset; i < p->len; ++i) {
|
/* copy from this buffer. maybe only partially. */
|
||||||
((u8_t *)dataptr)[left] = ((u8_t *)p->payload)[i];
|
buf_copy_len = p->len - offset;
|
||||||
if (++left >= len) {
|
if (buf_copy_len > len)
|
||||||
return;
|
buf_copy_len = len;
|
||||||
}
|
/* copy the necessary parts of the buffer */
|
||||||
}
|
memcpy(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
|
||||||
|
left += buf_copy_len;
|
||||||
|
len -= buf_copy_len;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user