From e5888a1ffdae813d7575f5fb02275c6bb07e5199 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Wed, 30 Mar 2011 15:46:40 +0300 Subject: Import sources from 2011-03-30 iso image --- sys/src/libventi/zero.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 sys/src/libventi/zero.c (limited to 'sys/src/libventi/zero.c') diff --git a/sys/src/libventi/zero.c b/sys/src/libventi/zero.c new file mode 100755 index 000000000..c40aea969 --- /dev/null +++ b/sys/src/libventi/zero.c @@ -0,0 +1,55 @@ +#include +#include +#include + +void +vtzeroextend(int type, uchar *buf, uint n, uint nn) +{ + uchar *p, *ep; + + switch(type&7) { + case 0: + memset(buf+n, 0, nn-n); + break; + default: + p = buf + (n/VtScoreSize)*VtScoreSize; + ep = buf + (nn/VtScoreSize)*VtScoreSize; + while(p < ep) { + memmove(p, vtzeroscore, VtScoreSize); + p += VtScoreSize; + } + memset(p, 0, buf+nn-p); + break; + } +} + +uint +vtzerotruncate(int type, uchar *buf, uint n) +{ + uchar *p; + + if(type == VtRootType){ + if(n < VtRootSize) + return n; + return VtRootSize; + } + + switch(type&7){ + case 0: + for(p = buf + n; p > buf; p--) { + if(p[-1] != 0) + break; + } + return p - buf; + default: + /* ignore slop at end of block */ + p = buf + (n/VtScoreSize)*VtScoreSize; + + while(p > buf) { + if(memcmp(p - VtScoreSize, vtzeroscore, VtScoreSize) != 0) + break; + p -= VtScoreSize; + } + return p - buf; + } +} -- cgit v1.2.3