1################################################################################ 2## 3## Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz. 4## Version 2.x, Copyright (C) 2001, Paul Marquess. 5## Version 1.x, Copyright (C) 1999, Kenneth Albanowski. 6## 7## This program is free software; you can redistribute it and/or 8## modify it under the same terms as Perl itself. 9## 10################################################################################ 11 12=provides 13 14my_sprintf 15 16=implementation 17 18#if !defined(my_sprintf) 19#if { NEED my_sprintf } 20 21/* Warning: my_sprintf 22 It's safer to use my_snprintf instead 23*/ 24 25/* Replace my_sprintf with my_snprintf */ 26 27int 28my_sprintf(char *buffer, const char* pat, ...) 29{ 30 va_list args; 31 va_start(args, pat); 32 vsprintf(buffer, pat, args); 33 va_end(args); 34 return strlen(buffer); 35} 36 37#endif 38#endif 39 40=xsinit 41 42#define NEED_my_sprintf 43 44=xsubs 45 46void 47my_sprintf() 48 PREINIT: 49 char buf[128]; 50 int len; 51 PPCODE: 52 len = my_sprintf(buf, "foo%s%d", "bar", 42); 53 mXPUSHi(len); 54 mXPUSHs(newSVpv(buf, 0)); 55 XSRETURN(2); 56 57=tests plan => 2 58 59my($l, $s) = Devel::PPPort::my_sprintf(); 60is($l, 8); 61is($s, "foobar42"); 62