deny share file read/write on Mac OS

  • Dear all,

        I have one application(processA) is writting one file.
        And , I create another application(processB) which want to know that if processA are writting the file.
        I know the Window MFC use CFile* file->open(fileName , CFile::shareDenyWrite) , it can return FALSE if the file is being written by processA.
        On Mac OS side. i try some method to do it . but all false .
        1.  use open(fileName , O_SHLOCK  , O_RDWR)
        2.  use FSOpenFork
        3.  NSFileManager

        How can i do? Waiting for you help.Thanks a lot.

    Thank you!
    --Ann
  • On 10 Jan 08, at 01:02, shengjun_guan (ºÞÁn«T) wrote:
    > I have one application(processA) is writting one file.
    > And , I create another application(processB) which want to know
    > that if processA are writting the file.
    > I know the Window MFC use CFile* file->open(fileName ,
    > CFile::shareDenyWrite) , it can return FALSE if the file is being
    > written by processA.
    > On Mac OS side. i try some method to do it . but all false .
    > 1.  use open(fileName , O_SHLOCK  , O_RDWR)
    > 2.  use FSOpenFork
    > 3.  NSFileManager
    >
    > How can i do? Waiting for you help.Thanks a lot.

    I found TN2037[1] in around a minute, which covers this stuff in
    excruciating detail. Please look for docs before you ask the mailing
    list!

    [1]:
    Thanks your reply.
    Because i can't control how ProcessA open/write the file.That mean
    ProcessA open the file without access lock ( O_EXLOCK ) , In my ProcessB
    , also can open the file.

    -----Original Message-----
    From: Andrew Farmer [mailto:<andfarm...>]
    Sent: 2008/1/10 [¬P´Á¥|] ¤U¤È 05:17
    To: shengjun_guan (ºÞÁn«T)
    Cc: <cocoa-dev...>
    Subject: Re: deny share file read/write on Mac OS

    On 10 Jan 08, at 01:02, shengjun_guan (ºÞÁn«T) wrote:
    > I have one application(processA) is writting one file.
    > And , I create another application(processB) which want to know
    > that if processA are writting the file.
    > I know the Window MFC use CFile* file->open(fileName ,
    > CFile::shareDenyWrite) , it can return FALSE if the file is being
    > written by processA.
    > On Mac OS side. i try some method to do it . but all false .
    > 1.  use open(fileName , O_SHLOCK  , O_RDWR)
    > 2.  use FSOpenFork
    > 3.  NSFileManager
    >
    > How can i do? Waiting for you help.Thanks a lot.

    I found TN2037[1] in around a minute, which covers this stuff in
    excruciating detail. Please look for docs before you ask the mailing
    list!

    [1]: http://developer.apple.com/technotes/tn/tn2037.html
  • On Jan 10, 2008, at 6:13 PM, shengjun_guan (ºÞÁn«T) wrote:

    > Because i can't control how ProcessA open/write the file.That mean
    > ProcessA open the file without access lock ( O_EXLOCK ) , In my
    > ProcessB
    > , also can open the file.

    That is correct.

    --
    Dave Carrigan
    <dave...>
    Seattle, WA, USA
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today