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