Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   File Lock Check (http://www.go4expert.com/forums/file-lock-check-t16711/)

khajalid 29Mar2009 17:01

File Lock Check
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++.

Ankush Gupta.

shabbir 31Mar2009 07:46

Re: File Lock Check
Use the Opening Flags for Exclusive Read/Write permission

khajalid 31Mar2009 08:40

Re: File Lock Check
I m a student so can u tell me How to implement that?

shabbir 31Mar2009 14:12

Re: File Lock Check
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.

khajalid 31Mar2009 16:41

Re: File Lock Check
i m implementing it as

shabbir 31Mar2009 19:15

Re: File Lock Check
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 ?

khajalid 1Apr2009 16:37

Re: File Lock Check
no, it is in c and i need to check the lock through c which was implemented by php.

khajalid 1Apr2009 16:42

Re: File Lock Check
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.

shabbir 1Apr2009 18:47

Re: File Lock Check
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

All times are GMT +5.5. The time now is 09:08.