C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-05-2003, 09:09 PM   #1
Registered User
 
Join Date: Oct 2002
Posts: 27
How to properly use flock()

I am making a call to flock() and getting the error
" warning: passing arg 1 of `flock' makes integer from pointer without a cast"
when I try to compile. I am running FreeBSD and using gcc.

Code:
  flock(logfile,LOCK_EX);/*lock log file*/
  fputs("client logged in",logfile);
  flock(logfile,LOCK_UN);/*unlock log file*/
logfile is declared like this
Code:
FILE *logfile;
this is my first time every using flock(), it seems like it would be much easier than using POSIX semaphores. Does anyone know why I am getting this error? The fputs() call does not give me any errors at compile time.

thanks in advance
samps005 is offline   Reply With Quote
Old 05-05-2003, 09:23 PM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,643
Read the man page for it. Then actually call it right. It uses a file descriptor. A descriptor is not the same thing as a "FILE*".

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 05-05-2003, 09:47 PM   #3
Registered User
 
Join Date: Oct 2002
Posts: 27
sorry, I did read the man page for it, I just didn't catch that is was asking for a file descriptor.

is there anyway to get the file descriptor from the file pointer?
samps005 is offline   Reply With Quote
Old 05-05-2003, 10:18 PM   #4
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,643
Quote:
Originally posted by samps005
is there anyway to get the file descriptor from the file pointer?
Do you need a file pointer? You could always use open instead. Or if you need a file pointer, I'm pretty sure there's a way to do it, but the function name escapes me at this time.

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 05-05-2003, 11:16 PM   #5
Registered User
 
Join Date: Oct 2002
Posts: 27
yeah, I need the file pointer most of my other code needs it. Does anyone else know of a function to get a file descriptor from a file pointer? Or maybe just another really simple way to lock a file?
samps005 is offline   Reply With Quote
Old 05-06-2003, 12:22 AM   #6
Registered User
 
Join Date: May 2003
Posts: 15
stat() might help you
-luke
__________________
I'm with
<----------- newb!
und3rdog is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
fwrite not writing property (or fread not reading properly) stanlvw C++ Programming 3 03-05-2009 03:14 AM
C++ system("rm") not deleting properly? fattysmo C++ Programming 4 05-17-2008 11:37 AM
terminal output not showing output properly stanlvw C Programming 13 11-19-2007 10:46 PM
How to properly use a .lib file? Kurisu33 C++ Programming 6 09-28-2006 08:19 PM
tic tac toe not working properly h_howee Game Programming 2 01-01-2006 01:59 AM


All times are GMT -6. The time now is 08:07 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22