Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

May the bluebird of happiness twiddle your bits.


devel / comp.os.ms-windows.programmer.win32 / Re: fopen - open in exclusive read mode ?

SubjectAuthor
* Re: fopen - open in exclusive read mode ?holyghost
`- Re: fopen - open in exclusive read mode ?R.Wieser

1
Re: fopen - open in exclusive read mode ?

<614d46ff$0$694$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=222&group=comp.os.ms-windows.programmer.win32#222

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date: Fri, 24 Sep 2021 05:33:16 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:91.0) Gecko/20100101
Thunderbird/91.1.1
Reply-To: hackingDOTjohan@yahooDOTcom
Subject: Re: fopen - open in exclusive read mode ?
Content-Language: en-US
Newsgroups: comp.os.ms-windows.programmer.win32
References: <rnu88l$6d9$1@gioia.aioe.org>
<1y5oiwrqbnin.13jdb4im9kqkx.dlg@40tude.net>
From: automn.willow@gmail.com (holyghost)
Organization: Brandywine Software
In-Reply-To: <1y5oiwrqbnin.13jdb4im9kqkx.dlg@40tude.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 46
Message-ID: <614d46ff$0$694$14726298@news.sunsite.dk>
NNTP-Posting-Host: 23bfefd4.news.sunsite.dk
X-Trace: 1632454399 news.sunsite.dk 694 automn.willow@gmail.com/109.136.39.83:48350
X-Complaints-To: staff@sunsite.dk
 by: holyghost - Fri, 24 Sep 2021 03:33 UTC

On 11/6/2020 2:33 PM, JJ wrote:
> On Wed, 4 Nov 2020 13:53:28 +0100, R.Wieser wrote:
>> Hello all,
>>
>> I've got a small program which rewrites the contents of a textfile. I'm
>> using "fopen" for both the source as well as the target file, reading lines
>> from the first and writing them to the second.
>>
>> The problem is that when both have the same name the file is destroyed. :-((
>>
>> To fix that I've been looking for an "exclusive read" open mode (so that
>> opening the targetfile would error-out). The thing is that Windows doesn't
>> seem to offer it :
>>
>> https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen
>>
>> It does offer an "x" modifier, but that one only works on writing.
>>
>> I've also found a reference to "flock", but that doesn't seem to be part of
>> the CRTDLL.DLL on XPsp3 .
>>
>> tl;dr:
>> How do I use "fopen" (or a similar crtdll function) to get an exclusive read
>> lock ?
>>
>> Regards,
>> Rudy Wieser
>
> Not possible using `fopen()`. Use `fsopen()` instead. `fopen()` is simply
> not share aware.
>
> `fopen()` uses `_SH_DENYNO` sharing flag no matter what. That flag
> translates to Windows' `FILE_SHARE_READ` and `FILE_SHARE_WRITE`.
>

AFAIK you don't need a read lock for file access (see a database course.)

holly

--
(__)
oo )
|_/\

My Software & Art company (donations are welcome) :
https://ko-fi.com/brandywine9

Re: fopen - open in exclusive read mode ?

<sik67o$1d13$2@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=225&group=comp.os.ms-windows.programmer.win32#225

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!aioe.org!BHGTVyTGRwF2ntnqLVfpDg.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: fopen - open in exclusive read mode ?
Date: Fri, 24 Sep 2021 11:36:24 +0200
Organization: Aioe.org NNTP Server
Lines: 14
Message-ID: <sik67o$1d13$2@gioia.aioe.org>
References: <rnu88l$6d9$1@gioia.aioe.org> <1y5oiwrqbnin.13jdb4im9kqkx.dlg@40tude.net> <614d46ff$0$694$14726298@news.sunsite.dk>
Injection-Info: gioia.aioe.org; logging-data="46115"; posting-host="BHGTVyTGRwF2ntnqLVfpDg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MSMail-Priority: Normal
X-Notice: Filtered by postfilter v. 0.9.2
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Response
 by: R.Wieser - Fri, 24 Sep 2021 09:36 UTC

holyghost,

> AFAIK you don't need a read lock for file access (see a database course.)

:-) A database locks the record when writing to it, so that when reading
there is no way that you will get half the old and half the new record.

But I suggest you read my problem specification first. Its not about the
read and write actions themselves.

Regards,
Rudy Wieser

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor