third_party/inchi/INCHI_BASE/src/ichi_io.c
int inchi_strbuf_update( INCHI_IOS_STRING *buf, int new_addition_size )
{
    int requsted_len;

    if (!buf)
    {
        return -1;
    }

    if (new_addition_size <= 0)
    {
        return buf->nAllocatedLength;
    }

    requsted_len = buf->nUsedLength + new_addition_size;

    if (requsted_len >= buf->nAllocatedLength)
    {
        /* Expand */
        int  nAddLength = inchi_max( buf->nPtr, new_addition_size );
                                    /* buf->nPtr stores size increment for this buffer */
        char *new_str =
            (char *) inchi_calloc( buf->nAllocatedLength + nAddLength,
                                   sizeof( new_str[0] ) );
        if (!new_str)
        {
            return -1; /* failed */
        }
        if (buf->pStr)
        {
            if (buf->nUsedLength > 0)
            {
                memcpy( new_str, buf->pStr, sizeof( new_str[0] )* buf->nUsedLength );
            }
            inchi_free( buf->pStr );
        }
        buf->pStr = new_str;
        buf->nAllocatedLength += nAddLength;
    }

    return buf->nAllocatedLength;
}
/****************************************************************************
 Check size and if necessary expand string buffer in INCHI_IOS_STRING
****************************************************************************/
Check size and if necessary expand string buffer in INCHI_IOS_STRING
Check size and if necessary expand string buffer in INCHI_IOS_STRING
int inchi_strbuf_update( INCHI_IOS_STRING *buf, int new_addition_size )
{
    int requsted_len;
    if (!buf)
    {
        return -1;
    }
    if (new_addition_size <= 0)
    {
        return buf->nAllocatedLength;
    }
    requsted_len = buf->nUsedLength + new_addition_size;
    if (requsted_len >= buf->nAllocatedLength)
    {
        int  nAddLength = inchi_max( buf->nPtr, new_addition_size );
        char *new_str =
            (char *) inchi_calloc( buf->nAllocatedLength + nAddLength,
                                   sizeof( new_str[0] ) );
        if (!new_str)
        {
            return -1; 
        }
        if (buf->pStr)
        {
            if (buf->nUsedLength > 0)
            {
                memcpy( new_str, buf->pStr, sizeof( new_str[0] )* buf->nUsedLength );
            }
            inchi_free( buf->pStr );
        }
        buf->pStr = new_str;
        buf->nAllocatedLength += nAddLength;
    }
    return buf->nAllocatedLength;
}
int inchi_strbuf_update ( INCHI_IOS_STRING * buf , int new_addition_size ) { int requsted_len ; if ( ! buf ) { return -1 ; } if ( new_addition_size <= 0 ) { return buf -> nAllocatedLength ; } requsted_len = buf -> nUsedLength + new_addition_size ; if ( requsted_len >= buf -> nAllocatedLength ) { int nAddLength = inchi_max ( buf -> nPtr , new_addition_size ) ; char * new_str = ( char * ) inchi_calloc ( buf -> nAllocatedLength + nAddLength , sizeof ( new_str [ 0 ] ) ) ; if ( ! new_str ) { return -1 ; } if ( buf -> pStr ) { if ( buf -> nUsedLength > 0 ) { memcpy ( new_str , buf -> pStr , sizeof ( new_str [ 0 ] ) * buf -> nUsedLength ) ; } inchi_free ( buf -> pStr ) ; } buf -> pStr = new_str ; buf -> nAllocatedLength += nAddLength ; } return buf -> nAllocatedLength ; }
Check size and if necessary expand string buffer in INCHI_IOS_STRING
Check size and if necessary expand string buffer in INCHI_IOS_STRING
/* Expand */ /* buf->nPtr stores size increment for this buffer */ /* failed */