CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
How can I make sure that my program is the only one accessing a file?
Category C Interview Questions
Rating (4.9) By 17 users
Added on 10/22/2004
Views 3262
Rate it!
Answers:

By using the sopen() function you can open a file in shared mode and explicitly deny reading and writing permissions to any other program but yours. This task is accomplished by using the SH_DENYWR shared flag to denote that your program is going to deny any writing or reading attempts by other programs.

For example, the following snippet of code shows a file being opened in shared mode, denying
access to all other files:

/* Note that the sopen() function is not ANSI compliant... */
fileHandle = sopen(?C:DATASETUP.DAT?, O_RDWR, SH_DENYWR);

By issuing this statement, all other programs are denied access to the SETUP.DAT file. If another program were to try to open SETUP.DAT for reading or writing, it would receive an EACCES error code, denoting that access is denied to the file.





If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is Preprocessor?
View Answer
What is a macro, and how do you use it?
View Answer
What will the preprocessor do for a program?
View Answer
How can you avoid including a header more than once?
View Answer
Can a file other than a .h file be included with #include?
View Answer
What is the benefit of using #define to declare a constant?
View Answer
What is the benefit of using an enum rather than a #define constant?
View Answer
How are portions of a program disabled in demo versions?
View Answer
Is it better to use a macro or a function?
View Answer
What is the difference between #include <file> and #include ?file??
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/1035/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.62