From: Matthew Fernandez Date: Mon, 7 Feb 2022 05:29:27 +0000 (+1100) Subject: API BREAK: fix: typedef 'ssize_t' to 'SSIZE_T' on Windows X-Git-Tag: 3.0.0~38^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d56ff9fd7590e925e9211db213719886fb0c307e;p=graphviz API BREAK: fix: typedef 'ssize_t' to 'SSIZE_T' on Windows In several places, code was using `int` as a drop-in replacement for `ssize_t` on Windows where it does not exist. This is incorrect on some platforms. E.g. on x86-64 this will result in `ssize_t` being a 32-bit type instead of a 64-bit type. This change replaces it with the correct Windows equivalent, `SSIZE_T`.¹ ¹ https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types?redirectedfrom=MSDN#ssize_t Gitlab: fixes #1804 --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b65e7da9..4e978cc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- **Breaking**: GVPR now typedefs `ssize_t` as `SSIZE_T` on Windows instead of + `int` #1804 - fix detection of unavailable output format - SVG layout doesn't always respect requested size #1855 - mismatched format string in `mingle` diff --git a/config-cmake.h.in b/config-cmake.h.in index 0272b8b23..6003517a1 100644 --- a/config-cmake.h.in +++ b/config-cmake.h.in @@ -32,8 +32,13 @@ // Typedefs for missing types #ifndef HAVE_SSIZE_T +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; +#else typedef int ssize_t; #endif +#endif // Libraries #cmakedefine HAVE_ANN diff --git a/lib/gvpr/gvpr.h b/lib/gvpr/gvpr.h index 2e94a2036..8f40b2265 100644 --- a/lib/gvpr/gvpr.h +++ b/lib/gvpr/gvpr.h @@ -28,7 +28,8 @@ extern "C" { #include "cgraph.h" #ifdef _MSC_VER -typedef int ssize_t; +#include +typedef SSIZE_T ssize_t; #endif /* Bits for flags variable in gvprstate_t. diff --git a/windows/include/config.h b/windows/include/config.h index e645f94c7..69cc733d3 100644 --- a/windows/include/config.h +++ b/windows/include/config.h @@ -276,5 +276,6 @@ /* Define to `int' if does not define. */ /* #undef pid_t */ -/* Define to `int' if does not define. */ -typedef int ssize_t; +/* Define to `SSIZE_T' if does not define. */ +#include +typedef SSIZE_T ssize_t; diff --git a/windows/include/unistd.h b/windows/include/unistd.h index cc8e95598..e4aee9834 100644 --- a/windows/include/unistd.h +++ b/windows/include/unistd.h @@ -9,6 +9,7 @@ #include #include /* for getpid() and the exec..() family */ #include /* for _getcwd() and _chdir() */ +#include #define srandom srand #define random rand @@ -31,7 +32,7 @@ #define lseek _lseek /* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */ -#define ssize_t int +#define ssize_t SSIZE_T #define STDIN_FILENO 0 #define STDOUT_FILENO 1