mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
577 B
21 lines
577 B
10 years ago
|
#include "duk_internal.h"
|
||
|
|
||
9 years ago
|
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
|
||
9 years ago
|
DUK_INTERNAL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len) {
|
||
10 years ago
|
duk_uint_t buf_size;
|
||
|
duk_uint_t buf_avail;
|
||
|
|
||
|
DUK_ASSERT(h_bufobj != NULL);
|
||
|
DUK_ASSERT(h_bufobj->buf != NULL);
|
||
|
|
||
9 years ago
|
buf_size = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_bufobj->buf);
|
||
10 years ago
|
if (h_bufobj->offset > buf_size) {
|
||
|
/* Slice starting point is beyond current length. */
|
||
|
return 0;
|
||
|
}
|
||
|
buf_avail = buf_size - h_bufobj->offset;
|
||
|
|
||
|
return buf_avail >= len ? len : buf_avail;
|
||
|
}
|
||
9 years ago
|
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
|