My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
soc_fcntl.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 
6 int fcntl(int fd, int cmd, ...)
7 {
8  int ret=0;
9  int arg=0;
10  u32 *cmdbuf = getThreadCommandBuffer();
11 
12  va_list args;
13 
14  if(cmd!=F_GETFL && cmd!=F_SETFL)
15  {
16  SOCU_errno = -EINVAL;
17  return -1;
18  }
19 
20  va_start(args, cmd);
21  if(cmd==F_SETFL)
22  {
23  arg = va_arg(args, int);
24 
25  if(arg && arg!=O_NONBLOCK)
26  {
27  SOCU_errno = -EINVAL;
28  va_end(args);
29  return -1;
30  }
31 
32  if(arg==O_NONBLOCK)arg = 0x4;
33  }
34  va_end(args);
35 
36  cmdbuf[0] = 0x001300C2;
37  cmdbuf[1] = (u32)fd;
38  cmdbuf[2] = (u32)cmd;
39  cmdbuf[3] = (u32)arg;
40  cmdbuf[4] = 0x20;
41 
42  if((ret = svcSendSyncRequest(SOCU_handle))!=0)return ret;
43 
44  ret = (int)cmdbuf[1];
45  if(ret==0)ret = _net_convert_error(cmdbuf[2]);
46  if(ret<0)SOCU_errno = ret;
47 
48  if(ret<0)return -1;
49  return ret;
50 }
u32 * getThreadCommandBuffer(void)
int SOCU_errno
Definition: soc_common.c:5
uint32_t u32
Definition: types.h:23
int fcntl(int fd, int cmd,...)
Definition: soc_fcntl.c:6
s32 _net_convert_error(s32 sock_retval)
Definition: soc_common.c:92
s32 svcSendSyncRequest(Handle session)
Handle SOCU_handle
Definition: soc_common.c:4