force binary mode for connections on win

stdin / stdout (for example) are created in text mode by default on
win. We need to flip them to binary mode for connection read and write.

See https://stackoverflow.com/questions/65014352/pipe-libvips-cli-output-to-stdout-in-windows
This commit is contained in:
John Cupitt 2020-11-26 10:15:48 +00:00
parent eddc99e6d8
commit acc579cc9d
3 changed files with 29 additions and 2 deletions

View File

@ -12,6 +12,7 @@
- block zero width or height images from imagemagick load [Koen1999] - block zero width or height images from imagemagick load [Koen1999]
- check for overflow in gifload height [lovell] - check for overflow in gifload height [lovell]
- fix msb_first default in ppm load and save [ewelot] - fix msb_first default in ppm load and save [ewelot]
- force binary mode on win for connection read / write [Alreiber]
6/9/20 started 8.10.2 6/9/20 started 8.10.2
- update magicksave/load profile handling [kelilevi] - update magicksave/load profile handling [kelilevi]

View File

@ -7,6 +7,9 @@
* - add vips_pipe_read_limit_set() * - add vips_pipe_read_limit_set()
* 3/10/20 * 3/10/20
* - improve behaviour with read and seek on pipes * - improve behaviour with read and seek on pipes
* 26/11/20
* - use _setmode() on win to force binary read for previously opened
* descriptors
*/ */
/* /*
@ -62,6 +65,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#ifdef OS_WIN32
#include <io.h>
#endif /*OS_WIN32*/
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/internal.h> #include <vips/internal.h>
@ -300,6 +306,13 @@ vips_source_build( VipsObject *object )
if( vips_object_argument_isset( object, "descriptor" ) ) { if( vips_object_argument_isset( object, "descriptor" ) ) {
connection->descriptor = dup( connection->descriptor ); connection->descriptor = dup( connection->descriptor );
connection->close_descriptor = connection->descriptor; connection->close_descriptor = connection->descriptor;
#ifdef OS_WIN32
/* Windows will create eg. stdin and stdout in text mode.
* We always read in binary mode.
*/
_setmode( connection->descriptor, _O_BINARY );
#endif /*OS_WIN32*/
} }
if( vips_object_argument_isset( object, "blob" ) ) { if( vips_object_argument_isset( object, "blob" ) ) {

View File

@ -2,6 +2,10 @@
* socket, node.js stream, etc. * socket, node.js stream, etc.
* *
* J.Cupitt, 19/6/14 * J.Cupitt, 19/6/14
*
* 26/11/20
* - use _setmode() on win to force binary write for previously opened
* descriptors
*/ */
/* /*
@ -51,6 +55,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#ifdef OS_WIN32
#include <io.h>
#endif /*OS_WIN32*/
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/internal.h> #include <vips/internal.h>
@ -135,10 +142,16 @@ vips_target_build( VipsObject *object )
else if( vips_object_argument_isset( object, "descriptor" ) ) { else if( vips_object_argument_isset( object, "descriptor" ) ) {
connection->descriptor = dup( connection->descriptor ); connection->descriptor = dup( connection->descriptor );
connection->close_descriptor = connection->descriptor; connection->close_descriptor = connection->descriptor;
#ifdef OS_WIN32
/* Windows will create eg. stdin and stdout in text mode.
* We always write in binary mode.
*/
_setmode( connection->descriptor, _O_BINARY );
#endif /*OS_WIN32*/
} }
else if( target->memory ) { else if( target->memory )
target->memory_buffer = g_byte_array_new(); target->memory_buffer = g_byte_array_new();
}
return( 0 ); return( 0 );
} }