Date: Tue, 19 Jun 2001 11:43:55 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Graham Reeds cc: djgpp AT delorie DOT com Subject: Re: Extracting a directory name. In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Precedence: bulk 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.