[libcamera-devel,RFC,v2,04/14] test: yaml-parser: Use write() instead of fwrite()
diff mbox series

Message ID 20220604185939.29163-5-laurent.pinchart@ideasonboard.com
State RFC
Headers show
Series
  • Replace boost JSON parser with libyaml in Raspberry Pi IPA
Related show

Commit Message

Laurent Pinchart June 4, 2022, 6:59 p.m. UTC
There's no point in wrapping a fd into a FILE to then only call fwrite()
and fclose(). Use write() and close() directly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 test/yaml-parser.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Nicolas Dufresne via libcamera-devel June 13, 2022, 4:12 a.m. UTC | #1
Hi Laurent,

On Sat, Jun 04, 2022 at 09:59:29PM +0300, Laurent Pinchart via libcamera-devel wrote:
> There's no point in wrapping a fd into a FILE to then only call fwrite()
> and fclose(). Use write() and close() directly.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  test/yaml-parser.cpp | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp
> index e75f8fe8f642..5ff4c3236dbf 100644
> --- a/test/yaml-parser.cpp
> +++ b/test/yaml-parser.cpp
> @@ -49,10 +49,11 @@ protected:
>  		if (fd == -1)
>  			return false;
>  
> -		FILE *fh = fdopen(fd, "w");
> -		fputs(content.c_str(), fh);
> +		int ret = write(fd, content.c_str(), content.size());
> +		close(fd);
>  
> -		fclose(fh);
> +		if (ret != static_cast<int>(content.size()))
> +			return false;
>  
>  		return true;
>  	}
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp
index e75f8fe8f642..5ff4c3236dbf 100644
--- a/test/yaml-parser.cpp
+++ b/test/yaml-parser.cpp
@@ -49,10 +49,11 @@  protected:
 		if (fd == -1)
 			return false;
 
-		FILE *fh = fdopen(fd, "w");
-		fputs(content.c_str(), fh);
+		int ret = write(fd, content.c_str(), content.size());
+		close(fd);
 
-		fclose(fh);
+		if (ret != static_cast<int>(content.size()))
+			return false;
 
 		return true;
 	}