OpenTP1 Version 7 Programming Reference C Language

[Contents][Index][Back][Next]

tprealloc - Change the size of a typed buffer

Format

ANSI C, C++

#include <xatmi.h>
char *tprealloc (char *ptr, long size)

K&R C

#include <xatmi.h>
char *tprealloc (ptr, size)
char      *ptr;
long      size;

Description

The function tprealloc() changes the size of the buffer pointed to by ptr to size bytes and returns a pointer to the new (possibly moved) buffer. As with tpalloc(), the size of the buffer is at least as large as size. A buffer's type remains the same after it is reallocated. After this function returns successfully, the returned pointer should be used to reference the buffer; ptr should no longer be used. The buffer's contents do not change up to the lesser of the new and old sizes.

Some buffer types require initialization before they can be used. tprealloc() reinitializes a buffer (in a communication-resource-manager-specific manner) after it is reallocated and before it is returned. Thus, the buffer returned to the caller is ready for use.

<<Arguments>>

<<ptr

Specify the pointer to the buffer.>>

<<size

Specify the size which will be in effect after the buffer is reallocated.>>

Return value

Upon successful completion, tprealloc() returns a pointer to a buffer of the appropriate type aligned on a long word. Otherwise it returns NULL and sets tperrno to indicate the error condition.

Errors

Under the following conditions, tprealloc() fails and sets tperrno to one of the following values:

Return value Return value (numeric) Explanation
TPEINVAL 4 Invalid arguments were given (for example, ptr is not a point to a buffer allocated for tpalloc()).
TPEPROTO 9 tprealloc() was called in an improper context.
TPESYSTEM 12 A communication resource manager system error has occurred. The exact nature of the error is determined in a product-specific manner.
TPEOS 7 An operating system error has occurred. The exact nature of the error is determined in a product-specific manner.

Application usage

If buffer reinitialization fails, tprealloc() fails returning NULL and the contents of the buffer pointed to by ptr may not be valid.

This function should not be used in concert with malloc(), realloc() or free() in the C library (for example, a buffer allocated with tprealloc() should not be freed with free()).

See also

tpalloc(), tpfree(), tptypes().

<<Notes on use with OpenTP1>>

  1. <<Under the OpenTP1, the buffer returned by the function tprealloc() is reinitialized to 0.>>
  2. <<The behavior caused by XATMI errors encountered during OSI TP communication may be different from the behavior caused by errors encountered conventional TCP/IP communication.>>