misc updates.

This commit is contained in:
Kelvin Sherlock 2016-11-11 12:02:06 -05:00
parent 2c22cac0ca
commit 4efee8a7ca
5 changed files with 52 additions and 5 deletions

View File

@ -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);

View File

@ -55,6 +55,46 @@
#endif
#ifdef _WIN32
#include <stdlib.h>
#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

View File

@ -170,7 +170,7 @@ tool_return<size_t> 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;
}

View File

@ -5,9 +5,14 @@
#include <memory>
#include <string>
#include <stddef.h>
#include <sys/types.h>
#include <macos/tool_return.h>
#ifdef _WIN32
typedef long ssize_t;
#endif
namespace native {
using MacOS::tool_return;

View File

@ -25,15 +25,17 @@
*/
#include "native_internal.h"
#include <string>
#include <algorithm>
#include <unistd.h>
#include <strings.h>
#include <cctype>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>