FLOPEN

Section: Misc. Reference Manual Pages (3bsd)
Page Index

BSD mandoc
 

NAME

flopen flopenat - Reliably open and lock a file  

LIBRARY

Lb libbsd  

SYNOPSIS

In sys/fcntl.h In libutil.h (See libbsd(7) for include usage.) Ft int Fn flopen const char *path int flags Ft int Fn flopen const char *path int flags mode_t mode Ft int Fn flopenat int fd const char *path int flags Ft int Fn flopenat int fd const char *path int flags mode_t mode  

DESCRIPTION

The Fn flopen function opens or creates a file and acquires an exclusive lock on it. It is essentially equivalent with calling Fn open with the same parameters followed by Fn flock with an Fa operation argument of LOCK_EX except that Fn 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, mailboxes and other kinds of files which are used for synchronization between processes.

If Fa flags includes O_NONBLOCK and the file is already locked, Fn flopen will fail and set errno to EWOULDBLOCK

As with Fn open , the additional Fa mode argument is required if Fa flags includes O_CREAT

The Fn flopenat function is equivalent to the Fn flopen function except in the case where the Fa path specifies a relative path. In this case the file to be opened is determined relative to the directory associated with the file descriptor Fa fd instead of the current working directory. If Fn flopenat is passed the special value AT_FDCWD in the Fa fd parameter, the current working directory is used and the behavior is identical to a call to Fn flopen .  

RETURN VALUES

If successful, Fn 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

An -nosplit The function and this manual page were written by An Dag-Erling Smørgrav Aq Mt des@FreeBSD.org .


 

Index

NAME
LIBRARY
SYNOPSIS
DESCRIPTION
RETURN VALUES
SEE ALSO
AUTHORS
LinuxReviews : manual page archive : man3