#include <stdio.h>
#include <string.h>
+#include <stdarg.h>
+#include <ick_lose.h>
#include "uncommon.h"
/* Options that might affect this */
else
return NULL;
}
+
+/**
+ * Invoke snprintf(), if supported. Otherwise invoke sprintf() and abort
+ * if we did overflow.
+ */
+int ick_snprintf_or_die(char *str, size_t size, const char *format, ...)
+{
+ va_list ap;
+ int retval;
+ va_start(ap, format);
+#ifdef HAVE_SNPRINTF
+ retval = vsnprintf(str, size, format, ap);
+#else
+ retval = vsprintf(str, format, ap);
+ /* TODO: Replace with some nice ick_lose(). */
+ if (retval >= size)
+ abort();
+#endif
+ va_end(ap);
+ return retval;
+}
/*@null@*/ /*@dependent@*/ extern FILE* ick_findandfopen(/*@observer@*/ const char*, /*@observer@*/ const char*, /*@observer@*/ const char*, /*@observer@*/ const char*);
/*@observer@*/ /*@null@*/ extern const char* ick_findandtestopen(/*@observer@*/ const char*, /*@observer@*/ const char*, /*@observer@*/ const char*, /*@observer@*/ const char*);
/*@null@*/ /*@dependent@*/ extern FILE* ick_findandfreopen(/*@observer@*/ const char*, /*@observer@*/ const char*, /*@observer@*/ const char*, /*@observer@*/ const char*, FILE*);
+extern int ick_snprintf_or_die(char *str, size_t size, const char *format, ...)
+#ifdef __GNUC__
+ __attribute__ ((format(printf, 3, 4)))
+#endif
+;