poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix warning about 'basename'


From: Jose E. Marchesi
Subject: Re: Fix warning about 'basename'
Date: Wed, 24 Feb 2021 10:22:07 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Bruno.

> On FreeBSD 12 and Solaris (IIRC), I'm seeing this warning:
>
> ../../poke/pk-cmd-def.c:73:15: warning: implicit declaration of
> function 'basename' is invalid in C99
> [-Wimplicit-function-declaration]
>               basename (source), first_line);
>               ^
> ../../poke/pk-cmd-def.c:73:15: warning: format specifies type 'char *'
> but the argument has type 'int' [-Wformat]
>               basename (source), first_line);
>               ^~~~~~~~~~~~~~~~~
> ../../poke/pk-cmd-def.c:99:15: warning: implicit declaration of
> function 'basename' is invalid in C99
> [-Wimplicit-function-declaration]
>               basename (source), first_line);
>               ^
> ../../poke/pk-cmd-def.c:99:15: warning: format specifies type 'char *'
> but the argument has type 'int' [-Wformat]
>               basename (source), first_line);
>               ^~~~~~~~~~~~~~~~~
> 4 warnings generated.
>
> The cause of the warning is that the basename() function has different
> semantics on different systems. See
> <https://www.gnu.org/software/gnulib/manual/html_node/basename.html>.
> In particular, there is a conflict between POSIX and GNU. Therefore,
> I propose to use the fix from the Gnulib documentation: use a differently
> named function last_component().
>
> Also, this function last_component() is already used in a couple of
> other places. But the module 'dirname' is overkill for it. The module
> 'basename-lgpl' is the minimal module that provides this function.
>
> Proposed patch.

OK for master.
Thanks!

>>From b0b5f0ca523dfd03644d4c063cb2dfda3fadd5d8 Mon Sep 17 00:00:00 2001
> From: Bruno Haible <bruno@clisp.org>
> Date: Wed, 24 Feb 2021 02:07:40 +0100
> Subject: [PATCH] Fix warning about 'basename' function.
>
> * bootstrap.conf (gnulib_modules, libpoke_modules): Request 'basename-lgpl'
> instead of 'dirname'.
> * libpoke/pkl.c: Include "basename-lgpl.h" instead of "dirname.h".
> * poke/pk-map.c: Likewise.
> * poke/pk-cmd-def.c: Likewise.
> (print_var_decl, print_fun_decl, print_type_decl): Use last_component() 
> instead
> of base_name() or basename().
> ---
>  bootstrap.conf    | 4 ++--
>  libpoke/pkl.c     | 2 +-
>  poke/pk-cmd-def.c | 8 ++++----
>  poke/pk-map.c     | 2 +-
>  4 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/bootstrap.conf b/bootstrap.conf
> index dbf7247..1325885 100644
> --- a/bootstrap.conf
> +++ b/bootstrap.conf
> @@ -22,9 +22,9 @@
>  gnulib_modules="
>    accept
>    array-list
> +  basename-lgpl
>    bind
>    byteswap
> -  dirname
>    findprog
>    fstat
>    gendocs
> @@ -63,8 +63,8 @@ gnulib_modules="
>  
>  # gnulib modules used in libpoke/.
>  libpoke_modules="
> +  basename-lgpl
>    byteswap
> -  dirname
>    gettime
>    free-posix
>    fstat
> diff --git a/libpoke/pkl.c b/libpoke/pkl.c
> index 22d6457..cdc9e72 100644
> --- a/libpoke/pkl.c
> +++ b/libpoke/pkl.c
> @@ -25,7 +25,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  
> -#include "dirname.h"
> +#include "basename-lgpl.h"
>  
>  #include "pkt.h"
>  #include "pk-utils.h"
> diff --git a/poke/pk-cmd-def.c b/poke/pk-cmd-def.c
> index 22b350b..fe9d7c4 100644
> --- a/poke/pk-cmd-def.c
> +++ b/poke/pk-cmd-def.c
> @@ -20,7 +20,7 @@
>  #include <string.h>
>  
>  #include "xalloc.h"
> -#include "dirname.h"
> +#include "basename-lgpl.h"
>  
>  #include "poke.h"
>  #include "pk-cmd.h"
> @@ -43,7 +43,7 @@ print_var_decl (int kind,
>  
>    if (source)
>      asprintf (&source_str, "%s:%d",
> -              base_name (source), first_line);
> +              last_component (source), first_line);
>    else
>      source_str = xstrdup ("<stdin>");
>  
> @@ -70,7 +70,7 @@ print_fun_decl (int kind,
>  
>    if (source)
>      asprintf (&source_str, "%s:%d",
> -              basename (source), first_line);
> +              last_component (source), first_line);
>    else
>      source_str = xstrdup ("<stdin>");
>  
> @@ -96,7 +96,7 @@ print_type_decl (int kind,
>  
>    if (source)
>      asprintf (&source_str, "%s:%d",
> -              basename (source), first_line);
> +              last_component (source), first_line);
>    else
>      source_str = xstrdup ("<stdin>");
>  
> diff --git a/poke/pk-map.c b/poke/pk-map.c
> index 7083345..67bb605 100644
> --- a/poke/pk-map.c
> +++ b/poke/pk-map.c
> @@ -24,7 +24,7 @@
>  #include <string.h>
>  #include <xalloc.h>
>  #include <assert.h>
> -#include "dirname.h"
> +#include "basename-lgpl.h"
>  
>  #include "poke.h"
>  #include "pk-utils.h"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]