[PATCH v2 1/5] util: introduce little_endian
Chen Jingpiao
chenjingpiao at gmail.com
Mon Mar 5 13:50:41 UTC 2018
* defs.h (little_endian): New prototype.
* util.c (little_endian): New function.
(next_set_bit): Use it.
---
defs.h | 2 ++
util.c | 12 ++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/defs.h b/defs.h
index b4170af48..c25cdb5e4 100644
--- a/defs.h
+++ b/defs.h
@@ -514,6 +514,8 @@ const struct xlat *genl_families_xlat(struct tcb *tcp);
extern unsigned long get_pagesize(void);
extern int next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits);
+extern bool little_endian(void);
+
/*
* Returns STR if it does not start with PREFIX,
* or a pointer to the first char in STR after PREFIX.
diff --git a/util.c b/util.c
index 38458658b..db7591f19 100644
--- a/util.c
+++ b/util.c
@@ -118,6 +118,13 @@ stpcpy(char *dst, const char *src)
}
#endif
+bool
+little_endian(void)
+{
+ const unsigned endian = 1;
+ return *(char *) (void *) &endian;
+}
+
/* Find a next bit which is set.
* Starts testing at cur_bit.
* Returns -1 if no more bits are set.
@@ -131,12 +138,9 @@ stpcpy(char *dst, const char *src)
int
next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits)
{
- const unsigned endian = 1;
- int little_endian = *(char *) (void *) &endian;
-
const uint8_t *array = bit_array;
unsigned pos = cur_bit / 8;
- unsigned pos_xor_mask = little_endian ? 0 : current_wordsize-1;
+ unsigned pos_xor_mask = little_endian() ? 0 : current_wordsize-1;
for (;;) {
uint8_t bitmask;
--
2.16.2.347.gba1b3b449.dirty
More information about the Strace-devel
mailing list