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 14__UNDEFINED__ 15 16=implementation 17 18#ifdef HAS_MEMCMP 19__UNDEFINED__ memNE(s1,s2,l) (memcmp(s1,s2,l)) 20__UNDEFINED__ memEQ(s1,s2,l) (!memcmp(s1,s2,l)) 21#else 22__UNDEFINED__ memNE(s1,s2,l) (bcmp(s1,s2,l)) 23__UNDEFINED__ memEQ(s1,s2,l) (!bcmp(s1,s2,l)) 24#endif 25 26__UNDEFINED__ memEQs(s1, l, s2) \ 27 (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1))) 28__UNDEFINED__ memNEs(s1, l, s2) !memEQs(s1, l, s2) 29 30__UNDEFINED__ memCHRs(s, c) ((const char *) memchr("" s "" , c, sizeof(s)-1)) 31 32__UNDEFINED__ MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t)) 33__UNDEFINED__ CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) 34#ifdef HAS_MEMSET 35__UNDEFINED__ ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t)) 36#else 37__UNDEFINED__ ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d) 38#endif 39 40__UNDEFINED__ PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)) 41__UNDEFINED__ PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) 42__UNDEFINED__ PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) 43__UNDEFINED__ Poison(d,n,t) PoisonFree(d,n,t) 44 45__UNDEFINED__ Newx(v,n,t) New(0,v,n,t) 46__UNDEFINED__ Newxc(v,n,t,c) Newc(0,v,n,t,c) 47__UNDEFINED__ Newxz(v,n,t) Newz(0,v,n,t) 48 49=xsubs 50 51int 52checkmem() 53 PREINIT: 54 char *p; 55 56 CODE: 57 RETVAL = 0; 58 Newx(p, 6, char); 59 CopyD("Hello", p, 6, char); 60 if (memEQ(p, "Hello", 6)) 61 RETVAL++; 62 ZeroD(p, 6, char); 63 if (memEQ(p, "\0\0\0\0\0\0", 6)) 64 RETVAL++; 65 if (memEQs(p, 6, "\0\0\0\0\0\0")) 66 RETVAL++; 67 Poison(p, 6, char); 68 if (memNE(p, "\0\0\0\0\0\0", 6)) 69 RETVAL++; 70 if (memNEs(p, 6, "\0\0\0\0\0\0")) 71 RETVAL++; 72 Safefree(p); 73 74 Newxz(p, 6, char); 75 if (memEQ(p, "\0\0\0\0\0\0", 6)) 76 RETVAL++; 77 Safefree(p); 78 79 Newxc(p, 3, short, char); 80 Safefree(p); 81 82 OUTPUT: 83 RETVAL 84 85=tests plan => 1 86 87is(Devel::PPPort::checkmem(), 6); 88