Mail Archives: djgpp/2001/06/19/04:44:50
On Mon, 18 Jun 2001, Graham Reeds wrote:
> > Did you consider the possibility that strncpy might not null-terminate
> > the resulting string in BaseDir?
>
> I did, and tried to append one with strcat, but that didn't solve the
> problem.
You didn't show the code which appended a null character, so perhaps
that was done incorrectly. What you did post is bound to print
garbage because the string isn't null-terminated.
> > (Btw, there are library functions to do this, called `basename' and
> > `direname'. They are better than your code, because they also support
> > forward slashes and file names like d:foo.)
>
> I've never heard of basename and/or dirname. They work fine, though a
> forward slash causes a SISEGV like my code did. How portable are these?
They are portable to most modern Unix and GNU/Linux platforms. I
don't know about MSVC, but you could simply take the source of these
two functions from djlsr203.zip and put it into your program. That's
the beauty of Free Software.
- Raw text -