third_party/inchi/INCHI_BASE/src/ichi_io.c
int inchi_strbuf_getline( INCHI_IOS_STRING *buf,
                          FILE *f,
                          int crlf2lf,
                          int preserve_lf )
{
    int c;
    inchi_strbuf_reset( buf );

    while (1)
    {
        c = fgetc( f );
        if (ferror( f ))
        {
            return -1;
        }
        if (c == EOF)
        {
            return -1;
        }
        inchi_strbuf_printf( buf, "%c", c );
        if (c == '\n')
        {
            break;
        }
    }

    if (crlf2lf)
    {
        if (buf->nUsedLength > 2)
        {
            if (buf->pStr[buf->nUsedLength - 2] == '\r')
            {
                buf->pStr[buf->nUsedLength - 2] = '\n';
                buf->pStr[--buf->nUsedLength] = '\0';
            }
        }
    }
    if (!preserve_lf)
    {
        buf->pStr[--buf->nUsedLength] = '\0';
    }

    return buf->nUsedLength;
}
/****************************************************************************
    Reads the next line to growing str buf.
    Returns n of read chars, -1 at end of file or at error.
*****************************************************************************/
Reads the next line to growing str buf.
Returns n of read chars, -1 at end of file or at error.
Reads the next line to growing str buf . Returns n of read chars - 1 at end of file or at error .
int inchi_strbuf_getline( INCHI_IOS_STRING *buf,
                          FILE *f,
                          int crlf2lf,
                          int preserve_lf )
{
    int c;
    inchi_strbuf_reset( buf );
    while (1)
    {
        c = fgetc( f );
        if (ferror( f ))
        {
            return -1;
        }
        if (c == EOF)
        {
            return -1;
        }
        inchi_strbuf_printf( buf, "%c", c );
        if (c == '\n')
        {
            break;
        }
    }
    if (crlf2lf)
    {
        if (buf->nUsedLength > 2)
        {
            if (buf->pStr[buf->nUsedLength - 2] == '\r')
            {
                buf->pStr[buf->nUsedLength - 2] = '\n';
                buf->pStr[--buf->nUsedLength] = '\0';
            }
        }
    }
    if (!preserve_lf)
    {
        buf->pStr[--buf->nUsedLength] = '\0';
    }
    return buf->nUsedLength;
}
int inchi_strbuf_getline ( INCHI_IOS_STRING * buf , FILE * f , int crlf2lf , int preserve_lf ) { int c ; inchi_strbuf_reset ( buf ) ; while ( 1 ) { c = fgetc ( f ) ; if ( ferror ( f ) ) { return -1 ; } if ( c == EOF ) { return -1 ; } inchi_strbuf_printf ( buf , " " , c ) ; if ( c == ' \n ' ) { break ; } } if ( crlf2lf ) { if ( buf -> nUsedLength > 2 ) { if ( buf -> pStr [ buf -> nUsedLength - 2 ] == ' \r ' ) { buf -> pStr [ buf -> nUsedLength - 2 ] = ' \n ' ; buf -> pStr [ -- buf -> nUsedLength ] = ' \0 ' ; } } } if ( ! preserve_lf ) { buf -> pStr [ -- buf -> nUsedLength ] = ' \0 ' ; } return buf -> nUsedLength ; }
Reads the next line to growing str buf.
Reads the next line to growing str buf .