my_strlcat my_strlcpy
#if !defined(my_strlcat) #if { NEED my_strlcat }
Size_t my_strlcat(char *dst, const char *src, Size_t size) { Size_t used, length, copy;
used = strlen(dst); length = strlen(src); if (size > 0 && used < size - 1) { copy = (length >= size - used) ? size - used - 1 : length; memcpy(dst + used, src, copy); dst[used + copy] = '\0'; } return used + length; } #endif #endif
#if !defined(my_strlcpy) #if { NEED my_strlcpy }
Size_t my_strlcpy(char *dst, const char *src, Size_t size) { Size_t length, copy;
length = strlen(src); if (size > 0) { copy = (length >= size) ? size - 1 : length; memcpy(dst, src, copy); dst[copy] = '\0'; } return length; }
#endif #endif
#define NEED_my_strlcat #define NEED_my_strlcpy
void my_strlfunc() PREINIT: char buf[8]; int len; PPCODE: len = my_strlcpy(buf, "foo", sizeof(buf)); mXPUSHi(len); mXPUSHs(newSVpv(buf, 0)); len = my_strlcat(buf, "bar", sizeof(buf)); mXPUSHi(len); mXPUSHs(newSVpv(buf, 0)); len = my_strlcat(buf, "baz", sizeof(buf)); mXPUSHi(len); mXPUSHs(newSVpv(buf, 0)); len = my_strlcpy(buf, "1234567890", sizeof(buf)); mXPUSHi(len); mXPUSHs(newSVpv(buf, 0)); len = my_strlcpy(buf, "1234", sizeof(buf)); mXPUSHi(len); mXPUSHs(newSVpv(buf, 0)); len = my_strlcat(buf, "567890123456", sizeof(buf)); mXPUSHi(len); mXPUSHs(newSVpv(buf, 0)); XSRETURN(12);
my @e = (3, 'foo', 6, 'foobar', 9, 'foobarb', 10, '1234567', 4, '1234', 16, '1234567', ); my @r = Devel::PPPort::my_strlfunc();
ok(@e == @r);
for (0 .. $#e) { ok($r[$_], $e[$_]); }
5 POD Errors
The following errors were encountered while parsing the POD:
Unknown directive: =provides
Unknown directive: =implementation
Unknown directive: =xsinit
Unknown directive: =xsubs
Unknown directive: =tests
To install , copy and paste the appropriate command in to your terminal.
cpanm
cpanm ATOOMIC/Devel-PPPort-3.46.tar.gz
CPAN shell
perl -MCPAN -e shell install ATOOMIC/Devel-PPPort-3.46.tar.gz
For more information on module installation, please visit the detailed CPAN module installation guide.