mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-13 14:24:11 +08:00
5f60d5f6bb
asm/unaligned.h is always an include of asm-generic/unaligned.h; might as well move that thing to linux/unaligned.h and include that - there's nothing arch-specific in that header. auto-generated by the following: for i in `git grep -l -w asm/unaligned.h`; do sed -i -e "s/asm\/unaligned.h/linux\/unaligned.h/" $i done for i in `git grep -l -w asm-generic/unaligned.h`; do sed -i -e "s/asm-generic\/unaligned.h/linux\/unaligned.h/" $i done git mv include/asm-generic/unaligned.h include/linux/unaligned.h git mv tools/include/asm-generic/unaligned.h tools/include/linux/unaligned.h sed -i -e "/unaligned.h/d" include/asm-generic/Kbuild sed -i -e "s/__ASM_GENERIC/__LINUX/" include/linux/unaligned.h tools/include/linux/unaligned.h
79 lines
1.9 KiB
C
79 lines
1.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright 2023 Red Hat
|
|
*/
|
|
|
|
#ifndef UDS_NUMERIC_H
|
|
#define UDS_NUMERIC_H
|
|
|
|
#include <linux/unaligned.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
|
|
/*
|
|
* These utilities encode or decode a number from an offset in a larger data buffer and then
|
|
* advance the offset pointer to the next field in the buffer.
|
|
*/
|
|
|
|
static inline void decode_s64_le(const u8 *buffer, size_t *offset, s64 *decoded)
|
|
{
|
|
*decoded = get_unaligned_le64(buffer + *offset);
|
|
*offset += sizeof(s64);
|
|
}
|
|
|
|
static inline void encode_s64_le(u8 *data, size_t *offset, s64 to_encode)
|
|
{
|
|
put_unaligned_le64(to_encode, data + *offset);
|
|
*offset += sizeof(s64);
|
|
}
|
|
|
|
static inline void decode_u64_le(const u8 *buffer, size_t *offset, u64 *decoded)
|
|
{
|
|
*decoded = get_unaligned_le64(buffer + *offset);
|
|
*offset += sizeof(u64);
|
|
}
|
|
|
|
static inline void encode_u64_le(u8 *data, size_t *offset, u64 to_encode)
|
|
{
|
|
put_unaligned_le64(to_encode, data + *offset);
|
|
*offset += sizeof(u64);
|
|
}
|
|
|
|
static inline void decode_s32_le(const u8 *buffer, size_t *offset, s32 *decoded)
|
|
{
|
|
*decoded = get_unaligned_le32(buffer + *offset);
|
|
*offset += sizeof(s32);
|
|
}
|
|
|
|
static inline void encode_s32_le(u8 *data, size_t *offset, s32 to_encode)
|
|
{
|
|
put_unaligned_le32(to_encode, data + *offset);
|
|
*offset += sizeof(s32);
|
|
}
|
|
|
|
static inline void decode_u32_le(const u8 *buffer, size_t *offset, u32 *decoded)
|
|
{
|
|
*decoded = get_unaligned_le32(buffer + *offset);
|
|
*offset += sizeof(u32);
|
|
}
|
|
|
|
static inline void encode_u32_le(u8 *data, size_t *offset, u32 to_encode)
|
|
{
|
|
put_unaligned_le32(to_encode, data + *offset);
|
|
*offset += sizeof(u32);
|
|
}
|
|
|
|
static inline void decode_u16_le(const u8 *buffer, size_t *offset, u16 *decoded)
|
|
{
|
|
*decoded = get_unaligned_le16(buffer + *offset);
|
|
*offset += sizeof(u16);
|
|
}
|
|
|
|
static inline void encode_u16_le(u8 *data, size_t *offset, u16 to_encode)
|
|
{
|
|
put_unaligned_le16(to_encode, data + *offset);
|
|
*offset += sizeof(u16);
|
|
}
|
|
|
|
#endif /* UDS_NUMERIC_H */
|