MCPcopy Create free account
hub / github.com/GJDuck/e9patch / fread_unlocked

Function fread_unlocked

examples/stdlib.c:3703–3740  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3701}
3702
3703static 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
3742static size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
3743{

Callers 1

freadFunction · 0.85

Calls 5

stdio_stream_read_initFunction · 0.85
stdio_stream_read_bufFunction · 0.85
fgetc_unlockedFunction · 0.85
feof_unlockedFunction · 0.85
ferror_unlockedFunction · 0.85

Tested by

no test coverage detected