p = strchr(name, '\0');
/* The next block assumes the buffer is at least 205 chars
long. At present, it's always at least 256 chars. */
- if (p-name > 200) {
- strcpy(name+200, "...");
- p = name+199;
+ if (p - name > 200) {
+#ifdef HAS_STRLCPY
+ strlcpy(name + 200, "...", 4);
+#else
+ strcpy(name + 200, "...");
+#endif
+ p = name + 199;
}
else {
p[1] = '\0';
*/
#ifdef SPRINTF_RETURNS_STRLEN
# define my_sprintf sprintf
+# ifdef HAS_SNPRINTF
+# define USE_SNPRINTF
+# endif
+# ifdef HAS_VSNPRINTF
+# define USE_VSNPRINTF
+# endif
#else
# define my_sprintf Perl_my_sprintf
#endif
/* Use fixed buffer as sv_catpvf etc. needs SVs */
char buffer[1024];
const STRLEN len = my_sprintf(buffer, "%.40s:%" IVdf " ", s ? s : "(none)", (IV) CopLINE(PL_curcop));
+# ifdef USE_VSNPRINTF
+ const STRLEN len2 = vnsprintf(buffer+len, sizeof(buffer) - len, fmt, ap);
+# else
const STRLEN len2 = vsprintf(buffer+len, fmt, ap);
+# endif /* USE_VSNPRINTF */
PerlLIO_write(PL_perlio_debug_fd, buffer, len + len2);
#else
const char *s = CopFILE(PL_curcop);
PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
{
dVAR;
+#ifdef USE_VSNPRINTF
+ const int val = vsnprintf(s, n, fmt, ap);
+#else
const int val = vsprintf(s, fmt, ap);
+#endif /* #ifdef USE_VSNPRINTF */
if (n >= 0) {
if (strlen(s) >= (STRLEN) n) {
dTHX;
/* Formats aren't yet marked for locales, so assume "yes". */
{
STORE_NUMERIC_STANDARD_SET_LOCAL();
+#ifdef USE_SNPRINTF
+ snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
+#else
sprintf(t, fmt, (int) fieldsize, (int) arg & 255, value);
+#endif /* ifdef USE_SNPRINTF */
RESTORE_NUMERIC_STANDARD();
}
t += fieldsize;
len = SvCUR(sv);
}
else
+#ifdef USE_SNPRINTF
+ len = snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
+ (unsigned long)++PL_evalseq);
+#else
len = my_sprintf(tmpbuf, "_<(%.10s_eval %lu)", code,
(unsigned long)++PL_evalseq);
+#endif /* ifdef USE_SNPRINTF */
SAVECOPFILE_FREE(&PL_compiling);
CopFILE_set(&PL_compiling, tmpbuf+2);
SAVECOPLINE(&PL_compiling);
CV* runcv;
U32 seq;
HV *saved_hh = NULL;
+ const char * const fakestr = "_<(eval )";
+#ifdef HAS_STRLCPY
+ const int fakelen = 9 + 1;
+#endif
if (PL_op->op_private & OPpEVAL_HAS_HH) {
saved_hh = (HV*) SvREFCNT_inc(POPs);
len = SvCUR(temp_sv);
}
else
+#ifdef USE_SNPRINTF
+ len = snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
+#else
len = my_sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
+#endif /* ifdef USE_SNPRINTF */
SAVECOPFILE_FREE(&PL_compiling);
CopFILE_set(&PL_compiling, tmpbuf+2);
SAVECOPLINE(&PL_compiling);
ret = doeval(gimme, NULL, runcv, seq);
if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
&& ret != PL_op->op_next) { /* Successive compilation. */
- strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
+ /* Copy in anything fake and short. */
+#ifdef HAS_STRLCPY
+ strlcpy(safestr, fakestr, fakelen);
+#else
+ strcpy(safestr, fakestr);
+#endif /* #ifdef HAS_STRLCPY */
}
return DOCATCH(ret);
}
U32 i;
for (i = 1; i <= rx->nparens; i++) {
char digits[TYPE_CHARS(long)];
+#ifdef USE_SNPRINTF
+ const STRLEN len = snprintf(digits, sizeof(digits), "%lu", (long)i);
+#else
const STRLEN len = my_sprintf(digits, "%lu", (long)i);
+#endif /* #ifdef USE_SNPRINTF */
GV *const *const gvp
= (GV**)hv_fetch(PL_defstash, digits, len, 0);
STRLEN len;
if (SvIOKp(sv)) {
- len = SvIsUV(sv) ? my_sprintf(tbuf,"%"UVuf, (UV)SvUVX(sv))
- : my_sprintf(tbuf,"%"IVdf, (IV)SvIVX(sv));
+ len = SvIsUV(sv)
+#ifdef USE_SNPRINTF
+ ? snprintf(tbuf, sizeof(tbuf), "%"UVuf, (UV)SvUVX(sv))
+ : snprintf(tbuf, sizeof(tbuf), "%"IVdf, (IV)SvIVX(sv));
+#else
+ ? my_sprintf(tbuf, "%"UVuf, (UV)SvUVX(sv))
+ : my_sprintf(tbuf, "%"IVdf, (IV)SvIVX(sv));
+#endif /* #ifdef USE_SNPRINTF */
} else {
Gconvert(SvNVX(sv), NV_DIG, 0, tbuf);
len = strlen(tbuf);
* --jhi */
#if defined(HAS_LONG_DOUBLE)
elen = ((intsize == 'q')
+# ifdef USE_SNPRINTF
+ ? snprintf(PL_efloatbuf, PL_efloatsize, ptr, nv)
+ : snprintf(PL_efloatbuf, PL_efloatsize, ptr, (double)nv));
+# else
? my_sprintf(PL_efloatbuf, ptr, nv)
: my_sprintf(PL_efloatbuf, ptr, (double)nv));
+# endif /* #ifdef USE_SNPRINTF */
#else
elen = my_sprintf(PL_efloatbuf, ptr, nv);
#endif
if (!PL_in_my_stash) {
char tmpbuf[1024];
PL_bufptr = s;
+#ifdef USE_SNPRINTF
+ snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
+#else
sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
+#endif /* #ifdef USE_SNPRINTF */
yyerror(tmpbuf);
}
#ifdef PERL_MAD
if ( SvNOK(ver) ) /* may get too much accuracy */
{
char tbuf[64];
- const STRLEN len = my_sprintf(tbuf,"%.9"NVgf, SvNVX(ver));
+#ifdef USE_SNPRINTF
+ const STRLEN len = snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
+#else
+ const STRLEN len = my_sprintf(tbuf, "%.9"NVgf, SvNVX(ver));
+#endif /* #ifdef USE_SNPRINTF */
version = savepvn(tbuf, len);
}
else
if (len == 2 && tmpbuf[0] == '.')
seen_dot = 1;
#endif
+#ifdef HAS_STRLCAT
+ (void)strlcpy(tmpbuf + len, scriptname, sizeof(tmpbuf) - len);
+#else
/* FIXME? Convert to memcpy by storing previous strlen(scriptname)
*/
(void)strcpy(tmpbuf + len, scriptname);
+#endif /* #ifdef HAS_STRLCAT */
#endif /* !VMS */
#ifdef SEARCH_EXTS
if ( SvNOK(ver) ) /* may get too much accuracy */
{
char tbuf[64];
- const STRLEN len = my_sprintf(tbuf,"%.9"NVgf, SvNVX(ver));
+#ifdef USE_SNPRINTF
+ const STRLEN len = snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
+#else
+ const STRLEN len = my_sprintf(tbuf, "%.9"NVgf, SvNVX(ver));
+#endif /* #ifdef USE_SNPRINTF */
version = savepvn(tbuf, len);
}
#ifdef SvVOK