1 ################################################################################
5 ## $Date: 2010/03/07 13:15:45 +0100 $
7 ################################################################################
9 ## Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz.
10 ## Version 2.x, Copyright (C) 2001, Paul Marquess.
11 ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
13 ## This program is free software; you can redistribute it and/or
14 ## modify it under the same terms as Perl itself.
16 ################################################################################
25 #if !defined(my_strlcat)
26 #if { NEED my_strlcat }
29 my_strlcat(char *dst, const char *src, Size_t size)
31 Size_t used, length, copy;
35 if (size > 0 && used < size - 1) {
36 copy = (length >= size - used) ? size - used - 1 : length;
37 memcpy(dst + used, src, copy);
38 dst[used + copy] = '\0';
45 #if !defined(my_strlcpy)
46 #if { NEED my_strlcpy }
49 my_strlcpy(char *dst, const char *src, Size_t size)
55 copy = (length >= size) ? size - 1 : length;
56 memcpy(dst, src, copy);
67 #define NEED_my_strlcat
68 #define NEED_my_strlcpy
78 len = my_strlcpy(buf, "foo", sizeof(buf));
80 mXPUSHs(newSVpv(buf, 0));
81 len = my_strlcat(buf, "bar", sizeof(buf));
83 mXPUSHs(newSVpv(buf, 0));
84 len = my_strlcat(buf, "baz", sizeof(buf));
86 mXPUSHs(newSVpv(buf, 0));
87 len = my_strlcpy(buf, "1234567890", sizeof(buf));
89 mXPUSHs(newSVpv(buf, 0));
90 len = my_strlcpy(buf, "1234", sizeof(buf));
92 mXPUSHs(newSVpv(buf, 0));
93 len = my_strlcat(buf, "567890123456", sizeof(buf));
95 mXPUSHs(newSVpv(buf, 0));
107 my @r = Devel::PPPort::my_strlfunc();