| 658 | */ |
| 659 | |
| 660 | int /* O - Character or -1 on end of file */ |
| 661 | cupsFileGetChar(cups_file_t *fp) /* I - CUPS file */ |
| 662 | { |
| 663 | /* |
| 664 | * Range check input... |
| 665 | */ |
| 666 | |
| 667 | DEBUG_printf(("4cupsFileGetChar(fp=%p)", (void *)fp)); |
| 668 | |
| 669 | if (!fp || (fp->mode != 'r' && fp->mode != 's')) |
| 670 | { |
| 671 | DEBUG_puts("5cupsFileGetChar: Bad arguments!"); |
| 672 | return (-1); |
| 673 | } |
| 674 | |
| 675 | if (fp->eof) |
| 676 | { |
| 677 | DEBUG_puts("5cupsFileGetChar: End-of-file!"); |
| 678 | return (-1); |
| 679 | } |
| 680 | |
| 681 | /* |
| 682 | * If the input buffer is empty, try to read more data... |
| 683 | */ |
| 684 | |
| 685 | DEBUG_printf(("5cupsFileGetChar: fp->eof=%d, fp->ptr=%p, fp->end=%p", fp->eof, (void *)fp->ptr, (void *)fp->end)); |
| 686 | |
| 687 | if (fp->ptr >= fp->end) |
| 688 | if (cups_fill(fp) <= 0) |
| 689 | { |
| 690 | DEBUG_puts("5cupsFileGetChar: Unable to fill buffer!"); |
| 691 | return (-1); |
| 692 | } |
| 693 | |
| 694 | /* |
| 695 | * Return the next character in the buffer... |
| 696 | */ |
| 697 | |
| 698 | DEBUG_printf(("5cupsFileGetChar: Returning %d...", *(fp->ptr) & 255)); |
| 699 | |
| 700 | fp->pos ++; |
| 701 | |
| 702 | DEBUG_printf(("6cupsFileGetChar: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); |
| 703 | |
| 704 | return (*(fp->ptr)++ & 255); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | /* |