Make soc_fcntl.c more sane.

This commit is contained in:
mtheall 2014-12-11 08:33:26 -06:00
parent d486a0ffc6
commit 20d4e95dfd

View File

@ -3,6 +3,31 @@
#include <fcntl.h>
#include <stdarg.h>
#define O_NONBLOCK_3DS 0x4
#define ALL_3DS (O_NONBLOCK_3DS)
#define ALL_FLAGS (O_NONBLOCK)
static int from_3ds(int flags)
{
int newflags = 0;
if(flags & O_NONBLOCK_3DS) newflags |= O_NONBLOCK;
/* add other flag translations here, but I have only seen O_NONBLOCK */
return newflags;
}
static int to_3ds(int flags)
{
int newflags = 0;
if(flags & O_NONBLOCK) newflags |= O_NONBLOCK_3DS;
/* add other flag translations here, but I have only seen O_NONBLOCK */
return newflags;
}
int fcntl(int fd, int cmd, ...)
{
int ret = 0;
@ -22,14 +47,15 @@ int fcntl(int fd, int cmd, ...)
{
arg = va_arg(args, int);
if(arg && arg!=O_NONBLOCK)
/* make sure they only used known flags */
if(arg & ~ALL_FLAGS)
{
SOCU_errno = -EINVAL;
va_end(args);
return -1;
}
if(arg==O_NONBLOCK)arg = 0x4;
arg = to_3ds(arg);
}
va_end(args);
@ -39,12 +65,22 @@ int fcntl(int fd, int cmd, ...)
cmdbuf[3] = (u32)arg;
cmdbuf[4] = 0x20;
if((ret = svcSendSyncRequest(SOCU_handle))!=0)return ret;
if((ret = svcSendSyncRequest(SOCU_handle)) != 0)
return ret;
ret = (int)cmdbuf[1];
if(ret==0)ret = _net_convert_error(cmdbuf[2]);
if(ret<0)SOCU_errno = ret;
if(ret == 0)
ret = _net_convert_error(cmdbuf[2]);
if(ret < 0)
SOCU_errno = ret;
if(ret<0)return -1;
return ret;
if(ret < 0)
return -1;
if(ret & ~ALL_3DS)
{
/* somehow report unknown flags */
}
return from_3ds(ret);
}