1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

File Lock Check

Discussion in 'C' started by khajalid, Mar 29, 2009.

  1. khajalid

    khajalid New Member

    Joined:
    Mar 29, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    I m making an project in which i have to access a file from from 2 programs. One program is in vc++ and other in php.In this i need to lock the file when one of the program is using it.So, when php is using the file, file get locked but if in the mean time when file is locked if vc++ needs to access it it must check whether the file is already been locked or not. so how to check for it using vc++.

    -regards.
    Ankush Gupta.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Use the Opening Flags for Exclusive Read/Write permission
     
  3. khajalid

    khajalid New Member

    Joined:
    Mar 29, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    I m a student so can u tell me How to implement that?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Read / Write files have the needed modes for that and see the File opening API in both.

    How you are trying to read the file in both and I would tell you the modes.
     
  5. khajalid

    khajalid New Member

    Joined:
    Mar 29, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    i m implementing it as
    fp=fopen("login.txt","r");
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    I assume you are mentioning this in PHP and try using this flock API . ( http://in.php.net/flock )

    For C++ also let me know the API you are using ?
     
  7. khajalid

    khajalid New Member

    Joined:
    Mar 29, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    no, it is in c and i need to check the lock through c which was implemented by php.
     
  8. khajalid

    khajalid New Member

    Joined:
    Mar 29, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Also i need to lock file through c after checking if it is unlocked.
    i have nthg to do with php.i is not my nwork.
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    If you are using Linux you can do is change the chmod of the file to the needed values so others can only access it as per your permission set.

    If you are using Windows then try using _open function
     

Share This Page