[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: opening twice with O_RDWR

From: Paul Pluzhnikov
Subject: Re: opening twice with O_RDWR
Date: Sun, 31 Dec 2006 06:28:46 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

Mike - EMAIL IGNORED <> writes:

> In the code fragment below, I would have expected a
> failure on the second open,

Why would you expect that?

> I would like to generate a failure.  How can I do this?

Use O_EXCL (which exists *just* for that purpose).

> The file is usually, but not always
> present before the program is run.

You can also stat() the file check whether it exists or not, then
change your program logic appropriateley.

>    if (handle1 < 0)
>       cerr << "fail1" << endl;

This is incorrect way to check for syscall failure.
Use "if (handle == -1)" instead (or your code will think that lsee()
past 2GB mark is a failure).

In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]