[libcamera-devel] log: Use libgen implementation of basename

Message ID 20181214085909.32325-1-kieran.bingham@ideasonboard.com
State Rejected
Headers show
Series
  • [libcamera-devel] log: Use libgen implementation of basename
Related show

Commit Message

Kieran Bingham Dec. 14, 2018, 8:59 a.m. UTC
Pull in the libgen header to define basename. Unfortuantely this
requires casting away the const flag on the filename.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/log.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart Dec. 14, 2018, 9:41 a.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Friday, 14 December 2018 10:59:09 EET Kieran Bingham wrote:
> Pull in the libgen header to define basename. Unfortuantely this
> requires casting away the const flag on the filename.

Please don't ! There's a reason why basename() from libgen.h has no const, 
that's because it may modify its argument.

Let's handle other libc implementations later (for the record I think recent 
Android versions provide the GNU_SOURCE implementation of basename()).

> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/libcamera/log.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
> index 3715e69d810e..7096071e53f6 100644
> --- a/src/libcamera/log.cpp
> +++ b/src/libcamera/log.cpp
> @@ -9,6 +9,7 @@
>  #include <ctime>
>  #include <iomanip>
>  #include <string.h>
> +#include <libgen.h>
> 
>  #include "log.h"
>  #include "utils.h"
> @@ -80,7 +81,7 @@ LogMessage::LogMessage(const char *fileName, unsigned int
> line, << std::setw(9) << timestamp.tv_nsec << "]";
> 
>  	msgStream << " " << log_severity_name(severity);
> -	msgStream << " " << basename(fileName) << ":" << line << " ";
> +	msgStream << " " << basename((char *)fileName) << ":" << line << " ";
>  }
> 
>  LogMessage::~LogMessage()

Patch

diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
index 3715e69d810e..7096071e53f6 100644
--- a/src/libcamera/log.cpp
+++ b/src/libcamera/log.cpp
@@ -9,6 +9,7 @@ 
 #include <ctime>
 #include <iomanip>
 #include <string.h>
+#include <libgen.h>
 
 #include "log.h"
 #include "utils.h"
@@ -80,7 +81,7 @@  LogMessage::LogMessage(const char *fileName, unsigned int line,
 		  << std::setw(9) << timestamp.tv_nsec << "]";
 
 	msgStream << " " << log_severity_name(severity);
-	msgStream << " " << basename(fileName) << ":" << line << " ";
+	msgStream << " " << basename((char *)fileName) << ":" << line << " ";
 }
 
 LogMessage::~LogMessage()