]> sigrok.org Git - libserialport.git/blobdiff - serialport.c
windows: Use architecture-specific size limit for WriteFile calls.
[libserialport.git] / serialport.c
index d0618bb91df7f13b225085948122c7efed7a18f0..74d46eede7953d7ac0c761c18001cd0a3a102ffe 100644 (file)
@@ -793,6 +793,10 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
                        RETURN_FAIL("SetCommTimeouts() failed");
        }
 
+       /* Reduce count if it exceeds the WriteFile limit. */
+       if (count > WRITEFILE_MAX_SIZE)
+               count = WRITEFILE_MAX_SIZE;
+
        /* Start write. */
        if (WriteFile(port->hdl, buf, count, NULL, &port->write_ovl)) {
                DEBUG("Write completed immediately");
@@ -921,6 +925,10 @@ SP_API enum sp_return sp_nonblocking_write(struct sp_port *port,
                        RETURN_FAIL("SetCommTimeouts() failed");
        }
 
+       /* Reduce count if it exceeds the WriteFile limit. */
+       if (count > WRITEFILE_MAX_SIZE)
+               count = WRITEFILE_MAX_SIZE;
+
        /* Copy data to our write buffer. */
        buf_bytes = min(port->write_buf_size, count);
        memcpy(port->write_buf, buf, buf_bytes);