MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsFileGetLine

Function cupsFileGetLine

cups/file.c:865–930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

863 */
864
865size_t /* O - Number of bytes on line or 0 on end of file */
866cupsFileGetLine(cups_file_t *fp, /* I - File to read from */
867 char *buf, /* I - Buffer */
868 size_t buflen) /* I - Size of buffer */
869{
870 int ch; /* Character from file */
871 char *ptr, /* Current position in line buffer */
872 *end; /* End of line buffer */
873
874
875 /*
876 * Range check input...
877 */
878
879 DEBUG_printf(("2cupsFileGetLine(fp=%p, buf=%p, buflen=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLCAST buflen));
880
881 if (!fp || (fp->mode != 'r' && fp->mode != 's') || !buf || buflen < 3)
882 return (0);
883
884 /*
885 * Now loop until we have a valid line...
886 */
887
888 for (ptr = buf, end = buf + buflen - 2; ptr < end ;)
889 {
890 if (fp->ptr >= fp->end)
891 if (cups_fill(fp) <= 0)
892 break;
893
894 *ptr++ = ch = *(fp->ptr)++;
895 fp->pos ++;
896
897 if (ch == '\r')
898 {
899 /*
900 * Check for CR LF...
901 */
902
903 if (fp->ptr >= fp->end)
904 if (cups_fill(fp) <= 0)
905 break;
906
907 if (*(fp->ptr) == '\n')
908 {
909 *ptr++ = *(fp->ptr)++;
910 fp->pos ++;
911 }
912
913 break;
914 }
915 else if (ch == '\n')
916 {
917 /*
918 * Line feed ends a line...
919 */
920
921 break;
922 }

Callers 8

mainFunction · 0.85
copy_commentsFunction · 0.85
copy_dscFunction · 0.85
copy_pageFunction · 0.85
copy_prologFunction · 0.85
copy_setupFunction · 0.85
copy_trailerFunction · 0.85
skip_pageFunction · 0.85

Calls 1

cups_fillFunction · 0.85

Tested by

no test coverage detected