lock_reg.c

来自「让你了解Unix进程间的通信是如何实现的」· C语言 代码 · 共 24 行

C
24
字号
/* include lock_reg */#include	"unpipc.h"intlock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len){	struct flock	lock;	lock.l_type = type;		/* F_RDLCK, F_WRLCK, F_UNLCK */	lock.l_start = offset;	/* byte offset, relative to l_whence */	lock.l_whence = whence;	/* SEEK_SET, SEEK_CUR, SEEK_END */	lock.l_len = len;		/* #bytes (0 means to EOF) */	return( fcntl(fd, cmd, &lock) );	/* -1 upon error */}/* end lock_reg */voidLock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len){	if (lock_reg(fd, cmd, type, offset, whence, len) == -1)		err_sys("lock_reg error");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?