xref: /minix/minix/lib/libasyn/asyn_synch.c (revision 433d6423)
1 /*	asyn_synch() - step back to synch		Author: Kees J. Bot
2  *								7 Jul 1997
3  */
4 #include "asyn.h"
5 
asyn_synch(asynchio_t * asyn,int fd)6 int asyn_synch(asynchio_t *asyn, int fd)
7 /* No more asynchronous operations on this file descriptor. */
8 {
9 	asynfd_t *afd;
10 	int op;
11 
12 	if ((unsigned) fd >= FD_SETSIZE) { errno= EBADF; return -1; }
13 	afd= &asyn->asyn_afd[fd];
14 
15 	for (op= 0; op < SEL_NR; op++) {
16 		if (afd->afd_state[op] != IDLE) {
17 			errno= EAGAIN;
18 			return -1;
19 		}
20 	}
21 
22 	/* Make sure the file flags are as they once were. */
23 	if (afd->afd_seen && fcntl(fd, F_SETFL, afd->afd_flags) < 0) return -1;
24 	afd->afd_seen= 0;
25 	return 0;
26 }
27