www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/06/19/04:44:50

Date: Tue, 19 Jun 2001 11:43:55 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Graham Reeds <grahamr AT ntlworld DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Extracting a directory name.
In-Reply-To: <SYpX6.32438$9t5.2956364@news6-win.server.ntlworld.com>
Message-ID: <Pine.SUN.3.91.1010619114327.7390I-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019