[Rpm-maint] [PATCH] Check for undefined macros

Alexey Tourbin alexey.tourbin at gmail.com
Wed Feb 6 02:55:33 UTC 2013


On Wed, Feb 06, 2013 at 05:48:58AM +0400, Dmitry V. Levin wrote:
> On Sun, Jan 27, 2013 at 05:27:09AM +0000, Alexey Tourbin wrote:
> [...]
> > --- a/build/pack.c
> > +++ b/build/pack.c
> > @@ -22,6 +22,7 @@
> >  #include "build/rpmbuild_misc.h"
> >  
> >  #include "debug.h"
> > +#include <libgen.h>
> >  
> >  typedef struct cpioSourceArchive_s {
> >      rpm_loff_t	cpioArchiveSize;
> > @@ -91,12 +92,14 @@ static rpmRC addFileToTag(rpmSpec spec, const char * file,
> >  	}
> >      }
> >  
> > +    int lineNum = 0;
> >      while (fgets(buf, sizeof(buf), f)) {
> > -	if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
> > -	    rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf);
> > +	char *exp = rpmExpandMacros(spec->macros, buf,
> > +			basename(fn), ++lineNum, NULL, NULL);
> > +	if (exp == NULL)
> >  	    goto exit;
> > -	}
> > -	appendStringBuf(sb, buf);
> > +	appendStringBuf(sb, exp);
> > +	free(exp);
> >      }
> >      headerPutString(h, tag, getStringBuf(sb));
> >      rc = RPMRC_OK;
> 
> There is no need to include <libgen.h>, just otherwise, since configure.ac
> uses AC_USE_SYSTEM_EXTENSIONS, you should avoid including <libgen.h> to
> get the GNU version of basename().

Some files already include <libgen.h> for XPG basename(3) and dirname(3),
and some not.  When filename passed to basename(3) is that of a regular
file (i.e. no trailing slashes), which is presumably the case with
rpmExpandMacros(), XPG basename and GNU basename behave identically.
Perhaps a new function, such as rbasename() in rpmstring.h, could
address this ambiguity, but this is beyound the focus of this patch.

$ git grep '<libgen\.h>\|\<basename(\|\<dirname(' *.c */*.c
build/files.c:#include <libgen.h>
build/files.c:                  basename(fn), ++lineNum, undefined, NULL);
build/files.c:  tmp = xstrdup(diskPath); /* basename() might modify */
build/files.c:  flp->cpioPath = xstrdup(basename(tmp));
build/pack.c:#include <libgen.h>
build/pack.c:                   basename(fn), ++lineNum, NULL, NULL);
build/parsePrep.c:                      c, basename(fn), patchcmd);
build/parsePrep.c:                      basename(fn), patchcmd);
build/parseSpec.c:#include <libgen.h>
build/parseSpec.c:                              basename(ofi->fileName), ofi->lineNum,
build/policies.c:       char *bname = basename(tmp);
build/rpmfc.c:      char *bn = basename(files[i]);
lib/fprint.c:#include <libgen.h>
lib/rpmts.c:#include <libgen.h>
lib/rpmts.c:    (void) rpmioMkpath(dirname(t), 0755, getuid(), getgid());
rpmbuild.c:#include <libgen.h>
rpmbuild.c:    specBase = basename(tarbuf);
rpmbuild.c:     /* dirname() may modify contents so extra hoops needed. */
rpmbuild.c:     srcdir = dirname(dir);
$


More information about the Rpm-maint mailing list