| 3701 | } |
| 3702 | |
| 3703 | static size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, |
| 3704 | FILE *stream) |
| 3705 | { |
| 3706 | if (stdio_stream_read_init(stream) < 0) |
| 3707 | return 0; |
| 3708 | size_t total = size * nmemb; |
| 3709 | if (total == 0) |
| 3710 | return 0; |
| 3711 | char *ptr8 = (char *)ptr; |
| 3712 | bool unget = (stream->unget != EOF); |
| 3713 | if (unget) |
| 3714 | { |
| 3715 | ptr8[0] = (char)stream->unget; |
| 3716 | stream->unget = EOF; |
| 3717 | } |
| 3718 | if (stream->read_ptr == NULL) |
| 3719 | { |
| 3720 | ssize_t result = stdio_stream_read_buf(stream, ptr8 + unget, |
| 3721 | ptr8 + total - unget); |
| 3722 | result = (result < 0? (ssize_t)unget: result); |
| 3723 | return ((size_t)result == total? nmemb: (size_t)result / size); |
| 3724 | } |
| 3725 | size_t i; |
| 3726 | for (i = unget; i < total; i++) |
| 3727 | { |
| 3728 | int c; |
| 3729 | if (stream->read_ptr < stream->read_end) |
| 3730 | c = (int)*stream->read_ptr++; |
| 3731 | else |
| 3732 | { |
| 3733 | c = fgetc_unlocked(stream); |
| 3734 | if (feof_unlocked(stream) || ferror_unlocked(stream)) |
| 3735 | break; |
| 3736 | } |
| 3737 | ptr8[i] = (char)c; |
| 3738 | } |
| 3739 | return (i == total? nmemb: i / size); |
| 3740 | } |
| 3741 | |
| 3742 | static size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) |
| 3743 | { |
no test coverage detected