Function _conResizeC() Foundation

Change the length of a character string container.

Syntax
XPPAPIRET _conResizeC(ContainerHandle chs, ULONG ulNewSize);
Parameters
ContainerHandle chs
Handle of a container of character string type.
ULONG ulNewSize
New length of the character string.
Return

The function returns an error code (XPP_ERR_...) when the container is not of character type, if not enough memory is availiable or the container was locked before. On success, the returned value is NULL and the length of the string is changed.

Description

This function can together with _conWLockC() be used to manipulate character strings directly. First you can use _conResizeC() to define the length of a string container. Then you can lock the string with _conWLockC() and write its content. If the string length is increased with _conResizeC() the old content will be preserved and addtional bytes will be of undefined content. If the new length is shorter the string is truncated at the end.

Note that a call with a locked container will be rejected because the location in memory may change and thus the previous returned pointer would be invalid.

Examples
Return all environment entries as string or array
#define INCL_DOSPROCESS         /* for PTIB, PPIB */ 
#include <os2.h>                /* DosGetInfoBlocks() */ 
#include <string.h>             /* strlen(), strcat() */ 
#include "xpppar.h" 
#include "xppcon.h" 

#define CRLF       "\x0D\x0A" 
/* 
 FT_GETE( [ @<xResultVar> ] ) -> nEntries 

 The environment entries will be returned in the reference 
 parameter one whose type defines the return type. 
 The returned value is the number of environments entries. 
*/ 
XPPRET XPPENTRY FT_GETE( XppParamList paramList ) 
{ 
PTIB            ptib; 
PPIB            ppib; 
CHAR           *pEnviron; 
CHAR           *pc; 
ContainerHandle chParam; 
BOOL            isRef; 
ULONG           returnType = XPP_UNDEF; 
ULONG           numEntries = 0; 
ULONG           totalSize = 0; 
ULONG           i; 

/* 
   Get the environment pointer of the current process. 
   The format of the environment string is: 
   <name>'='<value>'\0' ... <name>'='<value>'\0''\0' 
*/ 
DosGetInfoBlocks(&ptib, &ppib); 
pEnviron = ppib->pib_pchenv; 

/* 
   get reference parameter and check which kind of return is desired. 
*/ 
chParam = _conParam( paramList, 1, &isRef ); 
if ( chParam != NULLCONTAINER ) 
{ 
   if (isRef) 
      _conType( chParam, &returnType ); 
   else 
      _conRelease( chParam ); 
} 
/* 
   count number of environment entries and 
   total length of all environment strings 
*/ 
pc = pEnviron; 
while (*pc != '\0') 
{ 
   i = strlen(pc); 
   totalSize += i; 
   pc += i+1; 
   numEntries++; 
} 

if ( XPP_IS_CHAR(returnType) ) 
{ 
   /* 
      copy the entries into the string and separate them with CR/LF 
   */ 
   totalSize += 2*numEntries + 1; 
   if (! _conResizeC( chParam, totalSize ) 
       && ! _conWLockC( chParam, &pc, &totalSize )) 
   { 
      *pc = '\0'; 
      while (*pEnviron != '\0') 
      { 
         strcat(pc, pEnviron); 
         strcat(pc, CRLF); 
         pEnviron += strlen(pEnviron)+1; 
      } 
      _conUnlockC( chParam ); 
   } 
} 
else if ( XPP_IS_ARRAY( returnType ) ) 
{ 
   /* 
      copy the entries into the array 
      (If the array has not enough elements the 
      errors are just ignored) 
   */ 
   i = 1; 
   while (*pEnviron != '\0') 
   { 
      _storc( pEnviron, paramList, 1, i, 0 ); 
      pEnviron += strlen(pEnviron)+1; 
      i++; 
   } 
} 
/* 
   return value is always the total number of entries 
*/ 
_retnl( paramList, numEntries ); 
} 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.