@@ -103,13 +103,16 @@ static size_t zstd_check_compress_level(zend_long level)
103103}
104104
105105// Truncate string to given size
106- static zend_always_inline zend_string * zstd_string_output_truncate (zend_string * output , size_t real_length )
106+ static zend_always_inline zend_string *
107+ zstd_string_output_truncate (zend_string * output , size_t real_length )
107108{
108109 size_t capacity = ZSTR_LEN (output );
109110 size_t free_space = capacity - real_length ;
110111
111- // Reallocate just when capacity and real size differs a lot or the free space is bigger than 1 MB
112- if (UNEXPECTED (free_space > (capacity / 8 ) || free_space > (1024 * 1024 ))) {
112+ // Reallocate just when capacity and real size differs a lot
113+ // or the free space is bigger than 1 MB
114+ if (UNEXPECTED (free_space > (capacity / 8 )
115+ || free_space > (1024 * 1024 ))) {
113116 output = zend_string_truncate (output , real_length , 0 );
114117 }
115118 ZSTR_LEN (output ) = real_length ;
@@ -434,7 +437,8 @@ static int php_zstd_comp_flush_or_end(php_zstd_stream_data *self, int end)
434437 self -> output .pos = 0 ;
435438 res = ZSTD_compressStream (self -> cctx , & self -> output , & self -> input );
436439 if (ZSTD_IS_ERROR (res )) {
437- php_error_docref (NULL , E_WARNING , "libzstd error %s\n" , ZSTD_getErrorName (res ));
440+ php_error_docref (NULL , E_WARNING ,
441+ "libzstd error %s\n" , ZSTD_getErrorName (res ));
438442 ret = EOF ;
439443 }
440444 php_stream_write (self -> stream , self -> bufout , self -> output .pos );
@@ -452,7 +456,8 @@ static int php_zstd_comp_flush_or_end(php_zstd_stream_data *self, int end)
452456 res = ZSTD_flushStream (self -> cctx , & self -> output );
453457 }
454458 if (ZSTD_IS_ERROR (res )) {
455- php_error_docref (NULL , E_WARNING , "libzstd error %s\n" , ZSTD_getErrorName (res ));
459+ php_error_docref (NULL , E_WARNING ,
460+ "libzstd error %s\n" , ZSTD_getErrorName (res ));
456461 ret = EOF ;
457462 }
458463 php_stream_write (self -> stream , self -> bufout , self -> output .pos );
@@ -475,9 +480,11 @@ static int php_zstd_comp_flush_or_end(php_zstd_stream_data *self, int end)
475480 /* Flush / End */
476481 do {
477482 self -> output .pos = 0 ;
478- res = ZSTD_compressStream2 (self -> cctx , & self -> output , & in , end ? ZSTD_e_end : ZSTD_e_flush );
483+ res = ZSTD_compressStream2 (self -> cctx , & self -> output , & in ,
484+ end ? ZSTD_e_end : ZSTD_e_flush );
479485 if (ZSTD_isError (res )) {
480- php_error_docref (NULL , E_WARNING , "libzstd error %s\n" , ZSTD_getErrorName (res ));
486+ php_error_docref (NULL , E_WARNING ,
487+ "libzstd error %s\n" , ZSTD_getErrorName (res ));
481488 ret = EOF ;
482489 }
483490 php_stream_write (self -> stream , self -> output .dst , self -> output .pos );
@@ -561,9 +568,11 @@ static ssize_t php_zstd_decomp_read(php_stream *stream, char *buf, size_t count)
561568 /* for zstd */
562569 self -> output .pos = 0 ;
563570 self -> output .size = self -> sizeout ;
564- res = ZSTD_decompressStream (self -> dctx , & self -> output , & self -> input );
571+ res = ZSTD_decompressStream (self -> dctx ,
572+ & self -> output , & self -> input );
565573 if (ZSTD_IS_ERROR (res )) {
566- php_error_docref (NULL , E_WARNING , "libzstd error %s\n" , ZSTD_getErrorName (res ));
574+ php_error_docref (NULL , E_WARNING ,
575+ "libzstd error %s\n" , ZSTD_getErrorName (res ));
567576#if PHP_VERSION_ID >= 70400
568577 return -1 ;
569578#endif
@@ -574,7 +583,8 @@ static ssize_t php_zstd_decomp_read(php_stream *stream, char *buf, size_t count)
574583 } else {
575584 /* read */
576585 self -> input .pos = 0 ;
577- self -> input .size = php_stream_read (self -> stream , self -> bufin , self -> sizein );
586+ self -> input .size = php_stream_read (self -> stream ,
587+ self -> bufin , self -> sizein );
578588 if (!self -> input .size ) {
579589 /* EOF */
580590 count = 0 ;
@@ -586,13 +596,12 @@ static ssize_t php_zstd_decomp_read(php_stream *stream, char *buf, size_t count)
586596
587597
588598#if PHP_VERSION_ID < 70400
589- static size_t php_zstd_comp_write (php_stream * stream , const char * buf , size_t count )
590- {
599+ static size_t
591600#else
592- static ssize_t php_zstd_comp_write (php_stream * stream , const char * buf , size_t count )
593- {
601+ static ssize_t
594602#endif
595-
603+ php_zstd_comp_write (php_stream * stream , const char * buf , size_t count )
604+ {
596605 STREAM_DATA_FROM_STREAM ();
597606
598607#if ZSTD_VERSION_NUMBER >= 10400
@@ -601,9 +610,11 @@ static ssize_t php_zstd_comp_write(php_stream *stream, const char *buf, size_t c
601610
602611 do {
603612 self -> output .pos = 0 ;
604- res = ZSTD_compressStream2 (self -> cctx , & self -> output , & in , ZSTD_e_continue );
613+ res = ZSTD_compressStream2 (self -> cctx , & self -> output ,
614+ & in , ZSTD_e_continue );
605615 if (ZSTD_isError (res )) {
606- php_error_docref (NULL , E_WARNING , "libzstd error %s\n" , ZSTD_getErrorName (res ));
616+ php_error_docref (NULL , E_WARNING ,
617+ "libzstd error %s\n" , ZSTD_getErrorName (res ));
607618#if PHP_VERSION_ID >= 70400
608619 return -1 ;
609620#endif
@@ -643,7 +654,8 @@ static ssize_t php_zstd_comp_write(php_stream *stream, const char *buf, size_t c
643654 self -> output .pos = 0 ;
644655 res = ZSTD_compressStream (self -> cctx , & self -> output , & self -> input );
645656 if (ZSTD_IS_ERROR (res )) {
646- php_error_docref (NULL , E_WARNING , "libzstd error %s\n" , ZSTD_getErrorName (res ));
657+ php_error_docref (NULL , E_WARNING ,
658+ "libzstd error %s\n" , ZSTD_getErrorName (res ));
647659#if PHP_VERSION_ID >= 70400
648660 return -1 ;
649661#endif
@@ -714,7 +726,8 @@ php_stream_zstd_opener(
714726 return NULL ;
715727 }
716728
717- if (!strcmp (mode , "w" ) || !strcmp (mode , "wb" ) || !strcmp (mode , "a" ) || !strcmp (mode , "ab" )) {
729+ if (!strcmp (mode , "w" ) || !strcmp (mode , "wb" )
730+ || !strcmp (mode , "a" ) || !strcmp (mode , "ab" )) {
718731 compress = 1 ;
719732 } else if (!strcmp (mode , "r" ) || !strcmp (mode , "rb" )) {
720733 compress = 0 ;
@@ -727,11 +740,13 @@ php_stream_zstd_opener(
727740 zval * tmpzval ;
728741 zend_string * data ;
729742
730- if (NULL != (tmpzval = php_stream_context_get_option (context , "zstd" , "level" ))) {
743+ tmpzval = php_stream_context_get_option (context , "zstd" , "level" );
744+ if (NULL != tmpzval ) {
731745 level = zval_get_long (tmpzval );
732746 }
733747#if ZSTD_VERSION_NUMBER >= 10400
734- if (NULL != (tmpzval = php_stream_context_get_option (context , "zstd" , "dict" ))) {
748+ tmpzval = php_stream_context_get_option (context , "zstd" , "dict" );
749+ if (NULL != tmpzval ) {
735750 data = zval_get_string (tmpzval );
736751 if (compress ) {
737752 cdict = ZSTD_createCDict (ZSTR_VAL (data ), ZSTR_LEN (data ), level );
@@ -744,12 +759,15 @@ php_stream_zstd_opener(
744759 }
745760
746761 if (level > ZSTD_maxCLevel ()) {
747- php_error_docref (NULL , E_WARNING , "zstd: compression level (%d) must be less than %d" , level , ZSTD_maxCLevel ());
762+ php_error_docref (NULL , E_WARNING ,
763+ "zstd: compression level (%d) must be less than %d" ,
764+ level , ZSTD_maxCLevel ());
748765 level = ZSTD_maxCLevel ();
749766 }
750767
751768 self = ecalloc (sizeof (* self ), 1 );
752- self -> stream = php_stream_open_wrapper (path , mode , options | REPORT_ERRORS , NULL );
769+ self -> stream = php_stream_open_wrapper (path , mode ,
770+ options | REPORT_ERRORS , NULL );
753771 if (!self -> stream ) {
754772 efree (self );
755773 return NULL ;
@@ -760,7 +778,8 @@ php_stream_zstd_opener(
760778 self -> dctx = NULL ;
761779 self -> cctx = ZSTD_createCCtx ();
762780 if (!self -> cctx ) {
763- php_error_docref (NULL , E_WARNING , "zstd: compression context failed" );
781+ php_error_docref (NULL , E_WARNING ,
782+ "zstd: compression context failed" );
764783 php_stream_close (self -> stream );
765784 efree (self );
766785 return NULL ;
@@ -792,7 +811,8 @@ php_stream_zstd_opener(
792811 } else {
793812 self -> dctx = ZSTD_createDCtx ();
794813 if (!self -> dctx ) {
795- php_error_docref (NULL , E_WARNING , "zstd: compression context failed" );
814+ php_error_docref (NULL , E_WARNING ,
815+ "zstd: compression context failed" );
796816 php_stream_close (self -> stream );
797817 efree (self );
798818 return NULL ;
0 commit comments