Fix issues with stdio needed for Lua

See #61
This commit is contained in:
Justine Tunney 2021-03-06 16:06:15 -08:00
parent c3ed8d6c7f
commit d769df3482
17 changed files with 102 additions and 155 deletions

View file

@ -25,20 +25,14 @@
* Writes data to stream.
*
* @param stride specifies the size of individual items
* @param count is the number of strides to fetch
* @param count is the number of strides to write
* @return count on success, [0,count) on EOF, 0 on error or count==0
*/
size_t fwrite(const void *data, size_t stride, size_t count, FILE *f) {
size_t i, n;
const unsigned char *p;
for (n = stride * count, p = data, i = 0; i < n; ++i) {
if (fputc(p[i], f) == -1) {
if (!(i % stride)) {
return i / stride;
} else {
return __fseterr(f, EOVERFLOW);
}
}
if (fputc(p[i], f) == -1) return -1;
}
return count;
}