+/* Assuming presence of s, rc, maxsize.
+ Checks index for valid range, target buffer for sufficient remaining
+ capacity, and copies the locale-specific string (or "?" if index out
+ of range). Returns with zero if buffer capacity insufficient.
+*/
+#define SPRINTSTR( array, index, max ) \
+ { \
+ int ind = (index); \
+ const char * str = "?"; \
+ if ( ind >= 0 && ind <= max ) \
+ { \
+ str = array[ ind ]; \
+ } \
+ size_t len = strlen( str ); \
+ if ( rc < ( maxsize - len ) ) \
+ { \
+ strcpy( s + rc, str ); \
+ rc += len; \
+ } \
+ else \
+ { \
+ return 0; \
+ } \
+ }
+
+#define SPRINTREC( format ) \
+ { \
+ size_t count = strftime( s + rc, maxsize - rc, format, timeptr ); \
+ if ( count == 0 ) \
+ { \
+ return 0; \
+ } \
+ else \
+ { \
+ rc += count; \
+ } \
+ }
+