Some compilers, e.g. Microsoft Visual C++, don't define __STDC__ unless

extensions to ANSI C are disabled if they may cause strictly conforming
programs not to compile, or to work differently if those extensions are
enabled.  (Other compilers #define it as 0, e.g.  Sun's and, I think,
other AT&T-derived compilers; still others cheerfully define it as 1
even when those extensions are enabled, e.g. GCC.)

As such, checking whether __STDC__ is defined, or is defined as a
non-zero value, isn't the right way to check whether function prototypes
are supported; MSVC++ 6.0 supports them, but, by default, leaves
extensions of the sort described above enabled, and thus doesn't define
__STDC__.  This means that the compiler warns about arguments to
"snprintf()" when compiling it, as the declaration is an old-style
declaration.

As Ethereal uses function prototypes, there's not much point in making
it possible for its private "snprintf()" to be compiled or used when
function prototypes aren't supported; just get rid of the tests for
__STDC__, so that it's compiled with function prototypes regardless of
whether __STDC__ is defined or not.

While we're at it, have "snprintf()" give it a "__attribute__((format
(printf, 3, 4))))" when compiled by GCC 2.x or later, so that
format/argument checks can be done even on platforms lacking
"snprintf()".

svn path=/trunk/; revision=2689
This commit is contained in:
Guy Harris 2000-11-21 21:24:52 +00:00
parent de9a50d3e7
commit 90eccd89b8
2 changed files with 8 additions and 90 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: snprintf.c,v 1.11 2000/08/11 22:03:02 guy Exp $
* $Id: snprintf.c,v 1.12 2000/11/21 21:24:52 guy Exp $
*/
/*
@ -57,12 +57,7 @@
* Find the nth power of 10
*/
PRIVATE double
#ifdef __STDC__
pow_10(int n)
#else
pow_10(n)
int n;
#endif
{
int i;
double P;
@ -83,12 +78,7 @@ int n;
* log_10(250) = 2;
*/
PRIVATE int
#ifdef __STDC__
log_10(double r)
#else
log_10(r)
double r;
#endif
{
int i = 0;
double result = 1.;
@ -113,13 +103,7 @@ double r;
* In many ways it resemble the modf() found on most Un*x
*/
PRIVATE double
#ifdef __STDC__
integral(double real, double * ip)
#else
integral(real, ip)
double real;
double * ip;
#endif
{
int j;
double i, s, p;
@ -161,15 +145,7 @@ double * ip;
* declare with fix size
*/
PRIVATE char *
#ifdef __STDC__
numtoa(double number, int base, int precision, char ** fract)
#else
numtoa(number, base, precision, fract)
double number;
int base;
int precision;
char ** fract;
#endif
{
register int i, j;
double ip, fp; /* integer and fraction part */
@ -248,13 +224,7 @@ char ** fract;
* the representation with the right padding
*/
PRIVATE void
#ifdef __STDC__
decimal(struct DATA *p, double d)
#else
decimal(p, d)
struct DATA *p;
double d;
#endif
{
char *tmp;
@ -272,13 +242,7 @@ double d;
/* for %o octal representation */
PRIVATE void
#ifdef __STDC__
octal(struct DATA *p, double d)
#else
octal(p, d)
struct DATA *p;
double d;
#endif
{
char *tmp;
@ -296,13 +260,7 @@ double d;
/* for %x %X hexadecimal representation */
PRIVATE void
#ifdef __STDC__
hexa(struct DATA *p, double d)
#else
hexa(p, d)
struct DATA *p;
double d;
#endif
{
char *tmp;
@ -321,13 +279,7 @@ double d;
/* %s strings */
PRIVATE void
#ifdef __STDC__
strings(struct DATA *p, char *tmp)
#else
strings(p, tmp)
struct DATA *p;
char *tmp;
#endif
{
int i;
@ -345,13 +297,7 @@ char *tmp;
/* %f or %g floating point representation */
PRIVATE void
#ifdef __STDC__
floating(struct DATA *p, double d)
#else
floating(p, d)
struct DATA *p;
double d;
#endif
{
char *tmp, *tmp2;
int i;
@ -384,13 +330,7 @@ double d;
/* %e %E %g exponent representation */
PRIVATE void
#ifdef __STDC__
exponent(struct DATA *p, double d)
#else
exponent(p, d)
struct DATA *p;
double d;
#endif
{
char *tmp, *tmp2;
int j, i;
@ -445,13 +385,7 @@ double d;
/* initialize the conversion specifiers */
PRIVATE void
#ifdef __STDC__
conv_flag(char * s, struct DATA * p)
#else
conv_flag(s, p)
char * s;
struct DATA * p;
#endif
{
char number[MAX_FIELD/2];
int i;
@ -495,15 +429,7 @@ struct DATA * p;
}
PUBLIC int
#ifdef __STDC__
vsnprintf(char *string, size_t length, const char * format, va_list args)
#else
vsnprintf(string, length, format, args)
char *string;
size_t length;
char * format;
va_list args;
#endif
{
struct DATA data;
char conv_field[MAX_FIELD];
@ -653,20 +579,12 @@ va_list args;
#ifndef HAVE_SNPRINTF
PUBLIC int
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
snprintf(char *string, size_t length, const char * format, ...)
#else
snprintf(string, length, format, va_alist)
char *string;
size_t length;
char * format;
va_dcl
#endif
{
int rval;
va_list args;
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
#if defined(HAVE_STDARG_H)
va_start(args, format);
#else
va_start(args);

View File

@ -1,11 +1,11 @@
/*
* $Id: snprintf.h,v 1.4 2000/08/11 22:00:49 guy Exp $
* $Id: snprintf.h,v 1.5 2000/11/21 21:24:52 guy Exp $
*/
#ifndef __ETHEREAL_SNPRINTF_H__
#define __ETHEREAL_SNPRINTF_H__
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
#if defined(HAVE_STDARG_H)
# include <stdarg.h>
#else
# include <varargs.h>
@ -14,11 +14,11 @@
extern int vsnprintf(char *string, size_t length, const char * format,
va_list args);
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
extern int snprintf(char *string, size_t length, const char * format, ...);
#if __GNUC__ == 2
extern int snprintf(char *string, size_t length, const char * format, ...)
__attribute__((format (printf, 3, 4)));
#else
extern int snprintf(char *string, size_t length, const char * format,
int va_alist);
extern int snprintf(char *string, size_t length, const char * format, ...);
#endif
#endif