fix stream for php <= 7.3
authorRemi Collet <remi@remirepo.net>
Thu, 24 Sep 2020 09:58:37 +0000 (11:58 +0200)
committerRemi Collet <remi@remirepo.net>
Thu, 24 Sep 2020 09:59:37 +0000 (11:59 +0200)
src/php_pqlob.c

index 0c1fc288242ffc88bec2f1d815e649b756bfb861..0cb44a896875669ca4b4f5e42359117252b9a7a8 100644 (file)
@@ -100,7 +100,11 @@ static void php_pqlob_object_read_stream(void *o, zval *return_value)
        RETVAL_ZVAL(&zstream, 1, 0);
 }
 
+#if PHP_VERSION_ID < 70400
+static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
+#else
 static ssize_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
+#endif
 {
        php_pqlob_object_t *obj = stream->abstract;
        ssize_t written = 0;
@@ -115,10 +119,18 @@ static ssize_t php_pqlob_stream_write(php_stream *stream, const char *buffer, si
                php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
+#if PHP_VERSION_ID < 70400
+       return (written < 0 ? 0 : written);
+#else
        return written;
+#endif
 }
 
+#if PHP_VERSION_ID < 70400
+static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
+#else
 static ssize_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
+#endif
 {
        php_pqlob_object_t *obj = stream->abstract;
        ssize_t read = 0;
@@ -140,7 +152,11 @@ static ssize_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t le
                php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
+#if PHP_VERSION_ID < 70400
+       return (read < 0 ? 0 : read);
+#else
        return read;
+#endif
 }
 
 static ZEND_RESULT_CODE php_pqlob_stream_close(php_stream *stream, int close_handle)