projects
/
libusual.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
7d8c4e5
)
mbuf: mbuf_cut() function
author
Marko Kreen
<markokr@gmail.com>
Thu, 24 Sep 2009 09:59:45 +0000
(12:59 +0300)
committer
Marko Kreen
<markokr@gmail.com>
Tue, 8 Dec 2009 12:03:18 +0000
(14:03 +0200)
usual/mbuf.h
patch
|
blob
|
blame
|
history
diff --git
a/usual/mbuf.h
b/usual/mbuf.h
index fac69d71a982ac7c4efc6fddf29fddf08d715070..aa0ae81ac2ab41b28cba72ca966ebed7a9a83e61 100644
(file)
--- a/
usual/mbuf.h
+++ b/
usual/mbuf.h
@@
-230,5
+230,21
@@
static inline bool mbuf_fill(struct MBuf *buf, uint8_t byte, unsigned len)
return true;
}
+/* remove some data from buf */
+_MUSTCHECK
+static inline bool mbuf_cut(struct MBuf *buf, unsigned ofs, unsigned len)
+{
+ if (buf->reader)
+ return false;
+ if (ofs + len < buf->write_pos) {
+ unsigned endofs = ofs + len;
+ memmove(buf->data + ofs, buf->data + endofs, buf->write_pos - endofs);
+ buf->write_pos -= len;
+ } else if (ofs < buf->write_pos) {
+ buf->write_pos = ofs;
+ }
+ return true;
+}
+
#endif