Skip to content

Commit

Permalink
Add MS_PRINT_FUNC_FORMAT() macro to be able to decorate printf()-like…
Browse files Browse the repository at this point in the history
… functions, like msSetError(), msDebug(), msIO_printf(), etc...
  • Loading branch information
rouault committed Jul 6, 2013
1 parent dfea815 commit 77f9b81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions maperror.h
Expand Up @@ -92,6 +92,14 @@ extern "C" {
# define MS_DLL_EXPORT __declspec(dllexport)
#else
#define MS_DLL_EXPORT
#endif

#ifndef MS_PRINT_FUNC_FORMAT
#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
#else
#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx )
#endif
#endif

typedef struct errorObj {
Expand All @@ -114,7 +122,7 @@ extern "C" {
MS_DLL_EXPORT char *msGetErrorString(char *delimiter);

#ifndef SWIG
MS_DLL_EXPORT void msSetError(int code, const char *message, const char *routine, ...);
MS_DLL_EXPORT void msSetError(int code, const char *message, const char *routine, ...) MS_PRINT_FUNC_FORMAT(2,4) ;
MS_DLL_EXPORT void msWriteError(FILE *stream);
MS_DLL_EXPORT void msWriteErrorXML(FILE *stream);
MS_DLL_EXPORT char *msGetErrorCodeString(int code);
Expand Down Expand Up @@ -157,7 +165,7 @@ extern "C" {
} debugInfoObj;


MS_DLL_EXPORT void msDebug( const char * pszFormat, ... );
MS_DLL_EXPORT void msDebug( const char * pszFormat, ... ) MS_PRINT_FUNC_FORMAT(1,2) ;
MS_DLL_EXPORT int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath);
MS_DLL_EXPORT void msCloseErrorFile( void );
MS_DLL_EXPORT const char *msGetErrorFile( void );
Expand Down
14 changes: 11 additions & 3 deletions mapio.h
Expand Up @@ -40,11 +40,19 @@

#ifdef __cplusplus
extern "C" {
#endif

#ifndef MS_PRINT_FUNC_FORMAT
#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
#else
#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx )
#endif
#endif

/* stdio analogs */
int MS_DLL_EXPORT msIO_printf( const char *format, ... );
int MS_DLL_EXPORT msIO_fprintf( FILE *stream, const char *format, ... );
int MS_DLL_EXPORT msIO_printf( const char *format, ... ) MS_PRINT_FUNC_FORMAT(1,2);
int MS_DLL_EXPORT msIO_fprintf( FILE *stream, const char *format, ... ) MS_PRINT_FUNC_FORMAT(2,3);
int MS_DLL_EXPORT msIO_fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream );
int MS_DLL_EXPORT msIO_fread( void *ptr, size_t size, size_t nmemb, FILE *stream );
int MS_DLL_EXPORT msIO_vfprintf( FILE *fp, const char *format, va_list ap );
Expand All @@ -71,7 +79,7 @@ extern "C" {
msIOContext *stdout_context,
msIOContext *stderr_context );
msIOContext MS_DLL_EXPORT *msIO_getHandler( FILE * );
void msIO_setHeader (const char *header, const char* value, ...);
void msIO_setHeader (const char *header, const char* value, ...) MS_PRINT_FUNC_FORMAT(2,3);
void msIO_sendHeaders(void);

/*
Expand Down

0 comments on commit 77f9b81

Please sign in to comment.