Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, December 2006
O_EXCL


Message 1 in thread

Is there support for something similar to O_EXCL for QFiles? I.e. I want 
to open a file for writing. If the file exists already QFile::open() 
must fail.

Any hints?

/eno

--
 [ signature omitted ] 

Message 2 in thread

On 12/19/06, Enrico Thierbach <troll@xxxxxxxxxxxx> wrote:
> Is there support for something similar to O_EXCL for QFiles? I.e. I want
> to open a file for writing. If the file exists already QFile::open()
> must fail.

Doesn't seem like it. Is QFile::exists() an option?

-- 
 [ signature omitted ] 

Message 3 in thread

Robin Ericsson wrote:
> On 12/19/06, Enrico Thierbach <troll@xxxxxxxxxxxx> wrote:
>> Is there support for something similar to O_EXCL for QFiles? I.e. I want
>> to open a file for writing. If the file exists already QFile::open()
>> must fail.
> 
> Doesn't seem like it. Is QFile::exists() an option?

No, because it's not atomic.

/eno

--
 [ signature omitted ] 

Message 4 in thread

On Dec 19, 2006, at 8:54 AM, Enrico Thierbach wrote:

> Is there support for something similar to O_EXCL for QFiles? I.e. I  
> want to open a file for writing. If the file exists already  
> QFile::open() must fail.
>
> Any hints?

Use Unix ::open() with the appropriate flags, and pass the file  
descriptor to QFile;:open( int, OpenMode ). I would expect QFile::open 
() to return false if the given file descriptor is -1, which is the  
case when ::open() fails. The only bummer is that in this mode  
QFile::close() does not actual close a valid file descriptor; you  
will have to derive from QFile to do this.

Brad

-- 
 [ signature omitted ] 

Message 5 in thread

Brad Howes wrote:
> On Dec 19, 2006, at 8:54 AM, Enrico Thierbach wrote:
> 
>> Is there support for something similar to O_EXCL for QFiles? I.e. I 
>> want to open a file for writing. If the file exists already 
>> QFile::open() must fail.
>>
>> Any hints?
> 
> Use Unix ::open() with the appropriate flags, and pass the file 
> descriptor to QFile;:open( int, OpenMode ). I would expect QFile::open() 
> to return false if the given file descriptor is -1, which is the case 
> when ::open() fails. The only bummer is that in this mode QFile::close() 
> does not actual close a valid file descriptor; you will have to derive 
> from QFile to do this.
> 
> Brad
> 
That's it! Thanks,
/eno

--
 [ signature omitted ]