//lib/lock_test.c
#include	"unpipc.h"

pid_t
lock_test(int fd, int type, off_t offset, int whence, off_t len)
{
	struct flock	lock;

	lock.l_type = type;		/* F_RDLCK or F_WRLCK */
	lock.l_start = offset;	/*     l_whence */
	lock.l_whence = whence;	/* SEEK_SET, SEEK_CUR, SEEK_END */
	lock.l_len = len;		/*  , 0 -    */

	if (fcntl(fd, F_GETLK, &lock) == -1)
		return(-1);			/*   */

	if (lock.l_type == F_UNLCK)
		return(0);			/* false,      */
	return(lock.l_pid);		/* true,   PID ,   */
}
