File tree 3 files changed +19
-8
lines changed
3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -628,15 +628,22 @@ vips_allocate_input_array(VipsImage *out, ...)
628
628
static int
629
629
write_vips (VipsRegion * region , VipsRect * area , void * a )
630
630
{
631
- size_t nwritten , count ;
631
+ size_t count ;
632
632
void * buf ;
633
633
634
634
count = (size_t ) region -> bpl * area -> height ;
635
635
buf = VIPS_REGION_ADDR (region , 0 , area -> top );
636
636
637
637
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 )
640
647
return errno ;
641
648
642
649
buf = (void * ) ((char * ) buf + nwritten );
Original file line number Diff line number Diff line change @@ -459,9 +459,10 @@ vips_target_write_unbuffered(VipsTarget *target,
459
459
return 0 ;
460
460
461
461
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 );
465
466
466
467
/* n == 0 isn't strictly an error, but we treat it as
467
468
* one to make sure we don't get stuck in this loop.
Original file line number Diff line number Diff line change @@ -538,12 +538,15 @@ int
538
538
vips__write (int fd , const void * buf , size_t count )
539
539
{
540
540
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
542
542
// ... max 1gb, why not
543
543
int chunk_size = VIPS_MIN (1024 * 1024 * 1024 , count );
544
544
ssize_t nwritten = write (fd , buf , chunk_size );
545
545
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 ) {
547
550
vips_error_system (errno , "vips__write" , "%s" , _ ("write failed" ));
548
551
return -1 ;
549
552
}
You can’t perform that action at this time.
0 commit comments