From owner-freebsd-hackers Thu Nov 2 1:23: 3 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from whizkidtech.net (r31.bfm.org [216.127.220.127]) by hub.freebsd.org (Postfix) with ESMTP id DB58737B479 for ; Thu, 2 Nov 2000 01:22:55 -0800 (PST) Received: (from adam@localhost) by whizkidtech.net (8.9.2/8.9.2) id DAA00299; Thu, 2 Nov 2000 03:21:43 -0600 (CST) (envelope-from adam) Date: Thu, 2 Nov 2000 03:21:11 -0600 From: "G. Adam Stanislav" To: Michael Bacarella Cc: hackers@FreeBSD.org Subject: Re: Kernel calls, are they documented somewhere? Message-ID: <20001102032111.A258@whizkidtech.net> References: <20001101222558.A408@whizkidtech.net> <20001102001202.A14447@mmap.nyct.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <20001102001202.A14447@mmap.nyct.net>; from mbac@mmap.nyct.net on Thu, Nov 02, 2000 at 12:12:02AM -0500 Organization: Whiz Kid Technomagic X-URL: http://www.whizkidtech.net/ X-Castle: http://www.redprince.net/ X-Special-Effects: http://www.FilmSFX.com/ X-Operating-System: FreeBSD whizkidtech.net 3.1-RELEASE FreeBSD 3.1-RELEASE Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, Nov 02, 2000 at 12:12:02AM -0500, Michael Bacarella wrote: >This isn't such a daunting task with grep. Source code cross referencers >can also help, but I don't use them nearly as often as I thought I would. Thanks for the grep suggestion. I think I found the source code for open() now (with grep): /usr/src/sys/kern/vfs_syscalls.c Indeed, when it fails, it returns an error. That happens to be 2 when the file does not exist (ENOENT = 2). Hmmm. That means that if I get a value above 2, it can be the file descriptor, or it can be an error. That's making me a bit nervous. I need to distinguish between errors and file descriptors. However, there seems to be a way, though not fullproof: Each open returns the file descriptor that is 1 higher than the last. Since stdin, stdout, and stderr are open already, the first fd = 3, the next 4, etc. I suppose I need to declare a variable and initialize it to 3. Whenever I call open, if the return value equals to that variable, the open probably succeeded, otherwise it failed. Then, of course, I need to increase the variable so I can use it with the next open. But this will probably not work if my program is called as a child of another which has some files opened already, will it? I am certainly open (no pun intended) to suggestions. Adam -- Roma non uno die aedificata est To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message