Fix wrong struct used for timeval. Newlib expects 64bits for seconds and PSP expects 32

This commit is contained in:
Francisco Javier Trujillo Mata
2021-11-23 01:31:06 +01:00
parent 6192ee8bdf
commit 98bed321f1
4 changed files with 33 additions and 4 deletions

View File

@@ -703,7 +703,18 @@ void * _sbrk(ptrdiff_t incr)
#ifdef F__gettimeofday
int _gettimeofday(struct timeval *tp, struct timezone *tzp)
{
return __set_errno(sceKernelLibcGettimeofday(tp, tzp));
int ret;
struct SceKernelTimeval pspTimeval;
ret = __set_errno(sceKernelLibcGettimeofday(&pspTimeval, tzp));
if (ret < 0)
return ret;
/* Return the actual time since epoch */
tp->tv_sec = pspTimeval.tv_sec;
tp->tv_usec = pspTimeval.tv_usec;
return 0;
}
#endif

View File

@@ -31,7 +31,7 @@ static int __poll_select(int n, fd_set *readfds, fd_set *writefds, fd_set *excep
fd_set ready_readfds, ready_writefds, ready_exceptfds;
fd_set scereadfds, scewritefds;
SceKernelMppInfo info;
struct timeval scetv;
struct SceNetInetTimeval scetv;
FD_ZERO(&ready_readfds);
FD_ZERO(&ready_writefds);

View File

@@ -18,8 +18,17 @@
extern "C" {
#endif
/**
* This struct is needed because tv_sec size is different from what newlib expect
* Newlib expects 64bits for seconds and PSP expects 32bits
*/
struct SceNetInetTimeval {
uint32_t tv_sec;
uint32_t tv_usec;
};
int sceNetInetInit(void);
int sceNetInetSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int sceNetInetSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct SceNetInetTimeval *timeout);
int sceNetInetTerm(void);
int sceNetInetGetErrno(void);

View File

@@ -30,6 +30,15 @@ extern "C" {
#include <sys/time.h>
/**
* This struct is needed because tv_sec size is different from what newlib expect
* Newlib expects 64bits for seconds and PSP expects 32bits
*/
typedef struct SceKernelTimeval {
uint32_t tv_sec;
uint32_t tv_usec;
} SceKernelTimeval;
/**
* Get the time in seconds since the epoc (1st Jan 1970)
*
@@ -44,7 +53,7 @@ clock_t sceKernelLibcClock(void);
/**
* Get the current time of time and time zone information
*/
int sceKernelLibcGettimeofday(struct timeval *tp, struct timezone *tzp);
int sceKernelLibcGettimeofday(struct SceKernelTimeval *tp, struct timezone *tzp);
/**
* Write back the data cache to memory