From a516f84ef4d4f7e741b8a2303ccaf27035f5acb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wolfgang=20St=C3=B6ggl?= Date: Sat, 20 Jul 2019 13:20:12 +0200 Subject: [PATCH] Cleanup ssize_t, off_t and strtoll() for MSVC MSVC defines the standard type off_t. Remove unneeded off_t typedef. So far there has been a "typedef size_t ssize_t" in case of _MSC_VER, which is incorrect because size_t is unsigned and ssize_t signed. MSVC supports SSIZE_T (in capital letters). It is sufficient to have the typedef SSIZE_T ssize_t in rrd.h - remove redundant, obsolete code from rrd_restore.c The function strtoll() is supported since Visual Studio 2013. In rrd_resize.c, b_read is ssize_t. Use %zd in fprintf() as format specifier, because ssize_t is signed. --- src/rrd.h | 10 +++++----- src/rrd_resize.c | 2 +- src/rrd_restore.c | 5 ----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/rrd.h b/src/rrd.h index f6fe84e3..155cd65e 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -56,17 +56,17 @@ extern "C" { #ifndef _WIN32 #include /* for off_t */ -#else +#endif + #ifdef _MSC_VER +#include + typedef SSIZE_T ssize_t; #ifndef PERLPATCHLEVEL typedef int mode_t; #endif +#if _MSC_VER < 1800 #define strtoll _strtoi64 #endif -#ifndef __MINGW32__ /* MinGW-w64 has ssize_t and off_t */ - typedef size_t ssize_t; - typedef long off_t; -#endif #endif #include diff --git a/src/rrd_resize.c b/src/rrd_resize.c index 8d282e87..44c1ee57 100644 --- a/src/rrd_resize.c +++ b/src/rrd_resize.c @@ -255,7 +255,7 @@ int rrd_resize( if ((b_read=rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1)) <= 0) break; if(rrd_out_file->pos+b_read > rrd_out_file->file_len) { - fprintf(stderr,"WARNING: ignoring last %zu bytes\nWARNING: if you see this message multiple times for a single file you're in trouble\n", b_read); + fprintf(stderr,"WARNING: ignoring last %zd bytes\nWARNING: if you see this message multiple times for a single file you're in trouble\n", b_read); continue; } rrd_write(rrd_out_file, &buffer, b_read); diff --git a/src/rrd_restore.c b/src/rrd_restore.c index a931dccd..14b9446b 100644 --- a/src/rrd_restore.c +++ b/src/rrd_restore.c @@ -25,11 +25,6 @@ #ifndef _WIN32 # include /* for off_t */ -#else -#ifndef __MINGW32__ /* MinGW-w64 has ssize_t and off_t */ - typedef size_t ssize_t; - typedef long off_t; -#endif #endif #include -- 2.47.2