From 7a5656a4aefdc3af698cdc8f5e2fc55b7743fa5d Mon Sep 17 00:00:00 2001 From: Jeremy Kniager Date: Mon, 17 Jun 2019 14:04:38 -0600 Subject: vulkaninfo: Fix issue 202 Vulkaninfo was replacing function `snprintf` with function `_snprintf` on windows. This seems to be for backwards compatiblity with VS2013. `_snprintf` is considered deprecated in VS2015 as `snprintf` is properly implemented. Since we are dropping compatibility with VS2013 it seems like this replacement should be removed. Due to AppVeyor failing to build when this pre-processor command is removed entirely, the command has been modified to replace `snprintf` with `_snprintf_s`. This command should hopefully be removed entirely in a future commit. Change-Id: I85f726fcb0a1cfcc902487100d35dc63d2ba00d8 --- vulkaninfo/vulkaninfo.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vulkaninfo/vulkaninfo.c b/vulkaninfo/vulkaninfo.c index 888055be..e96df728 100644 --- a/vulkaninfo/vulkaninfo.c +++ b/vulkaninfo/vulkaninfo.c @@ -58,7 +58,6 @@ #ifdef _WIN32 -#define snprintf _snprintf #define strdup _strdup // Returns nonzero if the console is used only for this process. Will return @@ -4950,7 +4949,11 @@ static char *HumanReadable(const size_t sz) { if (which >= 0) { unit[0] = prefixes[which]; } +#ifdef _WIN32 + _snprintf_s(buf, kBufferSize * sizeof(char), kBufferSize, "%.2f %sB", result, unit); +#else snprintf(buf, kBufferSize, "%.2f %sB", result, unit); +#endif return strndup(buf, kBufferSize); } @@ -5561,7 +5564,11 @@ int main(int argc, char **argv) { AppCreateInstance(&inst); if (html_output) { +#ifdef _WIN32 + if (fopen_s(&out, "vulkaninfo.html", "w") != 0) out = NULL; +#else out = fopen("vulkaninfo.html", "w"); +#endif if (!out) { printf("Unable to open vulkaninfo.html for writing\n"); return 1; @@ -5648,8 +5655,13 @@ int main(int argc, char **argv) { VkLayerProperties const *layer_prop = &inst.global_layers[i].layer_properties; ExtractVersion(layer_prop->specVersion, &layer_major, &layer_minor, &layer_patch); +#ifdef _WIN32 + _snprintf_s(spec_version, sizeof(spec_version), 64, "%d.%d.%d", layer_major, layer_minor, layer_patch); + _snprintf_s(layer_version, sizeof(layer_version), 64, "%d", layer_prop->implementationVersion); +#else snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", layer_major, layer_minor, layer_patch); snprintf(layer_version, sizeof(layer_version), "%d", layer_prop->implementationVersion); +#endif if (html_output) { fprintf(out, "\t\t\t\t
"); -- cgit v1.2.3