Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!ll-xn!mit-eddie!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: BSD ?= SysV File Locking Message-ID: <6594@brl-smoke.ARPA> Date: Mon, 26-Oct-87 16:21:07 EST Article-I.D.: brl-smok.6594 Posted: Mon Oct 26 16:21:07 1987 Date-Received: Wed, 28-Oct-87 22:24:32 EST References: <463@petro.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Distribution: na Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 24 Keywords: lockf In article <463@petro.UUCP> jrb@petro.UUCP (Jon Boede) writes: >Does BSD use the lockf() convention like SysV? I've localized functions using >it in hopes that if it didn't I'd only have to fiddle with one area. If it >doesn't, what does the file locking under BSD 4.3 look like? flock() was adopted from the 1984 /usr/group Standard and earlier drafts of IEEE 1003.1. Later drafts of IEEE 1003.1 (POSIX) have adopted the more general locking provided by fcntl() on SVR2+ and later. Berkeley systems have for some time supplied flock(), which is not identical to either of the other two. The lockf() and flock() approaches can be emulated using fcntl() locking. It is good that you've localized this function, so that you can easily adapt it to other file locking kernel interfaces. The 4.2BSD version: #include /* defines the following advisory lock symbols used to construct an "operation" code for flock(): */ /* #define LOCK_SH 1 /* shared (read) lock */ /* #define LOCK_EX 2 /* exclusive (write) lock */ /* #define LOCK_NB 4 /* don't block when locking */ /* #define LOCK_UN 8 /* unlock */ extern int flock(int fd, int operation); /* returns 0 if successful */