Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use decltype instead of typeof, use GetSystemInfo on Windows #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions output_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <sys/mman.h>
#define O_BINARY 0
#else
#include <sysinfoapi.h>
#define ftruncate64 ftruncate
#endif

Expand All @@ -50,8 +51,8 @@

#define min(a, b) \
({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
decltype(a) _a = (a); \
decltype(b) _b = (b); \
(_a < _b) ? _a : _b; \
})

Expand Down Expand Up @@ -656,8 +657,13 @@ int write_fd_chunk(struct output_file* out, unsigned int len, int fd, int64_t of
int aligned_diff;
uint64_t buffer_size;
char* ptr;

#ifdef _WIN32
SYSTEM_INFO si;
GetSystemInfo(&si);
aligned_offset = offset & ~(si.dwPageSize - 1);
#else
aligned_offset = offset & ~(sysconf(_SC_PAGESIZE) - 1);
#endif
aligned_diff = offset - aligned_offset;
buffer_size = (uint64_t)len + (uint64_t)aligned_diff;

Expand Down