[PATCH v2 1/5] util: introduce little_endian

Dmitry V. Levin ldv at altlinux.org
Mon Mar 5 20:28:21 UTC 2018


On Mon, Mar 05, 2018 at 09:50:41PM +0800, Chen Jingpiao wrote:
> * 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;
> +}

As we already use WORDS_BIGENDIAN macro to distinguish big-endian and
little-endian cases, I don't think we need a new function for the same
purpose.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180305/32434843/attachment.bin>


More information about the Strace-devel mailing list