*
* A few endianness-aware macros for reading and writing data from in-memory
* buffers.
- *
- * Copyright (C) 2012 Eric Biggers
- *
- * wimlib - Library for working with WIM files
- *
- * 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, write to the Free Software Foundation, Inc., 59
- * Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _WIMLIB_IO_H
static inline const u8 *get_u16(const u8 *p, u16 *res)
{
- *res = to_le16(*(u16*)p);
+ *res = le16_to_cpu(*(u16*)p);
return p + 2;
}
static inline const u8 *get_u32(const u8 *p, u32 *res)
{
- *res = to_le32(*(u32*)p);
+ *res = le32_to_cpu(*(u32*)p);
return p + 4;
}
static inline const u8 *get_u56(const u8 *p, u64 *res)
{
- *res = to_le64(*(u64*)p) & 0x00ffffffffffffff;
+ *res = le64_to_cpu(*(u64*)p) & 0x00ffffffffffffff;
return p + 7;
}
static inline const u8 *get_u64(const u8 *p, u64 *res)
{
- *res = to_le64(*(u64*)p);
+ *res = le64_to_cpu(*(u64*)p);
return p + 8;
}
static inline u8 *put_u16(u8 *res, u16 val)
{
- *(uint16_t*)res = to_le16(val);
+ *(uint16_t*)res = cpu_to_le16(val);
return res + 2;
}
static inline u8 *put_u32(u8 *res, u32 val)
{
- *(uint32_t*)res = to_le32(val);
+ *(uint32_t*)res = cpu_to_le32(val);
return res + 4;
}
static inline u8 *put_u64(u8 *res, u64 val)
{
- *(u64*)res = to_le64(val);
+ *(u64*)res = cpu_to_le64(val);
return res + 8;
}
return p + num_bytes;
}
+static inline u8 *put_zeroes(u8 *p, size_t num_bytes)
+{
+ return (u8*)memset(p, 0, num_bytes) + num_bytes;
+}
+
static inline u8 *put_bytes(u8 *p, size_t num_bytes, const u8 *input)
{
- memcpy(p, input, num_bytes);
- return p + num_bytes;
+ return (u8*)memcpy(p, input, num_bytes) + num_bytes;
}
#endif /* _WIMLIB_IO_H */