My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
soc_ioctl.c
Go to the documentation of this file.
1 #include "soc_common.h"
2 #include <errno.h>
3 #include <fcntl.h>
4 #include <stdarg.h>
5 #include <sys/ioctl.h>
6 
7 int ioctl(int fd, int request, ...)
8 {
9  int ret;
10  int flags;
11  int *value;
12  va_list ap;
13 
14  va_start(ap, request);
15 
16  switch(request) {
17  case FIONBIO:
18  value = va_arg(ap, int*);
19  if(value == NULL) {
20  errno = EFAULT;
21  ret = -1;
22  }
23 
24  flags = fcntl(fd, F_GETFL, 0);
25  if(flags == -1) {
26  errno = SOC_GetErrno();
27  va_end(ap);
28  return -1;
29  }
30 
31  if(*value) ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
32  else ret = fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
33 
34  if(ret != 0)
35  errno = SOC_GetErrno();
36 
37  break;
38 
39  default:
40  errno = ENOTTY;
41  ret = -1;
42  break;
43  }
44 
45  va_end(ap);
46 
47  return ret;
48 }
#define FIONBIO
Definition: ioctl.h:3
int fcntl(int fd, int cmd,...)
Definition: soc_fcntl.c:6
int ioctl(int fd, int request,...)
Definition: soc_ioctl.c:7
int SOC_GetErrno()
Definition: soc_common.c:101