2021-03-02 18:58:11 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-03-02 19:57:57 +01:00
|
|
|
size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
|
2021-03-02 18:58:11 +01:00
|
|
|
unsigned bytes_written = 0;
|
|
|
|
unsigned bytes_count = size * nmemb;
|
2021-03-02 19:57:57 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < bytes_count; i++) {
|
|
|
|
char c = ptr[i];
|
|
|
|
|
|
|
|
if (fputc(c, stream) != c) {
|
|
|
|
break;
|
2021-03-02 18:58:11 +01:00
|
|
|
}
|
2021-03-02 19:57:57 +01:00
|
|
|
|
|
|
|
bytes_written++;
|
2021-03-02 18:58:11 +01:00
|
|
|
}
|
2021-03-02 19:57:57 +01:00
|
|
|
|
2021-03-02 18:58:11 +01:00
|
|
|
return bytes_written / size;
|
|
|
|
}
|