The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
More on CEP Maturity: Capability Versus Reliability iBot Complex Event Processing RSS News 0 06-03-2008 02:50 AM
Seeing the screen output beyond the scroll capability for the last run command bimukt UNIX for Dummies Questions & Answers 1 05-02-2008 01:22 AM
How do capability macros get named? frequency8 High Level Programming 2 05-23-2007 03:50 AM
saving macros for VIM yngwie UNIX for Dummies Questions & Answers 3 05-13-2007 09:26 PM
troff macros tonyt UNIX for Dummies Questions & Answers 2 01-03-2002 05:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2007
Registered User
 

Join Date: May 2007
Location: San Francisco bay area
Posts: 32
One last question about capability macros

This might be poorly worded.

In the header file, I have

#ifdef LOCK_FCNTL
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#define LOCK(file) setlock(fileno(file), F_WRLCK);
#define UNLOCK(file) setlock(fileno(file), F_UNLCK);
#endif /* LOCK_FCNTL */

#ifdef LOCK_FLOCK
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#define LOCK(file) flock(fileno(file), LOCK_EX)
#define UNLOCK(file) flock(fileno(file), LOCK_UN)
#endif /* LOCK_FLOCK */

And in the file that has main(), I have

#ifdef LOCK_FCNTL
/* Helper function to do fcntl locks.
*/

void setlock(int fd, int type)
{
struct flock lk;

lk.l_type= type;
lk.l_whence= 0;
lk.l_start= 0L;
lk.l_len= 0L;
fcntl(fd,F_SETLKW,&lk);
}

#endif /*LOCK_FCNTL*/


My current operating system supports both fcntl() and flock(). However, the macros for LOCK and UNLOCK seem to assume that the operating system supports either one or the other, but not both. When I compile and run the program, I get no errors.

So the question is, what macro does the computer use? Will it just chose one at random?
Reply With Quote
Forum Sponsor
  #2  
Old 05-23-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by frequency8
So the question is, what macro does the computer use? Will it just chose one at random?
The HAVE_xxx macros are determined by configure. This examines the system by test compilations.

If a system has both then the order of #ifdef's in the code will determine which is used.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0