6.2.2 Example: Testing for Change in Size of Reply Buffer

The following listing provides a generic example of how an application test for a change in buffer size after a call to tpcall(). In this example, the input and output buffers must remain equal in size.

Listing Testing for Change in Size of the Reply Buffer

char *svc, *idata, *odata;
long ilen, olen, bef_len, aft_len;
. . .
if (idata = tpalloc("STRING", NULL, 0) == NULL)
    error
if (odata = tpalloc("STRING", NULL, 0) == NULL)
    error

place string value into idata buffer

ilen = olen = strlen(idata)+1;
. . .
bef_len = olen;
if (tpcall(svc, idata, ilen, &odata, &olen, flags) == -1)
   error

aft_len = olen;

if (aft_len > bef_len){ /* message buffer has grown */

    if (idata = tprealloc(idata, olen) == NULL)
       error

}