Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!jarthur!elroy.jpl.nasa.gov!decwrl!orc!mipos3!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: How to get the pathname of the current executable? Message-ID: <1990Feb13.173913.4555@iwarp.intel.com> Date: 13 Feb 90 17:39:13 GMT References: <1610.25d028a3@wums.wustl.edu> <1990Feb7.211538.3894@iwarp.intel.com> <5378@buengc.BU.EDU> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 34 In-Reply-To: bph@buengc.BU.EDU (Blair P. Houghton) In article <5378@buengc.BU.EDU>, bph@buengc (Blair P. Houghton) writes: | Sum hecker. | | Take argv[0], if it doesn't have the path, or the full path, | cut it up to get the command name, say "prog", then strcat(3) | it onto "/usr/ucb/which" and call system(3): | | foo = "/usr/ucb/which prog" | system(foo); | | As long as you're still in the directory from which the | program was run, and as long as your path was the same | as the one set in your .cshrc (someone please tell me | why which(1) reads the .cshrc...) then you'll come up | with /usr/foo/bar/bletch/prog, barring surreptition. But, this is exactly what I said was subject to spoofing and failure! There is no general solution that works in all cases, although you can get a useful answer under *many* typical circumstances. In case this isn't *very* obvious... remember: argv[0] is ARBITRARY! Just because the shells typically pass the name of the command (with or without a leading path, depending on the shell) in argv[0] *doesn't* mean you can depend on it! Try reading a little closer next time, please. Just another UNIX hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/