📄 lockf.c
字号:
#ifndef lintstatic char *sccsid = "@(#)lockf.c 4.1 (ULTRIX) 7/3/90";#endif lint/************************************************************************ * * * Copyright (c) 1985 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//************************************************************************ * * Modification History * * Stephen Reilly, 09-Sep-85 * Created of the new lockf call. * ***********************************************************************/#include <errno.h>#include <fcntl.h>#include <unistd.h>lockf(fildes, function, size)long size;int fildes, function;{ struct flock l; int rv; l.l_whence = 1; if (size < 0) { l.l_start = size; l.l_len = -size; } else { l.l_start = 0L; l.l_len = size; } switch (function) { case F_ULOCK: l.l_type = F_UNLCK; rv = fcntl(fildes, F_SETLK, &l); break; case F_LOCK: l.l_type = F_WRLCK; rv = fcntl(fildes, F_SETLKW, &l); break; case F_TLOCK: l.l_type = F_WRLCK; rv = fcntl(fildes, F_SETLK, &l); break; case F_TEST: l.l_type = F_WRLCK; rv = fcntl(fildes, F_GETLK, &l); if (rv != -1) { if (l.l_type == F_UNLCK) return (0); else { errno = EACCES; return (-1); } } default: errno = EINVAL; return (-1); } if (rv < 0) { switch(errno) { case EMFILE: case ENOSPC: /* A deadlock error is given if we run out of resources, * in compliance with /usr/group standards. */ errno = EDEADLK; break; default: break; } } return (rv);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -