mirror of
https://github.com/ksherlock/mpw.git
synced 2024-06-14 11:29:28 +00:00
misc updates.
This commit is contained in:
parent
2c22cac0ca
commit
4efee8a7ca
|
@ -92,7 +92,7 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
||||||
if (length == -1) {
|
if (length == -1) {
|
||||||
LARGE_INTEGER file_size;
|
LARGE_INTEGER file_size;
|
||||||
GetFileSizeEx(fh, &file_size);
|
GetFileSizeEx(fh, &file_size);
|
||||||
length = file_size.QuadPart;
|
length = (size_t)file_size.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length == 0) return;
|
if (length == 0) return;
|
||||||
|
@ -173,7 +173,7 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
|
|
||||||
|
|
||||||
file_size.QuadPart = 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();
|
if (!SetEndOfFile(fh)) throw_error();
|
||||||
|
|
||||||
mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0);
|
mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0);
|
||||||
|
|
|
@ -55,6 +55,46 @@
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
|
|
||||||
// https://github.com/HowardHinnant/hash_append/blob/master/endian.h
|
// https://github.com/HowardHinnant/hash_append/blob/master/endian.h
|
||||||
|
|
|
@ -170,7 +170,7 @@ tool_return<size_t> fd_file::set_eof(ssize_t new_eof) {
|
||||||
|
|
||||||
if (_interactive) return MacOS::paramErr;
|
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();
|
if (ok < 0) return macos_error_from_errno();
|
||||||
return new_eof;
|
return new_eof;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,14 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <macos/tool_return.h>
|
#include <macos/tool_return.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
typedef long ssize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace native {
|
namespace native {
|
||||||
|
|
||||||
using MacOS::tool_return;
|
using MacOS::tool_return;
|
||||||
|
|
|
@ -25,15 +25,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "native_internal.h"
|
#include "native_internal.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user