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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to