Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

cpybuf

Copy one buffer area to another regardless of any null characters.

Short Name

cpybuf()

Type

Utility function

Declaration

void cpybuf(pTEXT destination, pTEXT source, UINT length)

Description

cpybuf() copies length bytes from source to destination.

It does not stop when it sees a null character. You can copy strings or structures with this.

We strongly suggest using cpybuf() instead of strcpy(), for the following reasons:

  • strcpy() copies until it reaches a null character, terminating the source string. If a string is larger than the destination buffer, an overwrite of adjacent data or code occurs. This can be an extremely difficult bug to find. Using a length as the size of the destination buffer as the limit to cpybuf() avoids this problem.
  • Many constructs used in FairCom DB are not null-terminated strings. Keys and data records can both have null characters embedded in the middle. strcpy() will not copy the entire data item in this case.

Example

FILNO keyno;

TEXT target[24],idxval[23];

LONG recbyt;


scanf("%23s",target);

recbyt = GetGTEKey(keyno,target,idxval);

while (recbyt) {

printf("\nIndex entry = %23s ", idxval);

printf("\nRecord # = %ld, recbyt);

cpybuf(target,idxval,23);

recbyt = GetGTKey(keyno,target,idxval);

}

Limitations

cpybuf() does not check to see if the buffer at destination is large enough to hold the data being moved.

See also

FairCom DB also includes cpybig(), which provides the same functionality as cpybuf(), and works for very large buffers, even on machines with segmented memory models. The length parameter is declared as VRLEN instead of UINT, which provides for larger buffers. Also see strcpy().

TOCIndex