FreeBSD/usr.sbin/ctm/ctm_rmail/ctm_rmail.c
/*
 * Create and lock the given file.
 *
 * Clearing the lock is as simple as closing the file descriptor we return.
 */
Create and lock the given file.
Clearing the lock is as simple as closing the file descriptor we return.
Create and lock the given file . Clearing the lock is as simple as closing the file descriptor we return .
int
lock_file(char *name)
    {
    int lfd;
    if ((lfd = open(name, O_WRONLY|O_CREAT, 0600)) < 0)
	{
	err("*open: '%s'", name);
	return -1;
	}
    if (flock(lfd, LOCK_EX) < 0)
	{
	close(lfd);
	err("*flock: '%s'", name);
	return -1;
	}
    return lfd;
    }
int lock_file ( char * name ) { int lfd ; if ( ( lfd = open ( name , O_WRONLY | O_CREAT , 0600 ) ) < 0 ) { err ( " " , name ) ; return -1 ; } if ( flock ( lfd , LOCK_EX ) < 0 ) { close ( lfd ) ; err ( " " , name ) ; return -1 ; } return lfd ; }
Create and lock the given file.
Create and lock the given file .