MCPcopy Create free account
hub / github.com/OSGeo/gdal / CPLReadLine

Function CPLReadLine

port/cpl_conv.cpp:596–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594 */
595
596const char *CPLReadLine(FILE *fp)
597
598{
599 /* -------------------------------------------------------------------- */
600 /* Cleanup case. */
601 /* -------------------------------------------------------------------- */
602 if (fp == nullptr)
603 {
604 CPLReadLineBuffer(-1);
605 return nullptr;
606 }
607
608 /* -------------------------------------------------------------------- */
609 /* Loop reading chunks of the line till we get to the end of */
610 /* the line. */
611 /* -------------------------------------------------------------------- */
612 size_t nBytesReadThisTime = 0;
613 char *pszRLBuffer = nullptr;
614 size_t nReadSoFar = 0;
615
616 do
617 {
618 /* --------------------------------------------------------------------
619 */
620 /* Grow the working buffer if we have it nearly full. Fail out */
621 /* of read line if we can't reallocate it big enough (for */
622 /* instance for a _very large_ file with no newlines). */
623 /* --------------------------------------------------------------------
624 */
625 if (nReadSoFar > 100 * 1024 * 1024)
626 // It is dubious that we need to read a line longer than 100 MB.
627 return nullptr;
628 pszRLBuffer = CPLReadLineBuffer(static_cast<int>(nReadSoFar) + 129);
629 if (pszRLBuffer == nullptr)
630 return nullptr;
631
632 /* --------------------------------------------------------------------
633 */
634 /* Do the actual read. */
635 /* --------------------------------------------------------------------
636 */
637 if (CPLFGets(pszRLBuffer + nReadSoFar, 128, fp) == nullptr &&
638 nReadSoFar == 0)
639 return nullptr;
640
641 nBytesReadThisTime = strlen(pszRLBuffer + nReadSoFar);
642 nReadSoFar += nBytesReadThisTime;
643 } while (nBytesReadThisTime >= 127 && pszRLBuffer[nReadSoFar - 1] != knCR &&
644 pszRLBuffer[nReadSoFar - 1] != knLF);
645
646 return pszRLBuffer;
647}
648
649/************************************************************************/
650/* CPLReadLineL() */

Callers 2

CSVDeaccessInternalFunction · 0.85
ReadLineClassicalFileFunction · 0.85

Calls 2

CPLReadLineBufferFunction · 0.85
CPLFGetsFunction · 0.85

Tested by

no test coverage detected