Commit | Line | Data |
c01be2ce |
1 | ################################################################################ |
2 | ## |
bfc37ff7 |
3 | ## $Revision: 3 $ |
c01be2ce |
4 | ## $Author: mhx $ |
bfc37ff7 |
5 | ## $Date: 2010/03/07 13:15:44 +0100 $ |
c01be2ce |
6 | ## |
7 | ################################################################################ |
8 | ## |
bfc37ff7 |
9 | ## Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz. |
c01be2ce |
10 | ## Version 2.x, Copyright (C) 2001, Paul Marquess. |
11 | ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski. |
12 | ## |
13 | ## This program is free software; you can redistribute it and/or |
14 | ## modify it under the same terms as Perl itself. |
15 | ## |
16 | ################################################################################ |
17 | |
18 | =provides |
19 | |
20 | my_sprintf |
21 | |
22 | =implementation |
23 | |
24 | #if !defined(my_sprintf) |
25 | #if { NEED my_sprintf } |
26 | |
27 | int |
28 | my_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 | |
46 | void |
47 | my_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 | |
59 | my($l, $s) = Devel::PPPort::my_sprintf(); |
60 | ok($l, 8); |
61 | ok($s, "foobar42"); |
62 | |