diff --git a/ChangeLog.txt b/ChangeLog.txt index 38098d77..ff71f4e0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,7 @@ Broker: - Various fixes around inflight quota management. Closes #2306. - Fix problem parsing config files with Windows line endings. Closes #2297. - Don't send retained messages when a shared subscription is made. +- Fix log being truncated in Windows. Client library: - Initialise sockpairR/W to invalid in `mosquitto_reinitialise()` to avoid diff --git a/lib/misc_mosq.c b/lib/misc_mosq.c index a00f8433..1a9c7993 100644 --- a/lib/misc_mosq.c +++ b/lib/misc_mosq.c @@ -32,6 +32,7 @@ Contributors: # include # include # include +# include #else # include #endif @@ -45,6 +46,8 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) #ifdef WIN32 char buf[4096]; int rc; + int flags = 0; + rc = ExpandEnvironmentStringsA(path, buf, 4096); if(rc == 0 || rc > 4096){ return NULL; @@ -64,9 +67,11 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) switch(mode[0]){ case 'a': dwCreationDisposition = OPEN_ALWAYS; + flags = _O_APPEND; break; case 'r': dwCreationDisposition = OPEN_EXISTING; + flags = _O_RDONLY; break; case 'w': dwCreationDisposition = CREATE_ALWAYS; @@ -88,6 +93,7 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) return NULL; } + memset(&sec, 0, sizeof(sec)); sec.nLength = sizeof(SECURITY_ATTRIBUTES); sec.bInheritHandle = FALSE; sec.lpSecurityDescriptor = &sd; @@ -100,7 +106,7 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) LocalFree(pacl); - fd = _open_osfhandle((intptr_t)hfile, 0); + fd = _open_osfhandle((intptr_t)hfile, flags); if (fd < 0) { return NULL; }