Mail Archives: djgpp/2007/05/31/08:31:54
-----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 -