How to properly use flock()

This is a discussion on How to properly use flock() within the Linux Programming forums, part of the Platform Specific Boards category; I am making a call to flock() and getting the error " warning: passing arg 1 of `flock' makes integer ...

  1. #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

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #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?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  5. #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?

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    15
    stat() might help you
    -luke
    I'm with
    <----------- newb!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 02:14 AM
  2. C++ system("rm") not deleting properly?
    By fattysmo in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2008, 11:37 AM
  3. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 09:46 PM
  4. How to properly use a .lib file?
    By Kurisu33 in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2006, 08:19 PM
  5. tic tac toe not working properly
    By h_howee in forum Game Programming
    Replies: 2
    Last Post: 01-01-2006, 12:59 AM

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