delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
Date: | Thu, 31 May 2007 12:35:31 +0200 |
From: | Robert Riebisch <Robert DOT Riebisch AT arcor DOT de> |
User-Agent: | Thunderbird 1.5.0.12 (Windows/20070509) |
MIME-Version: | 1.0 |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Finding a program's base directory |
Lines: | 45 |
Message-ID: | <465ea4ec$0$23146$9b4e6d93@newsspool1.arcor-online.net> |
Organization: | Arcor |
NNTP-Posting-Date: | 31 May 2007 12:35:24 CEST |
NNTP-Posting-Host: | 2d2db171.newsspool1.arcor-online.net |
X-Trace: | DXC=eb`?=4\QMO5_A0jCfgHO6>ic==]BZ:af>4Fo<]lROoR1Fl8W>\BH3Y2<2Wifi:>gf9B5lc^0gQ=41?lK5CCSWJM4k;WSL`n5Im2:0;EIU337C5A14d]]KebZ; |
X-Complaints-To: | usenet-abuse AT arcor DOT de |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
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; } *** -- Robert Riebisch Bitte NUR in der Newsgroup antworten! Please reply to the Newsgroup ONLY!
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |