| | |
I need file lock mechanism in Linux platform
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2007
Posts: 25
Reputation:
Solved Threads: 0
Hi all
there is a Windows API function as
This function contains argument for share mode.. When I provide it 0 value then no other process can open/access the file already opened while created this call. That is while I have its handle opened if i try to access file through notepad.. it is restricted.
I need to have a similar working in Linux platform. I found two functions given in Linux which are fcntl() and flock() these two provides file locking facility in Linux. But I have tested it by opening a file and then locking it using fcntl() but then when i open the same file through editor or open() system call it is opened and locking is not functional . I need you people's help. I want to have a lock on the file that no process shall be able to open the file while is is locked. plz help me out and suggest me what i am missing.
Regards
there is a Windows API function as
C Syntax (Toggle Plain Text)
HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile );
I need to have a similar working in Linux platform. I found two functions given in Linux which are fcntl() and flock() these two provides file locking facility in Linux. But I have tested it by opening a file and then locking it using fcntl() but then when i open the same file through editor or open() system call it is opened and locking is not functional . I need you people's help. I want to have a lock on the file that no process shall be able to open the file while is is locked. plz help me out and suggest me what i am missing.
Regards
On *nix all you have to do is pass the right arguments in the open statement and it will work the same way as CreateFile() odes. check your compiler to see if it has fsopen() because I'm not sure if that function is standard C or not.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Other Threads in the C Forum
- Previous Thread: how can i do this pl!
- Next Thread: CHar * variable
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list lists locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation overwrite owf pdf pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






