mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Drop the "?" from "writer1.copy_from_slice?".
This commit is contained in:
1 parent
587be36759
commit
a33f744da5
10 files changed
+142
-97
No files matched your search
+33
-17
@@ -413,40 +413,40 @@ puffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {
|
||||
return ((puffs_base_slice_u8){});
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_prefix returns up to the first n bytes of s.
|
||||
// puffs_base_slice_u8_prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
puffs_base_slice_u8 s,
|
||||
uint64_t n) {
|
||||
if ((uint64_t)(s.len) > n) {
|
||||
s.len = n;
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_suffix returns up to the last n bytes of s.
|
||||
// puffs_base_slice_u8_suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
puffs_base_slice_u8 s,
|
||||
uint64_t n) {
|
||||
if ((uint64_t)(s.len) > n) {
|
||||
s.ptr += (uint64_t)(s.len) - n;
|
||||
s.len = n;
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
s.len = up_to;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, n) where
|
||||
// n is the minimum of dst.len and src.len.
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, length)
|
||||
// where length is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
size_t n = dst.len < src.len ? dst.len : src.len;
|
||||
if (n > 0) {
|
||||
memmove(dst.ptr, src.ptr, n);
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
}
|
||||
return n;
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
@@ -490,11 +490,11 @@ static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
if (length > (wend - wptr)) {
|
||||
if (length > wend - wptr) {
|
||||
length = wend - wptr;
|
||||
}
|
||||
uint8_t* rptr = *ptr_rptr;
|
||||
if (length > (rend - rptr)) {
|
||||
if (length > rend - rptr) {
|
||||
length = rend - rptr;
|
||||
}
|
||||
if (length > 0) {
|
||||
@@ -505,6 +505,22 @@ static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t length = src.len;
|
||||
if (length > wend - wptr) {
|
||||
length = wend - wptr;
|
||||
}
|
||||
if (length > 0) {
|
||||
memmove(wptr, src.ptr, length);
|
||||
*ptr_wptr += length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_IMPL_H
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
Reference in new issue
Block a user