Skip to content

Commit 85f9d97

Browse files
committed
Fix some other occurrences
1 parent 5a3f29b commit 85f9d97

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

libvips/iofuncs/generate.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -628,15 +628,22 @@ vips_allocate_input_array(VipsImage *out, ...)
628628
static int
629629
write_vips(VipsRegion *region, VipsRect *area, void *a)
630630
{
631-
size_t nwritten, count;
631+
size_t count;
632632
void *buf;
633633

634634
count = (size_t) region->bpl * area->height;
635635
buf = VIPS_REGION_ADDR(region, 0, area->top);
636636

637637
do {
638-
nwritten = write(region->im->fd, buf, count);
639-
if (nwritten == (size_t) -1)
638+
// write() uses int not size_t on windows, so we need to chunk
639+
// ... max 1gb, why not
640+
int chunk_size = VIPS_MIN(1024 * 1024 * 1024, count);
641+
ssize_t nwritten = write(region->im->fd, buf, chunk_size);
642+
643+
/* n == 0 isn't strictly an error, but we treat it as
644+
* one to make sure we don't get stuck in this loop.
645+
*/
646+
if (nwritten <= 0)
640647
return errno;
641648

642649
buf = (void *) ((char *) buf + nwritten);

libvips/iofuncs/target.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,10 @@ vips_target_write_unbuffered(VipsTarget *target,
459459
return 0;
460460

461461
while (length > 0) {
462-
gint64 bytes_written;
463-
464-
bytes_written = class->write(target, data, length);
462+
// write() uses int not size_t on windows, so we need to chunk
463+
// ... max 1gb, why not
464+
int chunk_size = VIPS_MIN(1024 * 1024 * 1024, length);
465+
gint64 bytes_written = class->write(target, data, chunk_size);
465466

466467
/* n == 0 isn't strictly an error, but we treat it as
467468
* one to make sure we don't get stuck in this loop.

libvips/iofuncs/util.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,15 @@ int
538538
vips__write(int fd, const void *buf, size_t count)
539539
{
540540
do {
541-
// write() uses int not ssize_t on windows, so we need to chunk
541+
// write() uses int not size_t on windows, so we need to chunk
542542
// ... max 1gb, why not
543543
int chunk_size = VIPS_MIN(1024 * 1024 * 1024, count);
544544
ssize_t nwritten = write(fd, buf, chunk_size);
545545

546-
if (nwritten == (ssize_t) -1) {
546+
/* n == 0 isn't strictly an error, but we treat it as
547+
* one to make sure we don't get stuck in this loop.
548+
*/
549+
if (nwritten <= 0) {
547550
vips_error_system(errno, "vips__write", "%s", _("write failed"));
548551
return -1;
549552
}

0 commit comments

Comments
 (0)