Skip to content

Commit

Permalink
dokan_fuse:Use macros for printing DWORD and ULONG
Browse files Browse the repository at this point in the history
DWORD and ULONG are defined as unsigned long int on Windows. Cygwin64 is
LP64. Thus it defines them as unsigned int (to keep them 32-bits wide).
In order to enable portable printing, we define macros modeled after
inttypes.h like for example PRIuDWORD or PRIxDWORD.

Using these macros ensures that the correct printf-format-specifier is
used depending on the platform.
  • Loading branch information
Rondom committed Sep 20, 2016
1 parent 20caf59 commit 038c0d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions dokan_fuse/include/dokanfuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
#define FUSE_THREAD_COUNT 10
#define DOKAN_DLL L"dokan" DOKAN_MAJOR_API_VERSION L".dll"

// Cygwin64 is LP64 while Windows 64bit is LLP64.
// This why we define macros in the style of inttypes.h for printing DWORDs and ULONGs which are fixed to 32 bit.
#ifdef __LP64__
// DWORD and ULONG are unsigned int
# define PRIxDWORD "%x"
# define PRIuDWORD "%u"
# define PRIxULONG "%x"
# define PRIuULONG "%u"
#else
// DWORD and ULONG are unsigned long int
# define PRIxDWORD "%lx"
# define PRIuDWORD "%lu"
# define PRIxULONG "%lx"
# define PRIuULONG "%lu"
#endif

struct fuse_config
{
unsigned int umask;
Expand Down
10 changes: 5 additions & 5 deletions dokan_fuse/src/dokanfuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ CONST_END(cDisposition)
void DebugConstant(const char *name, ULONG value, Constant *c) {
while (c->name != NULL && c->value != value)
++c;
fprintf(stderr, "%s: %s (%lx)\n", name, c->name ? c->name : "unknown!",
fprintf(stderr, "%s: %s (" PRIxULONG ")\n", name, c->name ? c->name : "unknown!",
value);
}

Expand Down Expand Up @@ -177,9 +177,9 @@ FuseCreateFile(LPCWSTR FileName, PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
DebugConstantBit("\tDesiredAccess", DesiredAccess, cAccessMode);
DebugConstantBit("\tShareAccess", ShareAccess, cShareMode);
DebugConstant("\tDisposition", CreateDisposition, cDisposition);
FPRINTF(stderr, "\tAttributes: %u (0x%x)\n", FileAttributes,
FPRINTF(stderr, "\tAttributes: " PRIuULONG " (0x" PRIxULONG ")\n", FileAttributes,
FileAttributes);
FPRINTF(stderr, "\tOptions: %u (0x%x)\n", CreateOptions, CreateOptions);
FPRINTF(stderr, "\tOptions: " PRIuULONG " (0x" PRIxULONG ")\n", CreateOptions, CreateOptions);
fflush(stderr);
}

Expand Down Expand Up @@ -233,7 +233,7 @@ static NTSTATUS DOKAN_CALLBACK FuseWriteFile(LPCWSTR FileName, LPCVOID Buffer,
PDOKAN_FILE_INFO DokanFileInfo) {
impl_fuse_context *impl = the_impl;
if (impl->debug())
FPRINTF(stderr, "WriteFile: %ls, offset %lld, length %lu\n", FileName,
FPRINTF(stderr, "WriteFile: %ls, offset %lld, length " PRIuDWORD "\n", FileName,
Offset, NumberOfBytesToWrite);

impl_chain_guard guard(impl, DokanFileInfo->ProcessId);
Expand Down Expand Up @@ -439,7 +439,7 @@ FuseGetFileSecurity(LPCWSTR FileName, PSECURITY_INFORMATION SecurityInformation,
PULONG LengthNeeded, PDOKAN_FILE_INFO DokanFileInfo) {
impl_fuse_context *impl = the_impl;
if (impl->debug())
FPRINTF(stderr, "GetFileSecurity: %x\n", *SecurityInformation);
FPRINTF(stderr, "GetFileSecurity: " PRIxDWORD "\n", *SecurityInformation);

BY_HANDLE_FILE_INFORMATION byHandleFileInfo;
ZeroMemory(&byHandleFileInfo, sizeof(BY_HANDLE_FILE_INFORMATION));
Expand Down

0 comments on commit 038c0d4

Please sign in to comment.