#ifndef _FCNTL_H
#define _FCNTL_H

#include <sys/types.h>		// ͷļ˻ϵͳ͡

/* open/fcntl - NOCTTY, NDELAY isn't implemented yet */
/* open/fcntl - NOCTTY NDELAY ڻûʵ */
#define O_ACCMODE 00003		// ļģʽ롣
// ļopen()ļfcntl()ʹõļģʽͬʱֻʹ֮һ
#define O_RDONLY 00		// ֻʽļ
#define O_WRONLY 01		// ֻдʽļ
#define O_RDWR 02		// Զдʽļ
// ļ־open()ģʽ'λ'ķʽһʹá
#define O_CREAT 00100 /* not fcntl */	// ļھʹ
#define O_EXCL 00200 /* not fcntl */	// ռʹļ־
#define O_NOCTTY 00400 /* not fcntl */	// նˡ
#define O_TRUNC 01000 /* not fcntl */	// ļѴд򳤶ȽΪ0
#define O_APPEND 02000		// ӷʽ򿪣ļָΪļβ
#define O_NONBLOCK 04000 /* not fcntl */	// ʽ򿪺Ͳļ
#define O_NDELAY O_NONBLOCK	// ʽ򿪺Ͳļ

/* Defines for fcntl-commands. Note that currently
* locking isn't supported, and other things aren't really
* tested.
*/
/* 涨fcntl עĿǰû֧֣
* ʵϻûвԹ
*/
// ļ()fcntl()
#define F_DUPFD 0 /* dup */	// ļΪСֵľ
#define F_GETFD 1 /* get f_flags */	// ȡļ־
#define F_SETFD 2 /* set f_flags */	// ļ־
#define F_GETFL 3 /* more flags (cloexec) */	// ȡļ״̬־ͷģʽ
#define F_SETFL 4		// ļ״̬־ͷģʽ
// ļfcntl()ĵlock ָflock ṹָ롣
#define F_GETLK 5 /* not implemented */	// ֹflock ṹ
#define F_SETLK 6		// (F_RDLCK F_WRLCK)(F_UNLCK)
#define F_SETLKW 7		// ȴû

/* for F_[GET|SET]FL */
/*  F_GETFL F_SETFL */
// ִexec()غʱرļ(ִʱر - Close On EXECution)
#define FD_CLOEXEC 1		/* actually anything with low bit set goes */
/* ʵֻҪλΪ1  */

/* Ok, these are locking features, and aren't implemented at any
* level. POSIX wants them.
*/
/* OKͣκκжûʵ֡POSIX ׼ҪЩ͡
*/
#define F_RDLCK 0		// ļ
#define F_WRLCK 1		// ռдļ
#define F_UNLCK 2		// ļ

/* Once again - not implemented, but ... */
/* ͬ - Ҳûʵ֣... */
// ļݽṹӰļε(l_type)ʼƫ(l_whence)
// ƫ(l_start)(l_len)ʵʩĽid
struct flock
{
  short l_type;			// ͣF_RDLCKF_WRLCKF_UNLCK
  short l_whence;		// ʼƫ(SEEK_SETSEEK_CUR SEEK_END)
  off_t l_start;		// Ŀʼƫƣֽ
  off_t l_len;			// ĴС0 Ϊļĩβ
  pid_t l_pid;			// Ľid
};

// ʹ־ĺԭ͡
// ļдһѴļ
// filename ļļmode Ǵļԣμinclude/sys/stat.h
extern int creat (const char *filename, mode_t mode);
// ļӰļĴ򿪡
// fildes ļcmd ǲ23-30 С
extern int fcntl (int fildes, int cmd, ...);
// ļļļ֮佨ϵ
// filename ļļflags 7-17 ϵı־ϡ
extern int open (const char *filename, int flags, ...);

#endif
