:i	static char d_fcntl_sccs_id[] = "%W% %G%";
:1#include "V_s_lc.h"
#include "sys_fcntl.h"
extern char *d_getfdtype();
extern char *d_getowntype();
/*
* Here's our wrapper for the fcntl-catching system call.  Note that we
* generate a rather detailed debug message at level 4. This is a quite
* difficult part of most programs.
*/
d_fcntl(f,r,a)
	int   f;
	int   r;
	int   a;
{	int   e, i;
	char *m=unknown, *x=unknown;
	Switch(r) {
#ifdef F_DUPFD
	case F_DUPFD  : m = "F_DUPFD"  ; break;
#endif
#ifdef F_GETFD
	case F_GETFD  : m = "F_GETFD"  ; x = d_getfdtype(a); break;
#endif
#ifdef F_GETFL
	case F_GETFL  : m = "F_GETFL"  ; break;
#endif
#ifdef F_GETLK
	case F_GETLK  : m = "F_GETLK"  ; break;
#endif
#ifdef F_GETOWN
	case F_GETOWN : m = "F_GETOWN" ; x = d_getowntype(a); break;
#endif
#ifdef F_SETFD
	case F_SETFD  : m = "F_SETFD"  ; break;
#endif
#ifdef F_SETFL
	case F_SETFL  : m = "F_SETFL"  ; x = d_getfdtype(a); break;
#endif
#ifdef F_SETLK
	case F_SETLK  : m = "F_SETLK"  ; break;
#endif
#ifdef F_SETLKW
	case F_SETLKW : m = "F_SETLKW" ; break;
#endif
#ifdef F_SETOWN
	case F_SETOWN : m = "F_SETOWN" ; x = d_getowntype(a); break;
#endif
	}
:8	V8s "fcntl(%d,%s=%d,%s=%d)",f,m,r,x,a D;
	errno = 0;
#if defined(USE_syscall) && defined(SYS_fcntl)
	i = syscall(SYS_fcntl,f,r,a);
#else
	i = fcntl(f,r,a);
#endif
	e = errno;
:6	V6s "fcntl(%d,%s=%d,%s=%d)=%d [Err %d=%s=%s]",f,m,r,x,a,i,Errinfo D;
	errno = e;
	return i;
}
#if defined(USE_syscall) && defined(SYS_fcntl)
fcntl(f,r,a) {return d_fcntl(f,r,a);}
#endif
/*
* Here's a routine to return a symbolic name for an open/fcntl flag.  We  have
* to  be  a bit careful here, because different Unices define different flags,
* and there might be conflicts with the POSIX symbols.  We tried a switch, but
* there  are too many difficulties with multiple names for the same symbol, so
* we just do a string of ifs.  You may have to add to this list for a new kind
* of Unix.
*/
char *d_getfdtype(a)
{
/*
* Here are the POSIX fcntl flags:
*/
#ifdef F_DUPFD
	if (a==F_DUPFD) return "F_DUPFD";
#endif
#ifdef F_GETFD
	if (a==F_GETFD) return "F_GETFD";
#endif
#ifdef F_SETFD
	if (a==F_SETFD) return "F_SETFD";
#endif
#ifdef F_GETFL
	if (a==F_GETFL) return "F_GETFL";
#endif
#ifdef F_SETFL
	if (a==F_SETFL) return "F_SETFL";
#endif
#ifdef F_SETLK
	if (a==F_SETLK) return "F_SETLK";
#endif
#ifdef F_SETLKW
	if (a==F_SETLKW) return "F_SETLKW";
#endif
#ifdef FD_CLOEXEC
	if (a==FD_CLOEXEC) return "FD_CLOEXEC";
#endif
#ifdef O_APPEND
	if (a==O_APPEND) return "O_APPEND";
#endif
#ifdef O_NONBLOCK
	if (a==O_NONBLOCK) return "O_NONBLOCK";
#endif
#ifdef O_NDELAY
	if (a==O_NDELAY) return "O_NDELAY";
#endif
#ifdef O_RDONLY
	if (a==O_RDONLY) return "O_RDONLY";
#endif
#ifdef O_RDWR
	if (a==O_RDWR) return "O_RDWR";
#endif
#ifdef O_SYNC
	if (a==O_SYNC) return "O_SYNC";
#endif
#ifdef O_WRONLY
	if (a==O_WRONLY) return "O_WRONLY";
#endif
/*
* Here are some BSD symbols that may overlap with the above:
*/
#ifdef FNDELAY
	if (a==FNDELAY) return "FNDELAY";
#endif
#ifdef FSYNCRON
	if (a==FSYNCRON) return "FSYNCRON";
#endif
#ifdef FAPPEND
	if (a==FAPPEND) return "FAPPEND";
#endif
#ifdef FASYNC
	if (a==FASYNC) return "FASYNC";
#endif
#ifdef FNBLOCK
	if (a==FNBLOCK) return "FNBLOCK";
#endif
	return unknown;
}
char *d_getowntype(a)
{
	if (a >= 0) return "pid";
	return "pgrp";
}
