# New Ticket Created by Leopold Toetsch
# Please include the string: [perl #17876]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=17876 >
I didn't look, if this is really intended, but I wouldn't like to behave
Parrot_snprintf different then snprintf(3).
It would also be nice, if we could have a return value, consistent with
glibc 2.1.
leo
-- attachment 1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/39675/32138/4b302e/snprintf.patch
--- parrot/misc.c Fri Oct 11 10:00:38 2002
+++ parrot-leo/misc.c Sat Oct 12 13:11:01 2002
@@ -65,15 +65,22 @@
Parrot_vsnprintf(struct Parrot_Interp *interpreter, char *targ,
size_t len, const char *pat, va_list args)
{
- STRING *ret = Parrot_vsprintf_c(interpreter, pat, args);
+ STRING *ret;
+ if (len == 0)
+ return;
+ len--;
+ if (len) {
+ ret = Parrot_vsprintf_c(interpreter, pat, args);
string_transcode(interpreter, ret, NULL, NULL, &ret);
if (len > ret->bufused) {
len = ret->bufused;
}
+ if (len)
memcpy(targ, ret->strstart, len);
- targ[len + 1] = 0;
+ }
+ targ[len] = 0;
}
STRING *
--- parrot/t/src/sprintf.t Fri Oct 11 10:00:43 2002
+++ parrot-leo/t/src/sprintf.t Sat Oct 12 13:14:00 2002
@@ -21,11 +21,15 @@
double dval;
FLOATVAL fltval;
char *fmt;
+ char dest[20];
struct Parrot_Interp * interpreter;
interpreter = Parrot_new();
Parrot_init(interpreter, (void*) &dummy_var);
+ Parrot_snprintf(interpreter, dest, 2, "%s", "CERT");
+ printf("%s\n",dest);
+
S = Parrot_sprintf_c(interpreter, "Hello, %s\n", "Parrot!");
printf(string_to_cstring(interpreter, S));
@@ -81,6 +85,7 @@
return 0;
}
CODE
+C
Hello, Parrot!
PerlHash[0x100]
PerlHash[0x100]