mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 09:32:52 +00:00
Cleanups
This commit is contained in:
parent
4c7beacfe4
commit
b179dde1e7
@ -42,37 +42,40 @@ int access(const char* path, int mode) {
|
||||
|
||||
/* Just hardcode the Linux User ID, we're not on linux anyway */
|
||||
/* Feasible cool addition: nn::act for this? */
|
||||
uid_t getuid() {
|
||||
return 1000;
|
||||
uid_t getuid(void)
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
/* Fake user info */
|
||||
/* Not thread safe, but avoids returning local variable, so... */
|
||||
struct passwd out;
|
||||
struct passwd* getpwuid(uid_t uid) {
|
||||
out.pw_name = "retroarch";
|
||||
out.pw_passwd = "Wait, what?";
|
||||
out.pw_uid = uid;
|
||||
out.pw_gid = 1000;
|
||||
out.pw_gecos = "retroarch";
|
||||
out.pw_dir = "sd:/";
|
||||
out.pw_shell = "/vol/system_slc/fw.img";
|
||||
struct passwd* getpwuid(uid_t uid)
|
||||
{
|
||||
out.pw_name = "retroarch";
|
||||
out.pw_passwd = "Wait, what?";
|
||||
out.pw_uid = uid;
|
||||
out.pw_gid = 1000;
|
||||
out.pw_gecos = "retroarch";
|
||||
out.pw_dir = "sd:/";
|
||||
out.pw_shell = "/vol/system_slc/fw.img";
|
||||
|
||||
return &out;
|
||||
return &out;
|
||||
}
|
||||
|
||||
/* Basic Cafe OS clock thingy. */
|
||||
int _gettimeofday_r(struct _reent *ptr,
|
||||
struct timeval* ptimeval,
|
||||
void* ptimezone) {
|
||||
|
||||
void* ptimezone)
|
||||
{
|
||||
OSTime cosTime;
|
||||
uint64_t cosSecs;
|
||||
uint32_t cosUSecs;
|
||||
time_t unixSecs;
|
||||
|
||||
/* We need somewhere to put our output */
|
||||
if (ptimeval == NULL) {
|
||||
if (ptimeval == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
@ -85,8 +88,8 @@ int _gettimeofday_r(struct _reent *ptr,
|
||||
cosUSecs = ticks_to_us(cosTime) - (cosSecs * 1000000);
|
||||
|
||||
/* Convert to Unix time, epoch 1970-01-01 00:00.
|
||||
Constant value is seconds between 1970 and 2000.
|
||||
time_t is 32bit here, so the Wii U is vulnerable to the 2038 problem. */
|
||||
Constant value is seconds between 1970 and 2000.
|
||||
time_t is 32bit here, so the Wii U is vulnerable to the 2038 problem. */
|
||||
unixSecs = cosSecs + 946684800;
|
||||
|
||||
ptimeval->tv_sec = unixSecs;
|
||||
@ -95,7 +98,8 @@ int _gettimeofday_r(struct _reent *ptr,
|
||||
}
|
||||
|
||||
/* POSIX clock in all its glory */
|
||||
int clock_gettime(clockid_t clk_id, struct timespec* tp) {
|
||||
int clock_gettime(clockid_t clk_id, struct timespec* tp)
|
||||
{
|
||||
struct timeval ptimeval = { 0 };
|
||||
int ret = 0;
|
||||
OSTime cosTime;
|
||||
@ -134,110 +138,128 @@ static const char *wiiu_iface_name = "eth0";
|
||||
*
|
||||
* returns NULL if any of the memory allocations fail.
|
||||
*/
|
||||
static struct ifaddrs *buildEmptyIfa() {
|
||||
struct ifaddrs *result = (struct ifaddrs *)malloc(sizeof(struct ifaddrs));
|
||||
if(result != NULL) {
|
||||
memset(result, 0, sizeof(struct ifaddrs));
|
||||
result->ifa_name = strdup(wiiu_iface_name);
|
||||
result->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
||||
result->ifa_netmask = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
||||
result->ifa_dstaddr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
||||
static struct ifaddrs *buildEmptyIfa(void)
|
||||
{
|
||||
struct ifaddrs *result = (struct ifaddrs *)malloc(sizeof(struct ifaddrs));
|
||||
if (result)
|
||||
{
|
||||
memset(result, 0, sizeof(struct ifaddrs));
|
||||
result->ifa_name = strdup(wiiu_iface_name);
|
||||
result->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
||||
result->ifa_netmask = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
||||
result->ifa_dstaddr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
||||
|
||||
if(!result->ifa_name || !result->ifa_addr || !result->ifa_netmask || !result->ifa_dstaddr)
|
||||
goto error;
|
||||
if (!result->ifa_name || !result->ifa_addr || !result->ifa_netmask || !result->ifa_dstaddr)
|
||||
goto error;
|
||||
|
||||
memset(result->ifa_addr, 0, sizeof(struct sockaddr_in));
|
||||
result->ifa_addr->sa_family = AF_INET;
|
||||
memset(result->ifa_netmask, 0, sizeof(struct sockaddr_in));
|
||||
result->ifa_netmask->sa_family = AF_INET;
|
||||
memset(result->ifa_dstaddr, 0, sizeof(struct sockaddr_in));
|
||||
result->ifa_dstaddr->sa_family = AF_INET;
|
||||
}
|
||||
memset(result->ifa_addr, 0, sizeof(struct sockaddr_in));
|
||||
result->ifa_addr->sa_family = AF_INET;
|
||||
memset(result->ifa_netmask, 0, sizeof(struct sockaddr_in));
|
||||
result->ifa_netmask->sa_family = AF_INET;
|
||||
memset(result->ifa_dstaddr, 0, sizeof(struct sockaddr_in));
|
||||
result->ifa_dstaddr->sa_family = AF_INET;
|
||||
}
|
||||
|
||||
return result;
|
||||
error:
|
||||
freeifaddrs(result);
|
||||
return NULL;
|
||||
return result;
|
||||
error:
|
||||
freeifaddrs(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int getAssignedAddress(struct sockaddr_in *sa) {
|
||||
if(sa == NULL)
|
||||
return -1;
|
||||
ACIpAddress addr;
|
||||
int result = ACGetAssignedAddress(&addr);
|
||||
if(result == 0)
|
||||
sa->sin_addr.s_addr = addr;
|
||||
static int getAssignedAddress(struct sockaddr_in *sa)
|
||||
{
|
||||
ACIpAddress addr;
|
||||
int result;
|
||||
if (!sa)
|
||||
return -1;
|
||||
result = ACGetAssignedAddress(&addr);
|
||||
if (result == 0)
|
||||
sa->sin_addr.s_addr = addr;
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int getAssignedSubnet(struct sockaddr_in *sa) {
|
||||
if(sa == NULL)
|
||||
return -1;
|
||||
static int getAssignedSubnet(struct sockaddr_in *sa)
|
||||
{
|
||||
ACIpAddress mask;
|
||||
int result;
|
||||
if (!sa)
|
||||
return -1;
|
||||
|
||||
ACIpAddress mask;
|
||||
int result = ACGetAssignedSubnet(&mask);
|
||||
if(result == 0)
|
||||
sa->sin_addr.s_addr = mask;
|
||||
result = ACGetAssignedSubnet(&mask);
|
||||
if (result == 0)
|
||||
sa->sin_addr.s_addr = mask;
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int getBroadcastAddress(struct sockaddr_in *sa, struct sockaddr_in *addr, struct sockaddr_in *mask) {
|
||||
if(!sa || !addr || !mask)
|
||||
return -1;
|
||||
static int getBroadcastAddress(struct sockaddr_in *sa, struct sockaddr_in *addr, struct sockaddr_in *mask)
|
||||
{
|
||||
if (!sa || !addr || !mask)
|
||||
return -1;
|
||||
|
||||
sa->sin_addr.s_addr = addr->sin_addr.s_addr | (~mask->sin_addr.s_addr);
|
||||
return 0;
|
||||
sa->sin_addr.s_addr = addr->sin_addr.s_addr | (~mask->sin_addr.s_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ifaddrs *getWiiUInterfaceAddressData(void) {
|
||||
struct ifaddrs *result = buildEmptyIfa();
|
||||
static struct ifaddrs *getWiiUInterfaceAddressData(void)
|
||||
{
|
||||
struct ifaddrs *result = buildEmptyIfa();
|
||||
|
||||
if(result != NULL) {
|
||||
if(getAssignedAddress((struct sockaddr_in *)result->ifa_addr) < 0 ||
|
||||
getAssignedSubnet((struct sockaddr_in *)result->ifa_netmask) < 0 ||
|
||||
getBroadcastAddress((struct sockaddr_in *)result->ifa_dstaddr,
|
||||
if (result)
|
||||
{
|
||||
if (getAssignedAddress((struct sockaddr_in *)result->ifa_addr) < 0 ||
|
||||
getAssignedSubnet((struct sockaddr_in *)result->ifa_netmask) < 0 ||
|
||||
getBroadcastAddress((struct sockaddr_in *)result->ifa_dstaddr,
|
||||
(struct sockaddr_in *)result->ifa_addr,
|
||||
(struct sockaddr_in *)result->ifa_netmask) < 0) {
|
||||
goto error;
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
|
||||
error:
|
||||
freeifaddrs(result);
|
||||
return NULL;
|
||||
error:
|
||||
freeifaddrs(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int getifaddrs(struct ifaddrs **ifap) {
|
||||
if(ifap == NULL) {
|
||||
return -1;
|
||||
}
|
||||
*ifap = getWiiUInterfaceAddressData();
|
||||
int getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
if (!ifap)
|
||||
return -1;
|
||||
*ifap = getWiiUInterfaceAddressData();
|
||||
|
||||
return (*ifap == NULL) ? -1 : 0;
|
||||
return (*ifap == NULL) ? -1 : 0;
|
||||
}
|
||||
|
||||
void freeifaddrs(struct ifaddrs *ifp) {
|
||||
if(ifp != NULL) {
|
||||
if(ifp->ifa_name) {
|
||||
free(ifp->ifa_name);
|
||||
ifp->ifa_name = NULL;
|
||||
}
|
||||
if(ifp->ifa_addr) {
|
||||
free(ifp->ifa_addr);
|
||||
ifp->ifa_addr = NULL;
|
||||
}
|
||||
if(ifp->ifa_netmask) {
|
||||
free(ifp->ifa_netmask);
|
||||
ifp->ifa_netmask = NULL;
|
||||
}
|
||||
if(ifp->ifa_dstaddr) {
|
||||
free(ifp->ifa_dstaddr);
|
||||
ifp->ifa_dstaddr = NULL;
|
||||
}
|
||||
free(ifp);
|
||||
void freeifaddrs(struct ifaddrs *ifp)
|
||||
{
|
||||
if (ifp)
|
||||
{
|
||||
if (ifp->ifa_name)
|
||||
{
|
||||
free(ifp->ifa_name);
|
||||
ifp->ifa_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ifp->ifa_addr)
|
||||
{
|
||||
free(ifp->ifa_addr);
|
||||
ifp->ifa_addr = NULL;
|
||||
}
|
||||
|
||||
if (ifp->ifa_netmask)
|
||||
{
|
||||
free(ifp->ifa_netmask);
|
||||
ifp->ifa_netmask = NULL;
|
||||
}
|
||||
|
||||
if (ifp->ifa_dstaddr)
|
||||
{
|
||||
free(ifp->ifa_dstaddr);
|
||||
ifp->ifa_dstaddr = NULL;
|
||||
}
|
||||
free(ifp);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user