tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Adding missing __printflike attributions

On Sun, Mar 04, 2012 at 03:35:27PM -0500, Julio Merino wrote:
> Except that the code lives in external/bsd/atf/ and is shipped in
> other systems that do not have __printflike.
> __printflike is a NetBSD-ism, right?  If so, why do you think NetBSD
> is more important than any other system and thus __printflike has to
> be used?

What I usually do in circumstances like this is to reproduce the
definition from <sys/cdefs.h> in my own sources, and add a cpp check
to only define them if they're not already defined:

#ifndef __printflike
 * Compiler-dependent macros to declare that functions take printf-like 
 * or scanf-like arguments.  They are null except for versions of gcc
 * that are known to support the features properly (old versions of gcc-2   
 * didn't permit keeping the keywords out of the application namespace). 
#  if __GNUC_PREREQ__(2, 7)
#    define __printflike(fmtarg, firstvararg)       \
            __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
#    define __scanflike(fmtarg, firstvararg)        \
            __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
#    define __format_arg(fmtarg)    __attribute__((__format_arg__ (fmtarg)))
#  else
#    define __printflike(fmtarg, firstvararg)       /* nothing */
#    define __scanflike(fmtarg, firstvararg)        /* nothing */
#    define __format_arg(fmtarg)                    /* nothing */
#  endif

(the indentation is mine).


Home | Main Index | Thread Index | Old Index