2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * pattern_check(buf, buflen, pat, patlen, patshift)
24 * Check a buffer of length buflen against repeated occurrances of
25 * a pattern whose length is patlen. Patshift can be used to rotate
26 * the pattern by patshift bytes to the left.
28 * Patshift may be greater than patlen, the pattern will be rotated by
29 * (patshift % patshift) bytes.
31 * pattern_check returns -1 if the buffer does not contain repeated
32 * occurrances of the indicated pattern (shifted by patshift).
34 * The algorithm used to check the buffer relies on the fact that buf is
35 * supposed to be repeated copies of pattern. The basic algorithm is
36 * to validate the first patlen bytes of buf against the pat argument
37 * passed in - then validate the next patlen bytes against the 1st patlen
38 * bytes - the next (2*patlen) bytes against the 1st (2*pathen) bytes, and
39 * so on. This algorithm only works when the assumption of a buffer full
40 * of repeated copies of a pattern holds, and gives MUCH better results
41 * then walking the buffer byte by byte.
43 * Performance wise, It appears to be about 5% slower than doing a straight
44 * memcmp of 2 buffers, but the big win is that it does not require a
45 * 2nd comparison buffer, only the pattern.
47 int pattern_check( char * , int , char * , int , int );
50 * pattern_fill(buf, buflen, pat, patlen, patshift)
52 * Fill a buffer of length buflen with repeated occurrances of
53 * a pattern whose length is patlen. Patshift can be used to rotate
54 * the pattern by patshift bytes to the left.
56 * Patshift may be greater than patlen, the pattern will be rotated by
57 * (patshift % patlen) bytes.
59 * If buflen is not a multiple of patlen, a partial pattern will be written
60 * in the last part of the buffer. This implies that a buffer which is
61 * shorter than the pattern length will receive only a partial pattern ...
63 * pattern_fill always returns 0 - no validation of arguments is done.
65 * The algorithm used to fill the buffer relies on the fact that buf is
66 * supposed to be repeated copies of pattern. The basic algorithm is
67 * to fill the first patlen bytes of buf with the pat argument
68 * passed in - then copy the next patlen bytes with the 1st patlen
69 * bytes - the next (2*patlen) bytes with the 1st (2*pathen) bytes, and
70 * so on. This algorithm only works when the assumption of a buffer full
71 * of repeated copies of a pattern holds, and gives MUCH better results
72 * then filling the buffer 1 byte at a time.
74 int pattern_fill( char * , int , char * , int , int );