projects
/
ruby-vorbistagger.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
f20bab8
)
Handle short writes gracefully.
author
Tilman Sauerbeck
<tilman@code-monkey.de>
Fri, 18 Aug 2006 13:29:37 +0000
(15:29 +0200)
committer
Tilman Sauerbeck
<tilman@code-monkey.de>
Wed, 23 Aug 2006 17:39:15 +0000
(19:39 +0200)
ext/vcedit.c
patch
|
blob
|
history
diff --git
a/ext/vcedit.c
b/ext/vcedit.c
index 75bf80db99aac4b3205172cb5c14b520b4d9193a..b9650f8a157ed395281fece20874a1c24165b9df 100644
(file)
--- a/
ext/vcedit.c
+++ b/
ext/vcedit.c
@@
-377,6
+377,23
@@
err:
return ret;
}
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)
{
vcedit_error
vcedit_write (vcedit_state *state)
{
@@
-387,7
+404,6
@@
vcedit_write (vcedit_state *state)
FILE *out;
char *buffer, tmpfile[PATH_MAX];
int s, result, bytes, needflush = 0, needout = 0;
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;
if (!state->opened)
return VCEDIT_ERR_INVAL;
@@
-430,12
+446,10
@@
vcedit_write (vcedit_state *state)
ogg_stream_packetin (&streamout, &header_codebooks);
while ((result = ogg_stream_flush (&streamout, &ogout))) {
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;
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;
}
goto cleanup;
}
@@
-447,22
+461,18
@@
vcedit_write (vcedit_state *state)
if (needflush) {
if (ogg_stream_flush (&streamout, &ogout)) {
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;
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)) {
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;
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;
}
}
goto cleanup;
}
}
@@
-490,22
+500,18
@@
vcedit_write (vcedit_state *state)
streamout.e_o_s = 1;
while (ogg_stream_flush (&streamout, &ogout)) {
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;
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) {
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;
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;
}
goto cleanup;
}
@@
-523,12
+529,10
@@
vcedit_write (vcedit_state *state)
/* Don't bother going through the rest, we can just
* write the page out now
*/
/* 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;
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;
}
goto cleanup;
}