Commit b1655f1e authored by Kenneth Moreland's avatar Kenneth Moreland

Fix portable implementations with GNU compiler

The GNU compiler is being strict about POSIX compliance. Explicitly
port those things outside of POSIX (like snprintf).
parent f577114f
......@@ -69,7 +69,7 @@ void icetRaiseDiagnostic(IceTEnum type,
full_message[0] = '\0';
offset = 0;
#define ADD_TO_MESSAGE(...) \
offset += snprintf(full_message + offset, \
offset += icetSnprintf(full_message + offset, \
ICET_MESSAGE_SIZE - offset, \
__VA_ARGS__); \
if (offset > ICET_MESSAGE_SIZE) { \
......
......@@ -7,12 +7,18 @@
* This source code is released under the New BSD License.
*/
/* Turn on non-POSIX features of GNU. Many of these are widely available. */
#define _GNU_SOURCE
#include <IceTDevPorting.h>
#include <IceT.h>
#include <IceTDevDiagnostics.h>
#include <stdlib.h>
#include <stdarg.h>
#ifndef WIN32
#include <sys/time.h>
#else
......@@ -125,3 +131,20 @@ void icetPutEnv(const char *name, const char *value)
_putenv_s(name, value);
}
#endif /*WIN32*/
ICET_EXPORT IceTSizeType icetSnprintf(char *buffer, IceTSizeType size,
const char *format, ...)
{
va_list format_args;
IceTSizeType num_written;
va_start(format_args, format);
#ifdef WIN32
num_written = _vsnprintf_s(buffer, size, _TRUNCATE, format, format_args);
#else
num_written = vsnprintf(buffer, size, format, format_args);
#endif
va_end(format_args);
return num_written;
}
......@@ -27,8 +27,6 @@ extern "C" {
ICET_EXPORT IceTInt icetTypeWidth(IceTEnum type);
#ifdef WIN32
#define snprintf(buffer, size, ...) \
_snprintf_s(buffer, size, _TRUNCATE, __VA_ARGS__)
#define strncpy(dest, src, size) strncpy_s(dest, size, src, _TRUNCATE)
#define fdopen _fdopen
#endif
......@@ -44,6 +42,11 @@ ICET_EXPORT IceTBoolean icetGetEnv(const char *variable_name,
value as separate arguments. */
ICET_EXPORT void icetPutEnv(const char *name, const char *value);
/* A portable version of snprintf. The behavior might not be perfectly
consistent across platforms. */
ICET_EXPORT IceTSizeType icetSnprintf(char *buffer, IceTSizeType size,
const char *format, ...);
#ifdef __cplusplus
}
#endif
......
......@@ -110,10 +110,10 @@ static void DisplayNoDrawDoTest(void)
if (bad_count >= 10) {
char filename[256];
global_result = TEST_FAILED;
snprintf(filename, 256, "DisplayNoDraw_%s_%s_%d.ppm",
icetGetStrategyName(),
icetGetSingleImageStrategyName(),
global_iteration);
icetSnprintf(filename, 256, "DisplayNoDraw_%s_%s_%d.ppm",
icetGetStrategyName(),
icetGetSingleImageStrategyName(),
global_iteration);
write_ppm(filename, color_buffer,
(int)SCREEN_WIDTH, (int)SCREEN_HEIGHT);
}
......
......@@ -61,7 +61,7 @@ static IceTBoolean CheckPixel(const IceTImage image,
buffer = malloc(4*icetImageGetWidth(image)*icetImageGetHeight(image));
icetImageCopyColorub(image, buffer, ICET_IMAGE_COLOR_RGBA_UBYTE);
icetGetIntegerv(ICET_RANK, &rank);
snprintf(filename, 255, "FloatingViewport_%d.ppm", rank);
icetSnprintf(filename, 255, "FloatingViewport_%d.ppm", rank);
write_ppm(filename,
buffer,
icetImageGetWidth(image),
......
......@@ -253,7 +253,7 @@ static int MaxImageSplitTryMax()
printstat("Trying max image split of %d\n", max_image_split);
snprintf(image_split_string, 64, "%d", max_image_split);
icetSnprintf(image_split_string, 64, "%d", max_image_split);
icetPutEnv("ICET_MAX_IMAGE_SPLIT", image_split_string);
/* This is a bit hackish. The max image split value is set when the
......
......@@ -120,9 +120,9 @@ static int compare_color_buffers(IceTSizeType local_width,
/* Too many errors. Call it bad. */
printrank("Too many bad pixels!!!!!!\n");
/* Write current images. */
snprintf(filename, FILENAME_MAX, "ref%03d.ppm", rank);
icetSnprintf(filename, FILENAME_MAX, "ref%03d.ppm", rank);
write_ppm(filename, refcbuf, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT);
snprintf(filename, FILENAME_MAX, "bad%03d.ppm", rank);
icetSnprintf(filename, FILENAME_MAX, "bad%03d.ppm", rank);
write_ppm(filename, cb, (int)local_width, (int)local_height);
/* Write difference image. */
for (y = 0; y < local_height; y++) {
......@@ -146,7 +146,7 @@ static int compare_color_buffers(IceTSizeType local_width,
}
}
}
snprintf(filename, FILENAME_MAX, "diff%03d.ppm", rank);
icetSnprintf(filename, FILENAME_MAX, "diff%03d.ppm", rank);
write_ppm(filename, cb, (int)local_width, (int)local_height);
return 0;
}
......@@ -237,7 +237,7 @@ static int compare_depth_buffers(IceTSizeType local_width,
encoded[3] = 255;
}
}
snprintf(filename, FILENAME_MAX, "depth_error%03d.ppm", rank);
icetSnprintf(filename, FILENAME_MAX, "depth_error%03d.ppm", rank);
write_ppm(filename, (IceTUByte *)errbuf,
(int)local_width, (int)local_height);
......
......@@ -1113,14 +1113,14 @@ static int SimpleTimingDoRender()
IceTInt magic_k;
icetGetIntegerv(ICET_MAGIC_K, &magic_k);
snprintf(name_buffer, 256, "radix-k %d", (int)magic_k);
icetSnprintf(name_buffer, 256, "radix-k %d", (int)magic_k);
si_strategy_name = name_buffer;
} else if (g_single_image_strategy == ICET_SINGLE_IMAGE_STRATEGY_RADIXKR) {
static char name_buffer[256];
IceTInt magic_k;
icetGetIntegerv(ICET_MAGIC_K, &magic_k);
snprintf(name_buffer, 256, "radix-kr %d", (int)magic_k);
icetSnprintf(name_buffer, 256, "radix-kr %d", (int)magic_k);
si_strategy_name = name_buffer;
} else {
si_strategy_name = icetGetSingleImageStrategyName();
......@@ -1271,7 +1271,7 @@ static int SimpleTimingDoRender()
IceTUByte *buffer = malloc(SCREEN_WIDTH*SCREEN_HEIGHT*4);
char filename[256];
icetImageCopyColorub(image, buffer, ICET_IMAGE_COLOR_RGBA_UBYTE);
snprintf(filename, 256, "SimpleTiming%02d.ppm", rank);
icetSnprintf(filename, 256, "SimpleTiming%02d.ppm", rank);
write_ppm(filename, buffer, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT);
free(buffer);
}
......@@ -1348,7 +1348,7 @@ static int SimpleTimingDoParameterStudies()
char k_string[64];
int retval;
snprintf(k_string, 64, "%d", magic_k);
icetSnprintf(k_string, 64, "%d", magic_k);
icetPutEnv("ICET_MAGIC_K", k_string);
/* This is a bit hackish. The magic k value is set when the IceT
......@@ -1385,7 +1385,7 @@ static int SimpleTimingDoParameterStudies()
char image_split_string[64];
int retval;
snprintf(image_split_string, 64, "%d", image_split);
icetSnprintf(image_split_string, 64, "%d", image_split);
icetPutEnv("ICET_MAX_IMAGE_SPLIT", image_split_string);
/* This is a bit hackish. The max image split value is set when the
......
......@@ -220,7 +220,7 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
} else {
realstdout = NULL;
}
snprintf(filename, 64, "log.%04d", rank);
icetSnprintf(filename, 64, "log.%04d", rank);
#ifndef WIN32
outfd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
if (outfd < 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment