---
name: "pattern"
section: "3"
platform: "linux"
package: "ltp-dev"
version: "20091231+dfsg-1"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/pattern/3"
---

# pattern(3)

Fill a buffer with copies of a pattern pattern\_check - Validate a buffer against copies of a pattern

## 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.**
