return ret;
}
+static int
+write_data (const void *buf, size_t size, size_t nmemb, FILE *stream)
+{
+ while (nmemb > 0) {
+ size_t w;
+
+ w = fwrite (buf, size, nmemb, stream);
+ if (!w && ferror (stream))
+ return 0;
+
+ nmemb -= w;
+ buf += size * w;
+ }
+
+ return 1;
+}
+
vcedit_error
vcedit_write (vcedit_state *state)
{
FILE *out;
char *buffer, tmpfile[PATH_MAX];
int s, result, bytes, needflush = 0, needout = 0;
- size_t tmp;
if (!state->opened)
return VCEDIT_ERR_INVAL;
ogg_stream_packetin (&streamout, &header_codebooks);
while ((result = ogg_stream_flush (&streamout, &ogout))) {
- tmp = fwrite (ogout.header, 1, ogout.header_len, out);
- if (tmp != (size_t) ogout.header_len)
+ if (!write_data (ogout.header, 1, ogout.header_len, out))
goto cleanup;
- tmp = fwrite (ogout.body, 1, ogout.body_len, out);
- if (tmp != (size_t) ogout.body_len)
+ if (!write_data (ogout.body, 1, ogout.body_len, out))
goto cleanup;
}
if (needflush) {
if (ogg_stream_flush (&streamout, &ogout)) {
- tmp = fwrite (ogout.header, 1, ogout.header_len, out);
- if (tmp != (size_t) ogout.header_len)
+ if (!write_data (ogout.header, 1, ogout.header_len, out))
goto cleanup;
- tmp = fwrite (ogout.body, 1, ogout.body_len, out);
- if (tmp != (size_t) ogout.body_len)
+ if (!write_data (ogout.body, 1, ogout.body_len, out))
goto cleanup;
}
} else if (needout) {
if (ogg_stream_pageout (&streamout, &ogout)) {
- tmp = fwrite (ogout.header, 1, ogout.header_len, out);
- if (tmp != (size_t) ogout.header_len)
+ if (!write_data (ogout.header, 1, ogout.header_len, out))
goto cleanup;
- tmp = fwrite (ogout.body, 1, ogout.body_len, out);
- if (tmp != (size_t) ogout.body_len)
+ if (!write_data (ogout.body, 1, ogout.body_len, out))
goto cleanup;
}
}
streamout.e_o_s = 1;
while (ogg_stream_flush (&streamout, &ogout)) {
- tmp = fwrite (ogout.header, 1, ogout.header_len, out);
- if (tmp != (size_t) ogout.header_len)
+ if (!write_data (ogout.header, 1, ogout.header_len, out))
goto cleanup;
- tmp = fwrite (ogout.body, 1, ogout.body_len, out);
- if (tmp != (size_t) ogout.body_len)
+ if (!write_data (ogout.body, 1, ogout.body_len, out))
goto cleanup;
}
if (state->extrapage) {
- tmp = fwrite (ogin.header, 1, ogin.header_len, out);
- if (tmp != (size_t) ogin.header_len)
+ if (!write_data (ogin.header, 1, ogin.header_len, out))
goto cleanup;
- tmp = fwrite (ogin.body, 1, ogin.body_len, out);
- if (tmp != (size_t) ogin.body_len)
+ if (!write_data (ogin.body, 1, ogin.body_len, out))
goto cleanup;
}
/* Don't bother going through the rest, we can just
* write the page out now
*/
- tmp = fwrite (ogout.header, 1, ogout.header_len, out);
- if (tmp != (size_t) ogout.header_len)
+ if (!write_data (ogout.header, 1, ogout.header_len, out))
goto cleanup;
- tmp = fwrite (ogout.body, 1, ogout.body_len, out);
- if (tmp != (size_t) ogout.body_len)
+ if (!write_data (ogout.body, 1, ogout.body_len, out))
goto cleanup;
}