delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/11/13/14:48:58

From: "Juan Manuel Guerrero" <ST001906 AT HRZ1 DOT HRZ DOT TU-Darmstadt DOT De>
Organization: Darmstadt University of Technology
To: djgpp-workers AT delorie DOT com
Date: Mon, 13 Nov 2000 20:46:56 +0200
MIME-Version: 1.0
Subject: Re: Summary of the snprintf() situation
X-mailer: Pegasus Mail for Windows (v2.54DE)
Message-ID: <14EC05411785@HRZ1.hrz.tu-darmstadt.de>
Reply-To: djgpp-workers AT delorie DOT com

Date: Thu, 09 Nov 2000 00:07:21 +0000
From: Richard Dawe <richdawe AT bigfoot DOT com>

<SNIP>
> DJ Delorie expressed concern that the prototypes in stdio.h could conflict
> with packages that provide their own *snprintf functions. He gave an
> example: "For example, we don't prototype xmalloc() even though we provide
> it, because the prototypes used by actual software vary widely."
<SNIP>
> To DJ's concerns about packages including their own snprintf(), Eli
> Zaretskii said that he had not seen any packages that use these functions
> and asked if people could see what declarations packages used.
<SNIP>

A couple of weeks ago I "ported" for my own use the latest version of
Berkeley's DBM (version 3.1.17; no longer included into glibc; can be downloaded www.Sleepycat.com).
This software expects some kind of flock() function (not the issue in this mail)
and snprintf() and vsnprintf(). If the configuration script can not find the
above printf() functions in libc.a it uses it own ones.
Because both functions are small, I include the complete code of both in this mail.
This is an example of what a package may expect that snprintf() and vsnprintf()
definitions looks like.
Hope the information is of some use.

Regards,
Guerrero, Juan M.

diff -acrpNC3 1/snprintf.c 2/snprintf.c
*** 1/snprintf.c	Thu Jan  1 00:00:00 1970
--- 2/snprintf.c	Thu May 18 19:24:58 2000
***************
*** 0 ****
--- 1,65 ----
+ /*-
+  * See the file LICENSE for redistribution information.
+  *
+  * Copyright (c) 1996, 1997, 1998, 1999, 2000
+  *	Sleepycat Software.  All rights reserved.
+  */
+ 
+ #include "db_config.h"
+ 
+ #ifndef lint
+ static const char revid[] = "$Id: snprintf.c,v 11.4 2000/05/18 19:24:59 bostic Exp $";
+ #endif /* not lint */
+ 
+ #ifndef NO_SYSTEM_INCLUDES
+ #include <sys/types.h>
+ 
+ #include <stdio.h>
+ #endif
+ 
+ #include "db_int.h"
+ 
+ /*
+  * snprintf --
+  *	Bounded version of sprintf.
+  *
+  * PUBLIC: #ifndef HAVE_SNPRINTF
+  * PUBLIC: #ifdef __STDC__
+  * PUBLIC: int snprintf __P((char *, size_t, const char *, ...));
+  * PUBLIC: #else
+  * PUBLIC: int snprintf();
+  * PUBLIC: #endif
+  * PUBLIC: #endif
+  */
+ #ifndef HAVE_SNPRINTF
+ int
+ #ifdef __STDC__
+ snprintf(char *str, size_t n, const char *fmt, ...)
+ #else
+ snprintf(str, n, fmt, va_alist)
+ 	char *str;
+ 	size_t n;
+ 	const char *fmt;
+ 	va_dcl
+ #endif
+ {
+ 	va_list ap;
+ 	int rval;
+ 
+ 	COMPQUIET(n, 0);
+ #ifdef __STDC__
+ 	va_start(ap, fmt);
+ #else
+ 	va_start(ap);
+ #endif
+ #ifdef SPRINTF_RET_CHARPNT
+ 	(void)vsprintf(str, fmt, ap);
+ 	va_end(ap);
+ 	return (strlen(str));
+ #else
+ 	rval = vsprintf(str, fmt, ap);
+ 	va_end(ap);
+ 	return (rval);
+ #endif
+ }
+ #endif
diff -acrpNC3 1/vsnprint.c 2/vsnprint.c
*** 1/vsnprint.c	Thu Jan  1 00:00:00 1970
--- 2/vsnprint.c	Thu May 18 19:24:58 2000
***************
*** 0 ****
--- 1,47 ----
+ /*-
+  * See the file LICENSE for redistribution information.
+  *
+  * Copyright (c) 1996, 1997, 1998, 1999, 2000
+  *	Sleepycat Software.  All rights reserved.
+  */
+ 
+ #include "db_config.h"
+ 
+ #ifndef lint
+ static const char revid[] = "$Id: vsnprintf.c,v 11.4 2000/05/18 19:24:59 bostic Exp $";
+ #endif /* not lint */
+ 
+ #ifndef NO_SYSTEM_INCLUDES
+ #include <sys/types.h>
+ 
+ #include <stdio.h>
+ #endif
+ 
+ #include "db_int.h"
+ 
+ /*
+  * vsnprintf --
+  *	Bounded version of vsprintf.
+  *
+  * PUBLIC: #ifndef HAVE_VSNPRINTF
+  * PUBLIC: int vsnprintf();
+  * PUBLIC: #endif
+  */
+ #ifndef HAVE_VSNPRINTF
+ int
+ vsnprintf(str, n, fmt, ap)
+ 	char *str;
+ 	size_t n;
+ 	const char *fmt;
+ 	va_list ap;
+ {
+ 	COMPQUIET(n, 0);
+ 
+ #ifdef SPRINTF_RET_CHARPNT
+ 	(void)vsprintf(str, fmt, ap);
+ 	return (strlen(str));
+ #else
+ 	return (vsprintf(str, fmt, ap));
+ #endif
+ }
+ #endif

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019