lib/: spdx license conversion
[xfstests-dev.git] / include / pattern.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef _PATTERN_H_
7 #define _PATTERN_H_
8
9 /*
10  * pattern_check(buf, buflen, pat, patlen, patshift)
11  *
12  * Check a buffer of length buflen against repeated occurrances of
13  * a pattern whose length is patlen.  Patshift can be used to rotate
14  * the pattern by patshift bytes to the left.
15  *
16  * Patshift may be greater than patlen, the pattern will be rotated by
17  * (patshift % patshift) bytes.
18  *
19  * pattern_check returns -1 if the buffer does not contain repeated
20  * occurrances of the indicated pattern (shifted by patshift).
21  *
22  * The algorithm used to check the buffer relies on the fact that buf is 
23  * supposed to be repeated copies of pattern.  The basic algorithm is
24  * to validate the first patlen bytes of buf against the pat argument
25  * passed in - then validate the next patlen bytes against the 1st patlen
26  * bytes - the next (2*patlen) bytes against the 1st (2*pathen) bytes, and
27  * so on.  This algorithm only works when the assumption of a buffer full
28  * of repeated copies of a pattern holds, and gives MUCH better results
29  * then walking the buffer byte by byte.
30  *
31  * Performance wise, It appears to be about 5% slower than doing a straight
32  * memcmp of 2 buffers, but the big win is that it does not require a
33  * 2nd comparison buffer, only the pattern.
34  */
35 int pattern_check( char * , int , char * , int , int );
36
37 /*
38  * pattern_fill(buf, buflen, pat, patlen, patshift)
39  *
40  * Fill a buffer of length buflen with repeated occurrances of
41  * a pattern whose length is patlen.  Patshift can be used to rotate
42  * the pattern by patshift bytes to the left.
43  *
44  * Patshift may be greater than patlen, the pattern will be rotated by
45  * (patshift % patlen) bytes.
46  *
47  * If buflen is not a multiple of patlen, a partial pattern will be written
48  * in the last part of the buffer.  This implies that a buffer which is
49  * shorter than the pattern length will receive only a partial pattern ...
50  *
51  * pattern_fill always returns 0 - no validation of arguments is done.
52  *
53  * The algorithm used to fill the buffer relies on the fact that buf is 
54  * supposed to be repeated copies of pattern.  The basic algorithm is
55  * to fill the first patlen bytes of buf with the pat argument
56  * passed in - then copy the next patlen bytes with the 1st patlen
57  * bytes - the next (2*patlen) bytes with the 1st (2*pathen) bytes, and
58  * so on.  This algorithm only works when the assumption of a buffer full
59  * of repeated copies of a pattern holds, and gives MUCH better results
60  * then filling the buffer 1 byte at a time.
61  */
62 int pattern_fill( char * , int , char * , int , int );
63
64 #endif