| 2813 | */ |
| 2814 | |
| 2815 | static ssize_t /* O - Number of bytes written or -1 */ |
| 2816 | cups_write(cups_file_t *fp, /* I - CUPS file */ |
| 2817 | const char *buf, /* I - Buffer */ |
| 2818 | size_t bytes) /* I - Number bytes */ |
| 2819 | { |
| 2820 | size_t total; /* Total bytes written */ |
| 2821 | ssize_t count; /* Count this time */ |
| 2822 | |
| 2823 | |
| 2824 | DEBUG_printf(("7cups_write(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLCAST bytes)); |
| 2825 | |
| 2826 | /* |
| 2827 | * Loop until all bytes are written... |
| 2828 | */ |
| 2829 | |
| 2830 | total = 0; |
| 2831 | while (bytes > 0) |
| 2832 | { |
| 2833 | #ifdef _WIN32 |
| 2834 | if (fp->mode == 's') |
| 2835 | count = (ssize_t)send(fp->fd, buf, (unsigned)bytes, 0); |
| 2836 | else |
| 2837 | count = (ssize_t)write(fp->fd, buf, (unsigned)bytes); |
| 2838 | #else |
| 2839 | if (fp->mode == 's') |
| 2840 | count = send(fp->fd, buf, bytes, 0); |
| 2841 | else |
| 2842 | count = write(fp->fd, buf, bytes); |
| 2843 | #endif /* _WIN32 */ |
| 2844 | |
| 2845 | DEBUG_printf(("9cups_write: count=" CUPS_LLFMT, CUPS_LLCAST count)); |
| 2846 | |
| 2847 | if (count < 0) |
| 2848 | { |
| 2849 | /* |
| 2850 | * Writes can be interrupted by signals and unavailable resources... |
| 2851 | */ |
| 2852 | |
| 2853 | if (errno == EAGAIN || errno == EINTR) |
| 2854 | continue; |
| 2855 | else |
| 2856 | return (-1); |
| 2857 | } |
| 2858 | |
| 2859 | /* |
| 2860 | * Update the counts for the last write call... |
| 2861 | */ |
| 2862 | |
| 2863 | bytes -= (size_t)count; |
| 2864 | total += (size_t)count; |
| 2865 | buf += count; |
| 2866 | } |
| 2867 | |
| 2868 | /* |
| 2869 | * Return the total number of bytes written... |
| 2870 | */ |
| 2871 | |
| 2872 | return ((ssize_t)total); |
no outgoing calls
no test coverage detected