From 4efee8a7ca1dfe4b303281e1b6326b211ca944d3 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 11 Nov 2016 12:02:06 -0500 Subject: [PATCH] misc updates. --- cxx/mapped_file.cpp | 4 ++-- include/endian.h | 40 ++++++++++++++++++++++++++++++++++++++++ native/file.cpp | 2 +- native/file.h | 5 +++++ native/native.cpp | 6 ++++-- 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/cxx/mapped_file.cpp b/cxx/mapped_file.cpp index fee94a3..5fc9e16 100644 --- a/cxx/mapped_file.cpp +++ b/cxx/mapped_file.cpp @@ -92,7 +92,7 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si if (length == -1) { LARGE_INTEGER file_size; GetFileSizeEx(fh, &file_size); - length = file_size.QuadPart; + length = (size_t)file_size.QuadPart; } if (length == 0) return; @@ -173,7 +173,7 @@ void mapped_file_base::create(const path_type& p, size_t length) { file_size.QuadPart = length; - if (!SetFilePointerEx(fh, file_size, nullptr, FILE_BEGIN)); + if (!SetFilePointerEx(fh, file_size, nullptr, FILE_BEGIN)) throw_error(); if (!SetEndOfFile(fh)) throw_error(); mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0); diff --git a/include/endian.h b/include/endian.h index d320bab..dd21df7 100644 --- a/include/endian.h +++ b/include/endian.h @@ -55,6 +55,46 @@ #endif +#ifdef _WIN32 +#include + +#define bswap16 _byteswap_ushort +#define bswap32 _byteswap_ulong +#define bswap64 _byteswap_uint64 + +#if BYTE_ORDER == LITTLE_ENDIAN +#define htobe16(x) bswap16((x)) +#define htobe32(x) bswap32((x)) +#define htobe64(x) bswap64((x)) +#define htole16(x) ((uint16_t)(x)) +#define htole32(x) ((uint32_t)(x)) +#define htole64(x) ((uint64_t)(x)) + +#define be16toh(x) bswap16((x)) +#define be32toh(x) bswap32((x)) +#define be64toh(x) bswap64((x)) +#define le16toh(x) ((uint16_t)(x)) +#define le32toh(x) ((uint32_t)(x)) +#define le64toh(x) ((uint64_t)(x)) +#else /* BYTE_ORDER != LITTLE_ENDIAN */ +#define htobe16(x) ((uint16_t)(x)) +#define htobe32(x) ((uint32_t)(x)) +#define htobe64(x) ((uint64_t)(x)) +#define htole16(x) bswap16((x)) +#define htole32(x) bswap32((x)) +#define htole64(x) bswap64((x)) + +#define be16toh(x) ((uint16_t)(x)) +#define be32toh(x) ((uint32_t)(x)) +#define be64toh(x) ((uint64_t)(x)) +#define le16toh(x) bswap16((x)) +#define le32toh(x) bswap32((x)) +#define le64toh(x) bswap64((x)) +#endif /* BYTE_ORDER == LITTLE_ENDIAN */ + + +#endif + #ifdef __cplusplus // https://github.com/HowardHinnant/hash_append/blob/master/endian.h diff --git a/native/file.cpp b/native/file.cpp index a9adc50..362d74c 100644 --- a/native/file.cpp +++ b/native/file.cpp @@ -170,7 +170,7 @@ tool_return fd_file::set_eof(ssize_t new_eof) { if (_interactive) return MacOS::paramErr; - int ok = ::ftruncate(_fd, new_eof); + int ok = ftruncate(_fd, new_eof); if (ok < 0) return macos_error_from_errno(); return new_eof; } diff --git a/native/file.h b/native/file.h index 64a1f66..e15d05f 100644 --- a/native/file.h +++ b/native/file.h @@ -5,9 +5,14 @@ #include #include #include +#include #include +#ifdef _WIN32 +typedef long ssize_t; +#endif + namespace native { using MacOS::tool_return; diff --git a/native/native.cpp b/native/native.cpp index 82a25e5..b117ef1 100644 --- a/native/native.cpp +++ b/native/native.cpp @@ -25,15 +25,17 @@ */ + #include "native_internal.h" #include #include +#include +#include + #include #include -#include #include -#include #include