libctru/libctru/source/services/soc/soc_ioctl.c
Patrik Rak 6bca5af849
Make the FIONBIO ioctl actually work. (#441)
The fcntl needs the original `sockfd`, not the remapped one.
2020-04-15 09:09:17 +01:00

50 lines
710 B
C

#include "soc_common.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/ioctl.h>
int ioctl(int sockfd, int request, ...)
{
int ret;
int flags;
int *value;
va_list ap;
ret = soc_get_fd(sockfd);
if(ret < 0) {
errno = -ret;
return -1;
}
switch(request) {
case FIONBIO:
va_start(ap, request);
value = va_arg(ap, int*);
va_end(ap);
if(value == NULL) {
errno = EFAULT;
return -1;
}
flags = fcntl(sockfd, F_GETFL, 0);
if(flags == -1)
return -1;
if(*value)
ret = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
else
ret = fcntl(sockfd, F_SETFL, flags & ~O_NONBLOCK);
break;
default:
errno = ENOTTY;
ret = -1;
break;
}
return ret;
}