diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2018-04-05 18:44:15 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2018-04-05 18:44:15 +0000 |
commit | 040da21637161c189d1d1ca6505cdc1a3794126f (patch) | |
tree | 11032ac31b954f4b4b463b0dc2ecc95f2cffd7d9 /include/sg_lib.h | |
parent | 4d705222f0be707b7b5c43e4e3c2eed583845622 (diff) | |
download | sg3_utils-040da21637161c189d1d1ca6505cdc1a3794126f.tar.gz |
sg_lib: add sg_get_big_endian(), sg_set_big_endian()
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@767 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'include/sg_lib.h')
-rw-r--r-- | include/sg_lib.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/include/sg_lib.h b/include/sg_lib.h index b1d8e051..a66532b3 100644 --- a/include/sg_lib.h +++ b/include/sg_lib.h @@ -608,11 +608,27 @@ uint8_t * sg_memalign(uint32_t num_bytes, uint32_t align_to, /* Returns OS page size in bytes. If uncertain returns 4096. */ uint32_t sg_get_page_size(void); -/* If byte_count is 0 or less then the OS page size is used. Returns true - * if the remainder of ((unsigned)pointer % byte_count) is 0, else returns - * false. */ +/* If byte_count is 0 or less then the OS page size is used as denominator. + * Returns true if the remainder of ((unsigned)pointer % byte_count) is 0, + * else returns false. */ bool sg_is_aligned(const void * pointer, int byte_count); +/* Does similar job to sg_get_unaligned_be*() but this function starts at + * a given start_bit (i.e. within byte, so 7 is MSbit of byte and 0 is LSbit) + * offset. Maximum number of num_bits is 64. For example, these two + * invocations are equivalent (and should yield the same result); + * sg_get_big_endian(from_bp, 7, 16) + * sg_get_unaligned_be16(from_bp) */ +uint64_t sg_get_big_endian(const uint8_t * from_bp, + int start_bit /* 0 to 7 */, + int num_bits /* 1 to 64 */); + +/* Does similar job to sg_put_unaligned_be*() but this function starts at + * a given start_bit offset. Maximum number of num_bits is 64. Preserves + * residual bits in partially written bytes. start_bit 7 is MSb. */ +void sg_set_big_endian(uint64_t val, uint8_t * to, int start_bit /* 0 to 7 */, + int num_bits /* 1 to 64 */); + /* If os_err_num is within bounds then the returned value is 'os_err_num + * SG_LIB_OS_BASE_ERR' otherwise SG_LIB_OS_BASE_ERR is returned. If * os_err_num is 0 then 0 is returned. */ |