Next: , Previous: bpipe_data_copy, Up: Utility Functions   [Contents]


A.4.3 bpipe_data_dup

allocate memory for and duplicate a contiguous list of objects

Synopsis

#include <bpipe/bpipe.h>

void *bpipe_data_dup(
  void *data,
  size_t n,
  size_t size,
  int create_empty
);

Parameters

void *data

the buffer containing the data

size_t n

the number of elements of data

size_t size

the size of an element

int create_empty

if true, allocate and clear memory if the parameter data is NULL

Description

bpipe_data_dup allocates a block of memory and copies a sequential list of objects to that memory. If the pointer to the original data is NULL, and the create_empty flag is non zero, a block of memory large enough to contain the specified data is created and cleared. If the flag is zero, NULL is returned.

Returns

It returns a pointer to a block of memory duplicating the original data. Upon error bpipe_errno is set and NULL is returned.

Errors

Upon error bpipe_errno is set to one of the following errors:

BPENOMEM

a memory allocation failed