memins(3pub)

memins3pub

Insert bytes at beginning of memory block

Usage

#include <publib.h>
void *memins(void *tgt, size_t tgtsize, const void *src, size_t srcsize);

Overview

memins inserts srcsize bytes from src at the beginning of tgt, but moves the first tgtsize out of the way. The source and target memory blocks must not overlap.

Return value

memins returns its first argument.

Examples

To insert a new element at the ith position of an array, one might do the following.

int new, array[10];
memins(array+i, (10-i-1)*sizeof(array[0]), &new, sizeof(new));

Please note that the above code carefully avoids the trap of moving the last element of the array past the end of the array.

Releases

16 releases since Debian 1.2 (Rex); the text changed 4 times.

  1. 1.2–1.3
  2. 2.0–2.2
  3. 3.0
  4. 3.1–6.0
  5. 7–13

Author

Lars Wirzenius ([email protected])

From publib-dev 0.40-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.