Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Nov 2000 03:21:11 -0600
From:      "G. Adam Stanislav" <adam@whizkidtech.net>
To:        Michael Bacarella <mbac@mmap.nyct.net>
Cc:        hackers@FreeBSD.org
Subject:   Re: Kernel calls, are they documented somewhere?
Message-ID:  <20001102032111.A258@whizkidtech.net>
In-Reply-To: <20001102001202.A14447@mmap.nyct.net>; from mbac@mmap.nyct.net on Thu, Nov 02, 2000 at 12:12:02AM -0500
References:  <20001101222558.A408@whizkidtech.net> <20001102001202.A14447@mmap.nyct.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001102032111.A258>