2013-02-08 23:44:21 +00:00
|
|
|
/*
|
|
|
|
* virendian.h: aid for reading endian-specific data
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-13 14:53:50 +00:00
|
|
|
#ifndef LIBVIRT_VIRENDIAN_H
|
|
|
|
# define LIBVIRT_VIRENDIAN_H
|
2013-02-08 23:44:21 +00:00
|
|
|
|
|
|
|
# include "internal.h"
|
|
|
|
|
|
|
|
/* The interfaces in this file are provided as macros for speed. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReadBufInt64BE:
|
|
|
|
* @buf: byte to start reading at (can be 'char*' or 'unsigned char*');
|
|
|
|
* evaluating buf must not have any side effects
|
|
|
|
*
|
|
|
|
* Read 8 bytes at BUF as a big-endian 64-bit number. Caller is
|
|
|
|
* responsible to avoid reading beyond array bounds.
|
|
|
|
*/
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReadBufInt64BE(buf) \
|
|
|
|
(((uint64_t)(uint8_t)((buf)[0]) << 56) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[1]) << 48) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[2]) << 40) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[3]) << 32) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[4]) << 24) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[5]) << 16) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[6]) << 8) | \
|
2013-02-08 23:44:21 +00:00
|
|
|
(uint64_t)(uint8_t)((buf)[7]))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReadBufInt64LE:
|
|
|
|
* @buf: byte to start reading at (can be 'char*' or 'unsigned char*');
|
|
|
|
* evaluating buf must not have any side effects
|
|
|
|
*
|
|
|
|
* Read 8 bytes at BUF as a little-endian 64-bit number. Caller is
|
|
|
|
* responsible to avoid reading beyond array bounds.
|
|
|
|
*/
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReadBufInt64LE(buf) \
|
|
|
|
((uint64_t)(uint8_t)((buf)[0]) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[1]) << 8) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[2]) << 16) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[3]) << 24) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[4]) << 32) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[5]) << 40) | \
|
|
|
|
((uint64_t)(uint8_t)((buf)[6]) << 48) | \
|
2013-02-08 23:44:21 +00:00
|
|
|
((uint64_t)(uint8_t)((buf)[7]) << 56))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReadBufInt32BE:
|
|
|
|
* @buf: byte to start reading at (can be 'char*' or 'unsigned char*');
|
|
|
|
* evaluating buf must not have any side effects
|
|
|
|
*
|
|
|
|
* Read 4 bytes at BUF as a big-endian 32-bit number. Caller is
|
|
|
|
* responsible to avoid reading beyond array bounds.
|
|
|
|
*/
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReadBufInt32BE(buf) \
|
|
|
|
(((uint32_t)(uint8_t)((buf)[0]) << 24) | \
|
|
|
|
((uint32_t)(uint8_t)((buf)[1]) << 16) | \
|
|
|
|
((uint32_t)(uint8_t)((buf)[2]) << 8) | \
|
2013-02-08 23:44:21 +00:00
|
|
|
(uint32_t)(uint8_t)((buf)[3]))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReadBufInt32LE:
|
|
|
|
* @buf: byte to start reading at (can be 'char*' or 'unsigned char*');
|
|
|
|
* evaluating buf must not have any side effects
|
|
|
|
*
|
|
|
|
* Read 4 bytes at BUF as a little-endian 32-bit number. Caller is
|
|
|
|
* responsible to avoid reading beyond array bounds.
|
|
|
|
*/
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReadBufInt32LE(buf) \
|
|
|
|
((uint32_t)(uint8_t)((buf)[0]) | \
|
|
|
|
((uint32_t)(uint8_t)((buf)[1]) << 8) | \
|
|
|
|
((uint32_t)(uint8_t)((buf)[2]) << 16) | \
|
2013-02-08 23:44:21 +00:00
|
|
|
((uint32_t)(uint8_t)((buf)[3]) << 24))
|
|
|
|
|
2016-06-21 16:57:30 +00:00
|
|
|
/**
|
|
|
|
* virReadBufInt16BE:
|
|
|
|
* @buf: byte to start reading at (can be 'char*' or 'unsigned char*');
|
|
|
|
* evaluating buf must not have any side effects
|
|
|
|
*
|
|
|
|
* Read 2 bytes at BUF as a big-endian 16-bit number. Caller is
|
|
|
|
* responsible to avoid reading beyond array bounds.
|
|
|
|
*/
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReadBufInt16BE(buf) \
|
|
|
|
(((uint16_t)(uint8_t)((buf)[0]) << 8) | \
|
2016-06-21 16:57:30 +00:00
|
|
|
(uint16_t)(uint8_t)((buf)[1]))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virReadBufInt16LE:
|
|
|
|
* @buf: byte to start reading at (can be 'char*' or 'unsigned char*');
|
|
|
|
* evaluating buf must not have any side effects
|
|
|
|
*
|
|
|
|
* Read 2 bytes at BUF as a little-endian 16-bit number. Caller is
|
|
|
|
* responsible to avoid reading beyond array bounds.
|
|
|
|
*/
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReadBufInt16LE(buf) \
|
|
|
|
((uint16_t)(uint8_t)((buf)[0]) | \
|
2016-06-21 16:57:30 +00:00
|
|
|
((uint16_t)(uint8_t)((buf)[1]) << 8))
|
|
|
|
|
2018-12-13 14:53:50 +00:00
|
|
|
#endif /* LIBVIRT_VIRENDIAN_H */
|