*
* Email: crh@ubiqx.mn.org
*
- * $Id: Gstr.c 2012-06-12 21:46:10 -0500 crh$
+ * $Id: Gstr.c 2012-06-20 11:45:36 -0500 crh$
*
* -------------------------------------------------------------------------- **
*
Gstr tmp[1];
va_list ap;
- /* Make sure we have a buffer in our Gstr.
+ /* Make sure we have buffers in our Gstrs.
*/
if( NULL == gs->bufr )
- initGstr( gs );
+ if( NULL == initGstr( gs ) )
+ return( -1 );
+ if( NULL == initGstr( tmp ) )
+ return( -1 );
/* It may take two tries to format the string.
* If the first try returns a length that is greater than our buffer size,
tmp->len = 1 + vsnprintf( tmp->bufr, tmp->bSize, fmt, ap );
va_end( ap );
+ /* If our buffer is too small... */
if( (tmp->len) > (tmp->bSize) )
{
if( growGstr( tmp, tmp->len ) < 0 )
*
* Output: True if the string is empty, else false.
*
+ * Notes: There are three factors to consider when determining whether
+ * the string is empty.
+ * + If the string doesn't exist (is NULL), then it's empty.
+ * + If the string exists, but the first byte is '\0', it's empty.
+ * + If the Gstr length is zero, the string is empty.
+ *
* ------------------------------------------------------------------------ **
*/
{
- if( (NULL != gs->bufr) && ( '\0' != *(gs->bufr) ) )
+ if( (NULL != gs->bufr) && ('\0' != *(gs->bufr)) && (gs->len) )
return( false );
return( true );
} /* isemptyGstr */
*
* Email: crh@ubiqx.mn.org
*
- * $Id: Gstr.h 2012-06-12 21:46:10 -0500 crh$
+ * $Id: Gstr.h 2012-06-20 11:45:36 -0500 crh$
*
* -------------------------------------------------------------------------- **
*
*
* Output: True if the string is empty, else false.
*
+ * Notes: There are three factors to consider when determining whether
+ * the string is empty.
+ * + If the string doesn't exist (is NULL), then it's empty.
+ * + If the string exists, but the first byte is '\0', it's empty.
+ * + If the Gstr length is zero, the string is empty.
+ *
* ------------------------------------------------------------------------ **
*/
-
int lenGstr( Gstr *gs );
/* ------------------------------------------------------------------------ **
* Return the length of the string currently stored in the Gstr.