mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 14:54:49 -04:00
make it so that evbuffer_add_file where we read the complete contents of the file can fail without side effects
svn:r1069
This commit is contained in:
parent
66b2a7ffb7
commit
a0cae310d0
18
buffer.c
18
buffer.c
@ -1496,21 +1496,33 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* the default implementation */
|
/* the default implementation */
|
||||||
|
struct evbuffer *tmp = evbuffer_new();
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
|
|
||||||
if (lseek(fd, offset, SEEK_SET) == -1)
|
if (tmp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
|
if (lseek(fd, offset, SEEK_SET) == -1) {
|
||||||
|
evbuffer_free(tmp);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we add everything to a temporary buffer, so that we
|
||||||
|
* can abort without side effects if the read fails.
|
||||||
|
*/
|
||||||
while (length) {
|
while (length) {
|
||||||
read = evbuffer_read(outbuf, fd, length);
|
read = evbuffer_read(tmp, fd, length);
|
||||||
if (read == -1) {
|
if (read == -1) {
|
||||||
/* TODO(niels): deal with rewinding */
|
evbuffer_free(tmp);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
length -= read;
|
length -= read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evbuffer_add_buffer(outbuf, tmp);
|
||||||
|
evbuffer_free(tmp);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user