Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added mbuf_remove_range() #479

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/mgos_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void mgos_system_restart_after(int delay_ms);
/* Return random number in a given range. */
float mgos_rand_range(float from, float to);

/* Removes 'data_size' bytes from index of the buffer */
size_t mbuf_remove_range(struct mbuf *, size_t index, size_t data_size);

#ifdef __cplusplus
}
#endif
16 changes: 16 additions & 0 deletions src/mgos_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ float mgos_rand_range(float from, float to) {
return from + (((float) (to - from)) / RAND_MAX * rand());
}


size_t mbuf_remove_range(struct mbuf *mb, size_t i, size_t n) WEAK;
size_t mbuf_remove_range(struct mbuf *mb, size_t i, size_t n) {
size_t ret = 0;
if (n > 0 && n <= (mb->len - i)) {
memmove(&mb->buf[i], &mb->buf[i] + n, mb->len - n);
mb->len -= n;
ret = n;
}
else if (n > 0 && n >= (mb->len - i)) {
ret = mb->len - i;
mb->len -= ret;
}
return ret;
}

#if CS_ENABLE_STDIO
/*
* Intended for ffi
Expand Down