Date: Fri, 02 Dec 1994 10:03:26 +0100 To: olly AT mantis DOT co DOT uk (Olly Betts) From: tony AT nt DOT tuwien DOT ac DOT at Subject: Re: Getting a path in argv[0] Cc: djgpp AT sun DOT soe DOT clarkson DOT edu --=====================_786384206==_ Content-Type: text/plain; charset="us-ascii" >DJGPP seems to just give the leaf-name of the executable in argv[0], >rather than the executable path as DOS compilers seem to. I suppose >this follows the UNIX style, but I have a program which uses the path >on argv[0] to find support files. > >Is there a way of altering DJGPP's behaviour, or some way of finding out >where the executable which was run lives? If I'm going to need to alter >DJGPP's source, a pointer as to where to start looking would be helpful. Hi, I had the same problem a week ago. Q: Where is the *.exe which is currently running ? A: either in the current work directory or somewhere in the PATH (1st occurence). My solution: 1) check the current work directory. 2) check the PATH. Piece of code attached to this mail (ffpath.c). This should work on other platforms too if you change DIR_SEP and PATH_SEP. Regards, Tony --=====================_786384206==_ Content-Type: text/plain; charset="us-ascii" #include #include #include #include #include #define DIR_SEP "\\" #define PATH_SEP ";" char *ffpath(char *xfilename) { char *f_p = (char *)calloc(150, sizeof(char)); char *path = strdup(getenv("PATH")); char *pp = path; char *pbu = path; FILE *test = NULL; if((test = fopen(xfilename,"rb" )) != NULL) { fclose(test); strcpy(f_p, xfilename); free(path); return f_p; } else { while(pp = strsep(&path, PATH_SEP)) { strcpy(f_p, pp); strcat(f_p, DIR_SEP); strcat(f_p, xfilename); if((test = fopen(f_p,"rb" )) != NULL) { fclose(test); free(pbu); return f_p; } } } free(pbu); free(f_p); return NULL; } /* End ffpath() */ --=====================_786384206==_ Content-Type: text/plain; charset="us-ascii" ============================================================================ Dipl.-Ing. Anton HELM ** Private: Institut fuer Nachrichtentechnik ** und Hochfrequenztechnik ** Anton HELM Guszhausstr. 25/389 ** Gratian-Marx Str. 7/27 A-1040 Wien ** A-1110 Wien AUSTRIA ** AUSTRIA ** Tel.: +43-1-58801-3520 ** FAX : +43-1-5870583 ** email: Anton DOT Helm AT nt DOT tuwien DOT ac DOT at ** tony AT nt DOT tuwien DOT ac DOT at ** ________ __ __ __ __ __ _______ __ __ /__ __/ / / / / / / / / / / / _____/ / \ / / / / / / / / _____ / / __ / / / / / /____ / /\ \ / / / / / / / / /____/ / / / / / / / / / _____/ / / \ \ / / / / / /___/ / / /__/ /__/ / / / / /____ / / \ \/ / /__/ /_______/ /___________/ /_/ /______/ /_/ \__/ --=====================_786384206==_--