ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/05/31/08:31:54

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Thu, 31 May 2007 15:29:59 +0300
From: alex bodnaru <alexbodn AT 012 DOT net DOT il>
Subject: Re: Finding a program's base directory
In-reply-to: <465ea4ec$0$23146$9b4e6d93@newsspool1.arcor-online.net>
To: djgpp AT delorie DOT com
Message-id: <465EBFC7.2000400@alex3>
MIME-version: 1.0
X-Enigmail-Version: 0.94.2.0
References: <465ea4ec$0$23146$9b4e6d93 AT newsspool1 DOT arcor-online DOT net>
User-Agent: Icedove 1.5.0.10 (X11/20070329)
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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


hi

looks ok

alex

Robert Riebisch wrote:
> Hi!
> 
> I want to find a program's base directory. Program binary is in, e.g.,
> `C:\PROGRAMS\FOO\BIN\BAR.EXE'. get_base_dir() is called with argv[0] in
> pgm and shall return `C:\PROGRAMS\FOO'.
> 
> The following code works for me, but as I'm no C expert, I want you to
> have a look at it. Specifically I'm not sure about the `base_path !=
> NULL' comparison. Is it necessary or just a waste? Thanks in advance!
> 
> ***
> # ifdef __DJGPP__
> #  include <crt0.h>
> int _crt0_startup_flags = _CRT0_FLAG_USE_DOS_SLASHES;
> #  endif
> ***
> 
> ***
> static char *get_base_dir(char *pgm)
> {
>    static char base_path[MAX_PATH_LEN];
>    char *p;
> 
>    strncpy (base_path, pgm, MAX_PATH_LEN);
>    if (base_path != NULL)
>      {
> 	/* drop file name */
> 	p = strrchr (base_path, '\\');
> 	if (p != NULL)
> 	  {
> 	     *p = '\0';
> 	     /* drop also 'bin' */
> 	     p = strrchr (base_path, '\\');
> 	     if (p != NULL)
> 	       *p = '\0';
> 	  }
>      }
>    return base_path;
> }
> ***
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBRl6/x9pwN1sq38njAQKHngQAorJSgMWjWXUrIzOf4OqdxCaPO6rZ0glm
WeKvJwLrR0DpjuuLFKy5wirk4rRgexG/xXiFypA71qoCOpIRnSXiJQemGWDyrrm3
LoM+4bRUci1alPwoSl/a4Ytp2tm08LSyqUI2Gjn58Ty/hAp1MTplzUj8HBNDM1co
Aeh60UtHk+0=
=IjEN
-----END PGP SIGNATURE-----

- Raw text -


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