| 2758 | */ |
| 2759 | |
| 2760 | static ssize_t /* O - Number of bytes read or -1 */ |
| 2761 | cups_read(cups_file_t *fp, /* I - CUPS file */ |
| 2762 | char *buf, /* I - Buffer */ |
| 2763 | size_t bytes) /* I - Number bytes */ |
| 2764 | { |
| 2765 | ssize_t total; /* Total bytes read */ |
| 2766 | |
| 2767 | |
| 2768 | DEBUG_printf(("7cups_read(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLCAST bytes)); |
| 2769 | |
| 2770 | /* |
| 2771 | * Loop until we read at least 0 bytes... |
| 2772 | */ |
| 2773 | |
| 2774 | for (;;) |
| 2775 | { |
| 2776 | #ifdef _WIN32 |
| 2777 | if (fp->mode == 's') |
| 2778 | total = (ssize_t)recv(fp->fd, buf, (unsigned)bytes, 0); |
| 2779 | else |
| 2780 | total = (ssize_t)read(fp->fd, buf, (unsigned)bytes); |
| 2781 | #else |
| 2782 | if (fp->mode == 's') |
| 2783 | total = recv(fp->fd, buf, bytes, 0); |
| 2784 | else |
| 2785 | total = read(fp->fd, buf, bytes); |
| 2786 | #endif /* _WIN32 */ |
| 2787 | |
| 2788 | DEBUG_printf(("9cups_read: total=" CUPS_LLFMT, CUPS_LLCAST total)); |
| 2789 | |
| 2790 | if (total >= 0) |
| 2791 | break; |
| 2792 | |
| 2793 | /* |
| 2794 | * Reads can be interrupted by signals and unavailable resources... |
| 2795 | */ |
| 2796 | |
| 2797 | if (errno == EAGAIN || errno == EINTR) |
| 2798 | continue; |
| 2799 | else |
| 2800 | return (-1); |
| 2801 | } |
| 2802 | |
| 2803 | /* |
| 2804 | * Return the total number of bytes read... |
| 2805 | */ |
| 2806 | |
| 2807 | return (total); |
| 2808 | } |
| 2809 | |
| 2810 | |
| 2811 | /* |