PATTERN(3)

NAME
pattern_fill - Fill a buffer with copies of a pattern
pattern_check - Validate a buffer against copies of a pattern

SYNOPSIS
pattern_fill(char *buf, int buflen, char *pat, int patlen, int patshift)
pattern_check(char *buf, int buflen, char *pat, int patlen, int patshift)

DESCRIPTION
pattern_fill() fills a buffer of length buflen with repeated occurrences of a pattern whose length is patlen. If buflen is not a multiple of patlen, a partial pattern will be written in the last part of the buffer. This implies that a buffer which is shorter than the pattern length will receive only a partial pattern. pattern_check() verifies that buf contains repeated occurrences of the indicated pattern. The patshift argument to pattern_fill() and pattern_shift() specify that pat should be rotated (patshift % patlen) bytes to the left before filling or comparing the buffer. Since the pattern is rotated by (patshift % patlen), patshift may be greater than pathlen.

EXAMPLES
pattern_fill(buf, sizeof(buf), "abcde", 5, 0)
    fill buf with repeated occurrences of "abcde"
pattern_check(buf, sizeof(buf), "abcde", 5, 0)
    verify that buf consists of repeated occurrences of "abcde"
pattern_fill(buf, sizeof(buf), "abcde", 5, 3)
    fill buf with repeated occurrences of "deabc"

DIAGNOSTICS
pattern_fill() always returns 0 - no validation of arguments is done.
pattern_check() returns -1 if the buffer does not contain repeated occurrences of the indicated pattern (rotated patshift bytes) or 0 otherwise.

BUGS
None known.