aboutsummaryrefslogtreecommitdiffstats
path: root/ports/darwin/guts/fcntl.c
blob: b2b4ebc6915e2481e3f2d4c5e73f115a662b0cbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Copyright (c) 2011 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * int fcntl(int fd, int cmd, ... { struct flock *lock })
 *	int rc = -1;
 */
	int save_errno;
 	struct kludge { off_t unknown[6]; } x;

	va_start(ap, cmd);
	x = va_arg(ap, struct kludge);
	va_end(ap);

	rc = real_fcntl(fd, cmd, x);
	switch (cmd) {
	case F_DUPFD:
#ifdef F_DUPFD_CLOEXEC
	case F_DUPFD_CLOEXEC:
#endif
		/* actually do something */
		rc = real_fcntl(fd, cmd, x);
		save_errno = errno;
		if (rc != -1) {
			pseudo_debug(2, "fcntl_dup: %d->%d\n", fd, rc);
			pseudo_client_op(OP_DUP, 0, fd, rc, 0, 0);
		}
		errno = save_errno;
		break;
	default:
		/* pretty sure this is safe on x86. */
		rc = real_fcntl(fd, cmd, x);
		break;
	}

/*	return rc;
 * }
 */