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

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Dec 14 10:41:39 CET 2018


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 at 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()

-- 
Regards,

Laurent Pinchart





More information about the libcamera-devel mailing list