summaryrefslogtreecommitdiff
path: root/Configure
diff options
context:
space:
mode:
authorAaron Crane <arc@cpan.org>2017-11-18 18:07:23 +0000
committerAaron Crane <arc@cpan.org>2017-11-18 18:29:51 +0000
commit4059ba8734da3986285ad50019afbd56b586ad25 (patch)
tree72f2d7f4f78af14973ad71527d7d1aef141f00ff /Configure
parentbd1f84ac544f5604940057502e2035f39c92bd4e (diff)
downloadperl-4059ba8734da3986285ad50019afbd56b586ad25.tar.gz
Restore ability to build on platforms without snprintf()
C89 does not in fact define snprintf() or vsnprintf(), and we must therefore probe for the existence of those functions before trying to use them. khw++ for pointing out my earlier error. This reverts part or all of each of the following commits: 13d66b05c6163c3514774d3d11da5f3950e97e98 Rely on C89 vsnprintf() e791399041815a1a45cea3c7f277c7045b96e51b Rely on C89 snprintf() adf7d503e55721c500f0bf66560b8f5df7966fe7 pod/perlhacktips.pod: remove some outdated portability notes
Diffstat (limited to 'Configure')
-rwxr-xr-xConfigure69
1 files changed, 69 insertions, 0 deletions
diff --git a/Configure b/Configure
index 05cf80973e..b48aaff46a 100755
--- a/Configure
+++ b/Configure
@@ -807,6 +807,8 @@ d_signbit=''
d_sigprocmask=''
d_sigsetjmp=''
usesitecustomize=''
+d_snprintf=''
+d_vsnprintf=''
d_sockatmark=''
d_sockatmarkproto=''
d_ip_mreq=''
@@ -18330,6 +18332,71 @@ set d_sigsetjmp
eval $setvar
$rm_try
+: see if snprintf exists
+set snprintf d_snprintf
+eval $inlibc
+
+: see if vsnprintf exists
+set vsnprintf d_vsnprintf
+eval $inlibc
+
+case "$d_snprintf-$d_vsnprintf" in
+"$define-$define")
+ $cat <<EOM
+Checking whether your snprintf() and vsnprintf() work okay...
+EOM
+ $cat >try.c <<'EOCP'
+/* v?snprintf testing logic courtesy of Russ Allbery.
+ * According to C99:
+ * - if the buffer is too short it still must be \0-terminated
+ * - if the buffer is too short the potentially required length
+ * must be returned and not -1
+ * - if the buffer is NULL the potentially required length
+ * must be returned and not -1 or core dump
+ */
+#include <stdio.h>
+#include <stdarg.h>
+
+char buf[2];
+
+int test (char *format, ...)
+{
+ va_list args;
+ int count;
+
+ va_start (args, format);
+ count = vsnprintf (buf, sizeof buf, format, args);
+ va_end (args);
+ return count;
+}
+
+int main ()
+{
+ return ((test ("%s", "abcd") == 4 && buf[0] == 'a' && buf[1] == '\0'
+ && snprintf (NULL, 0, "%s", "abcd") == 4) ? 0 : 1);
+}
+EOCP
+ set try
+ if eval $compile; then
+ `$run ./try`
+ case "$?" in
+ 0) echo "Your snprintf() and vsnprintf() seem to be working okay." ;;
+ *) cat <<EOM >&4
+Your snprintf() and snprintf() don't seem to be working okay.
+EOM
+ d_snprintf="$undef"
+ d_vsnprintf="$undef"
+ ;;
+ esac
+ else
+ echo "(I can't seem to compile the test program--assuming they don't)"
+ d_snprintf="$undef"
+ d_vsnprintf="$undef"
+ fi
+ $rm_try
+ ;;
+esac
+
: see if sockatmark exists
set sockatmark d_sockatmark
eval $inlibc
@@ -24128,6 +24195,7 @@ d_sigprocmask='$d_sigprocmask'
d_sigsetjmp='$d_sigsetjmp'
d_sin6_scope_id='$d_sin6_scope_id'
d_sitearch='$d_sitearch'
+d_snprintf='$d_snprintf'
d_sockaddr_in6='$d_sockaddr_in6'
d_sockaddr_sa_len='$d_sockaddr_sa_len'
d_sockatmark='$d_sockatmark'
@@ -24216,6 +24284,7 @@ d_vfork='$d_vfork'
d_void_closedir='$d_void_closedir'
d_voidsig='$d_voidsig'
d_voidtty='$d_voidtty'
+d_vsnprintf='$d_vsnprintf'
d_wait4='$d_wait4'
d_waitpid='$d_waitpid'
d_wcscmp='$d_wcscmp'