#ifndef UTILITY_H_
#define UTILITY_H_
-#define UTILITY_H_CVSID "$Id: utility.h 3285 2011-03-04 22:08:49Z chrfranke $"
+#define UTILITY_H_CVSID "$Id: utility.h 3475 2011-11-10 21:43:40Z chrfranke $"
#include <time.h>
#include <sys/types.h> // for regex.h (according to POSIX)
#include <string.h>
#include <string>
-#if !defined(__GNUC__) && !defined(__attribute__)
-#define __attribute__(x) /**/
+#ifndef __GNUC__
+#define __attribute_format_printf(x, y) /**/
+#elif defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO
+// Check format of __mingw_*printf() instead of MSVCRT.DLL:*printf()
+#define __attribute_format_printf(x, y) __attribute__((format (gnu_printf, x, y)))
+#define HAVE_WORKING_SNPRINTF 1
+#else
+#define __attribute_format_printf(x, y) __attribute__((format (printf, x, y)))
#endif
// Make version information string
// return (v)sprintf() formated std::string
std::string strprintf(const char * fmt, ...)
- __attribute__ ((format (printf, 1, 2)));
+ __attribute_format_printf(1, 2);
std::string vstrprintf(const char * fmt, va_list ap);
#ifndef HAVE_WORKING_SNPRINTF
// Substitute by safe replacement functions
int safe_snprintf(char *buf, int size, const char *fmt, ...)
- __attribute__ ((format (printf, 3, 4)));
+ __attribute_format_printf(3, 4);
int safe_vsnprintf(char *buf, int size, const char *fmt, va_list ap);
#define snprintf safe_snprintf
#define vsnprintf safe_vsnprintf
// itself is defined differently in smartctl and smartd. So the
// function definition(s) are in smartd.c and in smartctl.c.
void pout(const char *fmt, ...)
- __attribute__ ((format (printf, 1, 2)));
+ __attribute_format_printf(1, 2);
// replacement for perror() with redirected output.
void syserror(const char *message);
// convert time in msec to a text string
void MsecToText(unsigned int msec, char *txt);
+// Format integer with thousands separator
+const char * format_with_thousands_sep(char * str, int strsize, uint64_t val,
+ const char * thousands_sep = 0);
+
+// Format capacity with SI prefixes
+const char * format_capacity(char * str, int strsize, uint64_t val,
+ const char * decimal_point = 0);
+
// Wrapper class for a raw data buffer
class raw_buffer
{