summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2005-10-24 21:20:21 +0000
committerNicholas Clark <nick@ccl4.org>2005-10-24 21:20:21 +0000
commitce582ceece605be1a68752611f28e5b1a8e80455 (patch)
tree422b44c3eb2a02d29ccc40eed53e892cb22ddc2a /util.c
parent78821a22f30aaed98d9c6643adb5ed18f868dbe7 (diff)
downloadperl-ce582ceece605be1a68752611f28e5b1a8e80455.tar.gz
Add my_sprintf, which is usually just a macro for sprintf, for those
places where we want to use the return value of sprintf. This allows a wrapper to be used for platforms where the C library isn't ANSI- conformant. p4raw-id: //depot/perl@25832
Diffstat (limited to 'util.c')
-rw-r--r--util.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/util.c b/util.c
index c46a40ed04..6df7d8d29a 100644
--- a/util.c
+++ b/util.c
@@ -2707,9 +2707,9 @@ Perl_pidgone(pTHX_ Pid_t pid, int status)
{
register SV *sv;
char spid[TYPE_CHARS(IV)];
+ size_t len = my_sprintf(spid, "%"IVdf, (IV)pid);
- sprintf(spid, "%"IVdf, (IV)pid);
- sv = *hv_fetch(PL_pidstatus,spid,strlen(spid),TRUE);
+ sv = *hv_fetch(PL_pidstatus,spid,len,TRUE);
SvUPGRADE(sv,SVt_IV);
SvIV_set(sv, status);
return;
@@ -5081,6 +5081,27 @@ Perl_mem_log_free(Malloc_t oldalloc, const char *filename, const int linenumber,
#endif /* PERL_MEM_LOG */
/*
+=for apidoc my_sprintf
+
+The C library C<sprintf>, wrapped if necessary, to ensure that it will return
+the length of the string written to the buffer. Only rare pre-ANSI systems
+need the wrapper function - usually this is a direct call to C<sprintf>.
+
+=cut
+*/
+#ifndef SPRINTF_RETURNS_STRLEN
+int
+Perl_my_sprintf(char *buffer, const char* pat, ...)
+{
+ va_list args;
+ va_start(args, pat);
+ vsprintf(buffer, pat, args);
+ va_end(args);
+ return strlen(buffer);
+}
+#endif
+
+/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4