Skip site navigation (1)Skip section navigation (2)

FreeBSD Man Pages

Man Page or Keyword Search:
Man Architecture
Apropos Keyword Search (all sections) Output format
home | help
FLOPEN(3)	       FreeBSD Library Functions Manual		     FLOPEN(3)

NAME
     flopen -- Reliably	open and lock a	file

LIBRARY
     System Utilities Library (libutil,	-lutil)

SYNOPSIS
     #include <sys/fcntl.h>
     #include <libutil.h>

     int
     flopen(const char *path, int flags);

     int
     flopen(const char *path, int flags, mode_t	mode);

DESCRIPTION
     The flopen() function opens or creates a file and acquires	an exclusive
     lock on it.  It is	essentially equivalent with calling open() with	the
     same parameters followed by flock() with an operation argument of
     LOCK_EX, except that flopen() will	attempt	to detect and handle races
     that may occur between opening / creating the file	and locking it.	 Thus,
     it	is well	suited for opening lock	files, PID files, spool	files, mail-
     boxes and other kinds of files which are used for synchronization between
     processes.

     If	flags includes O_NONBLOCK and the file is already locked, flopen()
     will fail and set errno to	EWOULDBLOCK.

     As	with open(), the additional mode argument is required if flags
     includes O_CREAT.

RETURN VALUES
     If	successful, flopen() returns a valid file descriptor.  Otherwise, it
     returns -1, and sets errno	as described in	flock(2) and open(2).

SEE ALSO
     errno(2), flock(2), open(2)

AUTHORS
     The flopen	function and this manual page were written by Dag-Erling
     Smorgrav <des@FreeBSD.org>.

FreeBSD	10.1			 June 6, 2009			  FreeBSD 10.1

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUES | SEE ALSO | AUTHORS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=flopen&sektion=3&manpath=FreeBSD+9.3-RELEASE>

home | help