From owner-freebsd-questions Thu Nov 18 14:28:22 1999 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 662E3154DE for ; Thu, 18 Nov 1999 14:28:18 -0800 (PST) (envelope-from bright@wintelcom.net) Received: from localhost (bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) with ESMTP id OAA25600; Thu, 18 Nov 1999 14:54:21 -0800 (PST) Date: Thu, 18 Nov 1999 14:54:21 -0800 (PST) From: Alfred Perlstein To: Greg Lehey Cc: rover@lglobus.ru, freebsd-questions@FreeBSD.ORG Subject: Re: Is there correct way for program to read from itself? In-Reply-To: <19991118172315.02758@mojave.sitaranetworks.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, 18 Nov 1999, Greg Lehey wrote: > On Friday, 19 November 1999 at 0:27:59 +0300, Oleg V. Volkov wrote: > > On Thu, Nov 18, 1999 at 03:47:36PM -0500, Greg Lehey wrote: > >> On Thursday, 18 November 1999 at 23:28:46 +0300, Oleg V. Volkov wrote: > >>> On Thu, Nov 18, 1999 at 03:23:24PM -0500, Greg Lehey wrote: > >>>>>>> Is there correct way for porgram to read from it's own file? > >>>>>> I'm not sure I understand. What do you mean by "it's own file"? > >>>>>> If you mean the object file, sure. Where's the problem? > >>>>> I mean this situation: > >>>>> I have some program /usr/local/bin/someprog. Is there a way for it > >>>>> to read from itself (from /usr/local/bin/someprog). > >>>> Sure, that's what I said. What do you expect to find? > >>> Could you give me short example? > >> OK, here's copyme.c: > >> > >> #include > >> #include > >> #include > >> #include > >> > >> extern int errno; > >> > >> main (int argc, char *argv []) > >> { > > [skip] > >> } > >> > >> And here's what happens when I run it: > >> > >> $ copyme foo > >> $ cmp copyme foo > >> $ ls -l copyme foo > >> -rwxrwxrwx 1 grog eng 4197 Nov 18 15:44 copyme > >> -r-------- 1 grog eng 4197 Nov 18 15:44 foo > >> $ > >> > >> Not much use, is it? Was that your class assignment? > > > > Heh, and now put it into PATH... > > and > > > > $ copyme foo > > Can't open copyme: No such file or directory > > > > Everything is not that easy. > > That wasn't the question. But it can be fixed. How about you doing > it? I think procfs would be even more helpful (unless the 'file' is still done, or is it?) You guys should have gotten my profs suggestion but someone obviously dropped cc lines. *sigh* And Greg is definetly right, you should be able to look around to solve this problem, if the problem is then PATH, then searching the path is what you need to do, but I still think procfs offers what you need. man 5 procfs. -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message