flock in windows?

Started by
12 comments, last by user0 10 years, 8 months ago

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?

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.

Omae Wa Mou Shindeiru

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?

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.

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

A quick google search would seem to indicate that Mingw/Windows does not support flock().

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.

looking here I see flock is part of posix so maybe some hope?

http://en.wikipedia.org/wiki/Fcntl.h#Operations_on_file_descriptors

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/

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

This topic is closed to new replies.

Advertisement