Jump to content
  • Advertisement
Sign in to follow this  
jeff8j

flock in windows?

This topic is 1839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im cross compiling with mingw and currently using flock for some serverside sessions.

 

I get error: ‘LOCK_EX’ was not declared in this scope but its not saying anything about flock itself?

 

Does flock work in windows or do I have to change it to use the LockFileEx? If it does work in windows what would I include to get LOCK_EX defined?

Share this post


Link to post
Share on other sites
Advertisement

It's a missing symbol error like any other.

In which file do you think "LOCK_EX" is defined? Are you really including that file? Is it really defined there? Does some #if or #ifdef remove the definition? Are you doing something unusual with namespaces and/or macros? The questions are the usual generic ones, and the techniques to answer them, like inspecting preprocessor output, are platform independent.

Share this post


Link to post
Share on other sites

For linux I believe its in sys/fcntl.h or sys/file.h and those are included in the mingw build as well nothing any different. Im coming to the conclusion that flock simply doesnt work in windows because if I use say 2 for LOCK_EX which I found it to be defined as it doesnt compile because it can find the flock function. Can someone confirm or deny that flock works or doesnt on windows?

Share this post


Link to post
Share on other sites

flock is not C, or Win32 API, and does not even appear to be POSIX. So the question would be if your compiler/gcc port includes that function in its libraries.

Share this post


Link to post
Share on other sites

I see I am finding contradictory posts about flock being posix though. So now I guess the question is if mingw does flock?

Share this post


Link to post
Share on other sites

Yes it does but when I search "mingw flock" the two posts I see that have a striaght to the point answer one is from 2001 and another from 2007 infact the newest post on the first page is from 2012 so im hoping to get a more informed answer or an alternative rather than just look it up on google.

Share this post


Link to post
Share on other sites

Also, if I recall Linux and Window's do not have the same functionality anyway. As far as I know on Window's it is not possible to ignore a lock (via LockFile or the CreateFile sharing modes), but on Linux a file lock is only an advice thing (and from memory I am not even sure if fopen follows it by default). So you may need to think carefully about what you are trying to do.

 

 

Regarding that wiki page. It seems to just say most unix like systems have it, not that it is part of the POSIX standard, and searching for POSIX related things, the closest I just found was fcntl http://pubs.opengroup.org/onlinepubs/9699919799/

Edited by SyncViews

Share this post


Link to post
Share on other sites

Yea in linux you can still open a file that is locked but you cant obtain a lock on it so you have to build your program to handle it other programs that dont check will ignore the lock.

 

Yea I see that now I was taken there from the posix wiki and didnt think about it.

 

Im just trying to get something locking it seems odd this would be so hard to find information about someone has to be doing it.

Hmm ill look more at the flock file and see if thats implemented

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!