develooper Front page | perl.perl5.porters | Postings from January 2006

[PATCH] snprintf() and vsnprintf() (was Re: [PATCH] Configure: stdio char (un)signedness)

Thread Previous | Thread Next
From:
Steve Peters
Date:
January 2, 2006 07:37
Subject:
[PATCH] snprintf() and vsnprintf() (was Re: [PATCH] Configure: stdio char (un)signedness)
Message ID:
20060102153727.GA14247@mccoy.peters.homeunix.org
On Mon, Jan 02, 2006 at 07:53:53AM +0200, Jarkko Hietaniemi wrote:
> H.Merijn Brand wrote:
> > On Sat, 26 Nov 2005 11:25:18 +0200, Jarkko Hietaniemi <jhietaniemi@gmail.com>
> > wrote:
> > 
> >> Not that the detection of the stdio char signedness is all that
> >> important these days, but I grew bored by these warnings in Tru64:
> > 
> > Sorry for the delay. This sounds very reasonable, and I have applied this
> > in change #26557. Thanks.
> 
> If I may present a tiny wish for (5.9.3) Configure; since we seem to
> scan for the safe strl*() functions these days, how about also scanning
> for snprintf() and vsnprintf(), for the same reason, providing a safer
> API for  people doing XS work?  (One might of course use sv_*pvf*() for
> the same effect, but sometimes that is an overkill.)  (Use also
> Porting/checkcfgvar.pl, and tweak vms/*.)
> Thank you.

Adding support for snprintf() and vsnprintf() isn't too difficult to do if
you optimistically (or foolishly) assume these functions both return int's as
POSIX specifies.  As both functions are relatively new to most libc's, I'll 
assume the standards are being followed for now.

Bellow is the patch of what would be needed to make it work.
Of course, metaconfig should be used to make this happen, and I left off the
necessary changes to Porting/Glossary due to the large "DO NO EDIT THIS FILE" 
warning.

Enjoy,

Steve Peters
steve@fisharerojo.org

--- config_h.SH.old     2005-10-31 12:18:10.000000000 -0600
+++ config_h.SH 2006-01-02 09:09:51.000000000 -0600
@@ -2688,6 +2688,12 @@
 #$d_vprintf HAS_VPRINTF        /**/
 #$d_charvspr USE_CHAR_VSPRINTF         /**/

+/* HAS_VSNPRINTF:
+ *     This symbol, if defined, indicates that the vsnprintf routine is
+ *     available for use.
+ */
+#$d_vsnprintf HAS_VSNPRINTF    /**/
+
 /* HAS_WRITEV:
  *     This symbol, if defined, indicates that the writev routine is
  *     available to do scatter writes.
@@ -3960,6 +3966,12 @@
  */
 #$d_sigprocmask HAS_SIGPROCMASK                /**/

+/* HAS_SNPRINTF:
+ *     This symbol, if defined, indicates that the snprintf() library
+ *     function is available for use.
+ */
+#$d_snprintf HAS_SNPRINTF              /**/
+
 /* HAS_SOCKATMARK:
  *     This symbol, if defined, indicates that the sockatmark routine is
  *     available to test whether a socket is at the out-of-band mark.
--- Configure.old       2006-01-02 08:55:18.000000000 -0600
+++ Configure   2006-01-02 09:17:14.000000000 -0600
@@ -690,6 +690,7 @@
 d_msg_proxy=''
 d_oldsock=''
 d_scm_rights=''
+d_snprintf=''
 d_socket=''
 d_sockpair=''
 sockethdr=''
@@ -778,6 +779,7 @@
 d_volatile=''
 d_charvspr=''
 d_vprintf=''
+d_vsnprintf=''
 d_wait4=''
 d_waitpid=''
 d_wcstombs=''
@@ -16536,6 +16538,10 @@
 eval $setvar
 $rm -f try.c try

+: see if snprintf exists
+set snprintf d_snprintf
+eval $inlibc
+
 : see if sockatmark exists
 set sockatmark d_sockatmark
 eval $inlibc
@@ -17628,6 +17634,10 @@
 *) usevfork='false';;
 esac

+: see if vsnprintf exists
+set closedir d_vsnprintf
+eval $inlibc
+
 : see if closedir exists
 set closedir d_closedir
 eval $inlibc
@@ -21375,6 +21385,7 @@
 d_sigaction='$d_sigaction'
 d_sigprocmask='$d_sigprocmask'
 d_sigsetjmp='$d_sigsetjmp'
+d_snprintf='$d_snprintf'
 d_sockatmark='$d_sockatmark'
 d_sockatmarkproto='$d_sockatmarkproto'
 d_socket='$d_socket'
@@ -21456,6 +21467,7 @@
 d_voidtty='$d_voidtty'
 d_volatile='$d_volatile'
 d_vprintf='$d_vprintf'
+d_vsnprintf='$d_vsnprintf'
 d_wait4='$d_wait4'
 d_waitpid='$d_waitpid'
 d_wcstombs='$d_wcstombs'
--- handy.h.old 2006-01-02 08:53:36.000000000 -0600
+++ handy.h     2006-01-02 09:20:48.000000000 -0600
@@ -175,7 +175,7 @@
 #endif

 /* HMB H.Merijn Brand - a placeholder for preparing Configure patches */
-#if defined(HAS_MALLOC_SIZE) && defined(HAS_MALLOC_GOOD_SIZE) && defined(HAS_CLE
ARENV)
+#if defined(HAS_MALLOC_SIZE) && defined(HAS_MALLOC_GOOD_SIZE) && defined(HAS_CLE
ARENV) && defined(HAS_SNPRINTF) && defined(HAS_VSNPRINTF)
 /* Not (yet) used at top level, but mention them for metaconfig */
 #endif


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About