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?

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.