This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Broken basename()


> 
> Thank's for the info!
> 
> What's the rule about using libgen.h and string.h ?
> 
> Can I automatically replace all my libgen.h with string.h
> inside my application?
> 
> If not, how can I make the two includes coexist ?
> 
> Thanks,
> Jean-Pierre

I must admid that I'm definately NOT an glibc expert. I just looked in
the libgen.h header file. :-)

But I still think it is a bug that the function doesn't work as it should
when you include libgen.h. Can somebody confirm this?

If you read the comments in those header files you will see that only the
order of inclusion is important. So if you want to use both include files
and the basename() from string.h then do this:

#include <string.h>   /* include string.h before libgen.h ! */
#include <libgen.h>

....

Succes,

-Remco

> 
> 
> Remco van den Berg wrote:
> 
> > >
> > > Hi!
> > >
> > > I have glibc-devel-2.1.1-6 freshly installed from RedHat 6.0 CD.
> > >
> > > When doing the following, basename no longer returns the right value...
> > >
> > >
> > > #include <libgen.h>
> > > #include <stdio.h>
> > >
> > > int main()
> > > {
> > > char *path = "/jp/include/basename.Text";
> > > printf("basename = %s\n", basename(path));
> > > // will output "/basename.Text" instead of "basename.Text"
> > > }
> > >
> > > --
> > > Jean-Pierre Belanger, OSim Product Development Manager
> > > OriginalSim  - Framework for building distributed simulations.
> > > Tel: 514-766-8868 Ex:28, Fax: 514-766-8861
> > > mailto:jpbelanger@originalsim.com, http://www.originalsim.com
> >
> > And if you use the GNU version it works:
> >
> > Just replace libgen.h by string.h.
> >
> > -Remco
> 
> 
> 
> --
> Jean-Pierre Belanger, OSim Product Development Manager
> OriginalSim  - Framework for building distributed simulations.
> Tel: 514-766-8868 Ex:28, Fax: 514-766-8861
> mailto:jpbelanger@originalsim.com, http://www.originalsim.com
> 
> 
> 
> 
> 


-- 
----------------------------------------------------------------------------
    Remco van den Berg                     Admin DSE  http://www.dse.nl/    
      rvdberg@dse.nl                   Linux Certified Systems Engineer :-) 
----------------------------------------------------------------------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]