--- embedaddon/smartmontools/utility.h 2012/02/21 16:32:16 1.1 +++ embedaddon/smartmontools/utility.h 2012/10/09 09:36:45 1.1.1.2 @@ -4,7 +4,7 @@ * Home page of code is: http://smartmontools.sourceforge.net * * Copyright (C) 2002-11 Bruce Allen - * Copyright (C) 2008-11 Christian Franke + * Copyright (C) 2008-12 Christian Franke * Copyright (C) 2000 Michael Cornwell * * This program is free software; you can redistribute it and/or modify @@ -26,7 +26,7 @@ #ifndef UTILITY_H_ #define UTILITY_H_ -#define UTILITY_H_CVSID "$Id: utility.h,v 1.1 2012/02/21 16:32:16 misho Exp $" +#define UTILITY_H_CVSID "$Id: utility.h,v 1.1.1.2 2012/10/09 09:36:45 misho Exp $" #include #include // for regex.h (according to POSIX) @@ -36,8 +36,14 @@ #include #include -#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 @@ -45,13 +51,20 @@ std::string format_version_info(const char * prog_name // 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); +// Return true if STR starts with PREFIX +inline bool str_starts_with(const char * str, const char * prefix) + { return !strncmp(str, prefix, strlen(prefix)); } + +inline bool str_starts_with(const std::string & str, const char * prefix) + { return !strncmp(str.c_str(), prefix, strlen(prefix)); } + #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 @@ -75,7 +88,7 @@ void dateandtimezoneepoch(char *buffer, time_t tval); // 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);