/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Further, this software is distributed without any warranty that it is * free of the rightful claim of any third person regarding infringement * or the like. Any license provided herein, whether implied or * otherwise, applies only to this software file. Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, * Mountain View, CA 94043, or: * * http://www.sgi.com * * For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ */ #include #include #include /* memset */ #include /* rand */ #include "databin.h" #if UNIT_TEST #include #endif static char Errmsg[80]; void databingen (mode, buffer, bsize, offset) int mode; /* either a, c, r, o, z or C */ char *buffer; /* buffer pointer */ int bsize; /* size of buffer */ int offset; /* offset into the file where buffer starts */ { int ind; switch (mode) { default: case 'a': /* alternating bit pattern */ memset(buffer,0x55,bsize); break; case 'c': /* checkerboard pattern */ memset(buffer,0xf0,bsize); break; case 'C': /* */ for (ind=0;ind< bsize;ind++) { buffer[ind] = ((offset+ind)%8 & 0177); } break; case 'o': memset(buffer,0xff,bsize); break; case 'z': memset(buffer,0x0,bsize); break; case 'r': /* random */ for (ind=0;ind< bsize;ind++) { buffer[ind] = (rand () & 0177) | 0100; } } } /*********************************************************************** * * return values: * >= 0 : error at byte offset into the file, offset+buffer[0-(bsize-1)] * < 0 : no error ***********************************************************************/ int databinchk(mode, buffer, bsize, offset, errmsg) int mode; /* either a, c, r, z, o, or C */ char *buffer; /* buffer pointer */ int bsize; /* size of buffer */ int offset; /* offset into the file where buffer starts */ char **errmsg; { int cnt; unsigned char *chr; int total; long expbits; long actbits; chr = (unsigned char *) buffer; total=bsize; if (errmsg != NULL) { *errmsg = Errmsg; } switch (mode) { default: case 'a': /* alternating bit pattern */ expbits=0x55; break; case 'c': /* checkerboard pattern */ expbits=0xf0; break; case 'C': /* counting pattern */ for (cnt=0;cnt< bsize;cnt++) { expbits = ((offset+cnt)%8 & 0177); if (buffer[cnt] != expbits) { sprintf(Errmsg, "data mismatch at offset %d, exp:%#lo, act:%#o", offset+cnt, expbits, buffer[cnt]); return offset+cnt; } } sprintf(Errmsg, "all %d bytes match desired pattern", bsize); return -1; case 'o': expbits=0xff; break; case 'z': expbits=0; break; case 'r': return -1; /* no check can be done for random */ } for (cnt=0; cnt