⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lockopen2.c

📁 这是unix网络编程一书的源代码希望能对大家的学习提供一种便利
💻 C
字号:
#include	"unpipc.h"

#define	LOCKFILE	"/tmp/seqno.lock"

void
my_lock(int fd)
{
	int		tempfd;

		/* create with O_TRUNC and no permission bits */
	while ( (tempfd = open(LOCKFILE, O_CREAT | O_WRONLY | O_TRUNC, 0)) < 0) {
		if (errno != EACCES)
			err_sys("open error for lock file");
		/* someone else has the lock, loop around and try again */
	}
	Close(tempfd);			/* opened the file, we have the lock */
}

void
my_unlock(int fd)
{
	Unlink(LOCKFILE);		/* release lock by removing file */
}

⌨️ 快捷键说明

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