mirror of
https://github.com/Maschell/libutils.git
synced 2024-11-06 05:05:08 +01:00
Fix filetypes
This commit is contained in:
parent
2a5f6aaa82
commit
f28e502af3
@ -19,13 +19,13 @@ public:
|
|||||||
|
|
||||||
CFile();
|
CFile();
|
||||||
CFile(const std::string & filepath, eOpenTypes mode);
|
CFile(const std::string & filepath, eOpenTypes mode);
|
||||||
CFile(const u8 * memory, s32 memsize);
|
CFile(const uint8_t * memory, int32_t memsize);
|
||||||
virtual ~CFile();
|
virtual ~CFile();
|
||||||
|
|
||||||
s32 open(const std::string & filepath, eOpenTypes mode);
|
int32_t open(const std::string & filepath, eOpenTypes mode);
|
||||||
s32 open(const u8 * memory, s32 memsize);
|
int32_t open(const uint8_t * memory, int32_t memsize);
|
||||||
|
|
||||||
bool isOpen() const {
|
BOOL isOpen() const {
|
||||||
if(iFd >= 0)
|
if(iFd >= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -37,14 +37,14 @@ public:
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
s32 read(u8 * ptr, size_t size);
|
int32_t read(uint8_t * ptr, size_t size);
|
||||||
s32 write(const u8 * ptr, size_t size);
|
int32_t write(const uint8_t * ptr, size_t size);
|
||||||
s32 fwrite(const char *format, ...);
|
int32_t fwrite(const char *format, ...);
|
||||||
s32 seek(long int offset, s32 origin);
|
int32_t seek(long int offset, int32_t origin);
|
||||||
u64 tell() {
|
uint64_t tell() {
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
u64 size() {
|
uint64_t size() {
|
||||||
return filesize;
|
return filesize;
|
||||||
};
|
};
|
||||||
void rewind() {
|
void rewind() {
|
||||||
@ -52,10 +52,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
s32 iFd;
|
int32_t iFd;
|
||||||
const u8 * mem_file;
|
const uint8_t * mem_file;
|
||||||
u64 filesize;
|
uint64_t filesize;
|
||||||
u64 pos;
|
uint64_t pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char * FilePath;
|
char * FilePath;
|
||||||
bool isDir;
|
BOOL isDir;
|
||||||
} DirEntry;
|
} DirEntry;
|
||||||
|
|
||||||
class DirList {
|
class DirList {
|
||||||
@ -43,39 +43,39 @@ public:
|
|||||||
//!\param path Path from where to load the filelist of all files
|
//!\param path Path from where to load the filelist of all files
|
||||||
//!\param filter A fileext that needs to be filtered
|
//!\param filter A fileext that needs to be filtered
|
||||||
//!\param flags search/filter flags from the enum
|
//!\param flags search/filter flags from the enum
|
||||||
DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 maxDepth = 0xffffffff);
|
DirList(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
virtual ~DirList();
|
virtual ~DirList();
|
||||||
//! Load all the files from a directory
|
//! Load all the files from a directory
|
||||||
bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 maxDepth = 0xffffffff);
|
BOOL LoadPath(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||||
//! Get a filename of the list
|
//! Get a filename of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char * GetFilename(s32 index) const;
|
const char * GetFilename(int32_t index) const;
|
||||||
//! Get the a filepath of the list
|
//! Get the a filepath of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char *GetFilepath(s32 index) const {
|
const char *GetFilepath(int32_t index) const {
|
||||||
if (!valid(index)) return "";
|
if (!valid(index)) return "";
|
||||||
else return FileInfo[index].FilePath;
|
else return FileInfo[index].FilePath;
|
||||||
}
|
}
|
||||||
//! Get the a filesize of the list
|
//! Get the a filesize of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
u64 GetFilesize(s32 index) const;
|
uint64_t GetFilesize(int32_t index) const;
|
||||||
//! Is index a dir or a file
|
//! Is index a dir or a file
|
||||||
//!\param list index
|
//!\param list index
|
||||||
bool IsDir(s32 index) const {
|
BOOL IsDir(int32_t index) const {
|
||||||
if(!valid(index)) return false;
|
if(!valid(index)) return false;
|
||||||
return FileInfo[index].isDir;
|
return FileInfo[index].isDir;
|
||||||
};
|
};
|
||||||
//! Get the filecount of the whole list
|
//! Get the filecount of the whole list
|
||||||
s32 GetFilecount() const {
|
int32_t GetFilecount() const {
|
||||||
return FileInfo.size();
|
return FileInfo.size();
|
||||||
};
|
};
|
||||||
//! Sort list by filepath
|
//! Sort list by filepath
|
||||||
void SortList();
|
void SortList();
|
||||||
//! Custom sort command for custom sort functions definitions
|
//! Custom sort command for custom sort functions definitions
|
||||||
void SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
||||||
//! Get the index of the specified filename
|
//! Get the index of the specified filename
|
||||||
s32 GetFileIndex(const char *filename) const;
|
int32_t GetFileIndex(const char *filename) const;
|
||||||
//! Enum for search/filter flags
|
//! Enum for search/filter flags
|
||||||
enum {
|
enum {
|
||||||
Files = 0x01,
|
Files = 0x01,
|
||||||
@ -84,18 +84,18 @@ public:
|
|||||||
};
|
};
|
||||||
protected:
|
protected:
|
||||||
// Internal parser
|
// Internal parser
|
||||||
bool InternalLoadPath(std::string &path);
|
BOOL InternalLoadPath(std::string &path);
|
||||||
//!Add a list entrie
|
//!Add a list entrie
|
||||||
void AddEntrie(const std::string &filepath, const char * filename, bool isDir);
|
void AddEntrie(const std::string &filepath, const char * filename, BOOL isDir);
|
||||||
//! Clear the list
|
//! Clear the list
|
||||||
void ClearList();
|
void ClearList();
|
||||||
//! Check if valid pos is requested
|
//! Check if valid pos is requested
|
||||||
inline bool valid(u32 pos) const {
|
inline BOOL valid(uint32_t pos) const {
|
||||||
return (pos < FileInfo.size());
|
return (pos < FileInfo.size());
|
||||||
};
|
};
|
||||||
|
|
||||||
u32 Flags;
|
uint32_t Flags;
|
||||||
u32 Depth;
|
uint32_t Depth;
|
||||||
const char *Filter;
|
const char *Filter;
|
||||||
std::vector<DirEntry> FileInfo;
|
std::vector<DirEntry> FileInfo;
|
||||||
};
|
};
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
class FSUtils {
|
class FSUtils {
|
||||||
public:
|
public:
|
||||||
static s32 LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size);
|
static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);
|
||||||
|
|
||||||
//! todo: C++ class
|
//! todo: C++ class
|
||||||
static s32 CreateSubfolder(const char * fullpath);
|
static int32_t CreateSubfolder(const char * fullpath);
|
||||||
static s32 CheckFile(const char * filepath);
|
static int32_t CheckFile(const char * filepath);
|
||||||
static bool saveBufferToFile(const char * path, void * buffer, u32 size);
|
static BOOL saveBufferToFile(const char * path, void * buffer, uint32_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __FS_UTILS_H_
|
#endif // __FS_UTILS_H_
|
||||||
|
@ -43,12 +43,12 @@
|
|||||||
|
|
||||||
typedef uint32_t sec_t;
|
typedef uint32_t sec_t;
|
||||||
|
|
||||||
typedef bool (* FN_MEDIUM_STARTUP)(void) ;
|
typedef BOOL (* FN_MEDIUM_STARTUP)(void) ;
|
||||||
typedef bool (* FN_MEDIUM_ISINSERTED)(void) ;
|
typedef BOOL (* FN_MEDIUM_ISINSERTED)(void) ;
|
||||||
typedef bool (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ;
|
typedef BOOL (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ;
|
||||||
typedef bool (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ;
|
typedef BOOL (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ;
|
||||||
typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ;
|
typedef BOOL (* FN_MEDIUM_CLEARSTATUS)(void) ;
|
||||||
typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ;
|
typedef BOOL (* FN_MEDIUM_SHUTDOWN)(void) ;
|
||||||
|
|
||||||
struct DISC_INTERFACE_STRUCT {
|
struct DISC_INTERFACE_STRUCT {
|
||||||
unsigned long ioType ;
|
unsigned long ioType ;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#ifndef _GETTEXT_H_
|
#ifndef _GETTEXT_H_
|
||||||
#define _GETTEXT_H_
|
#define _GETTEXT_H_
|
||||||
|
|
||||||
|
#include <wut_types.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -25,7 +27,7 @@ extern "C"
|
|||||||
#define tr(s) gettext(s)
|
#define tr(s) gettext(s)
|
||||||
#define trNOOP(s) s
|
#define trNOOP(s) s
|
||||||
|
|
||||||
bool gettextLoadLanguage(const char* langFile);
|
BOOL gettextLoadLanguage(const char* langFile);
|
||||||
void gettextCleanUp(void);
|
void gettextCleanUp(void);
|
||||||
/*
|
/*
|
||||||
* input msg = a text in ASCII
|
* input msg = a text in ASCII
|
||||||
|
@ -7,12 +7,12 @@ extern "C" {
|
|||||||
|
|
||||||
#include <wut_types.h>
|
#include <wut_types.h>
|
||||||
|
|
||||||
s32 recvwait(s32 sock, void *buffer, s32 len);
|
int32_t recvwait(int32_t sock, void *buffer, int32_t len);
|
||||||
u8 recvbyte(s32 sock);
|
uint8_t recvbyte(int32_t sock);
|
||||||
u32 recvword(s32 sock);
|
uint32_t recvword(int32_t sock);
|
||||||
s32 checkbyte(s32 sock);
|
int32_t checkbyte(int32_t sock);
|
||||||
s32 sendwait(s32 sock, const void *buffer, s32 len);
|
int32_t sendwait(int32_t sock, const void *buffer, int32_t len);
|
||||||
s32 sendbyte(s32 sock, unsigned char byte);
|
int32_t sendbyte(int32_t sock, unsigned char byte);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -43,14 +43,14 @@ public:
|
|||||||
deleterInstance->deleteElements.push(e);
|
deleterInstance->deleteElements.push(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool deleteListEmpty() {
|
static BOOL deleteListEmpty() {
|
||||||
if(!deleterInstance) {
|
if(!deleterInstance) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return deleterInstance->deleteElements.empty();
|
return deleterInstance->deleteElements.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool realListEmpty() {
|
static BOOL realListEmpty() {
|
||||||
if(!deleterInstance) {
|
if(!deleterInstance) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ private:
|
|||||||
|
|
||||||
void executeThread(void);
|
void executeThread(void);
|
||||||
|
|
||||||
bool exitApplication;
|
BOOL exitApplication;
|
||||||
std::queue<AsyncDeleter::Element *> deleteElements;
|
std::queue<AsyncDeleter::Element *> deleteElements;
|
||||||
std::queue<AsyncDeleter::Element *> realDeleteElements;
|
std::queue<AsyncDeleter::Element *> realDeleteElements;
|
||||||
CMutex deleteMutex;
|
CMutex deleteMutex;
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
if(pMutex)
|
if(pMutex)
|
||||||
OSUnlockMutex(pMutex);
|
OSUnlockMutex(pMutex);
|
||||||
}
|
}
|
||||||
bool tryLock(void) {
|
BOOL tryLock(void) {
|
||||||
if(!pMutex)
|
if(!pMutex)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
typedef void (* Callback)(CThread *thread, void *arg);
|
typedef void (* Callback)(CThread *thread, void *arg);
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
CThread(s32 iAttr, s32 iPriority = 16, s32 iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||||
: pThread(NULL)
|
: pThread(NULL)
|
||||||
, pThreadStack(NULL)
|
, pThreadStack(NULL)
|
||||||
, pCallback(callback)
|
, pCallback(callback)
|
||||||
@ -38,7 +38,7 @@ public:
|
|||||||
//! allocate the thread
|
//! allocate the thread
|
||||||
pThread = (OSThread*)memalign(8, sizeof(OSThread));
|
pThread = (OSThread*)memalign(8, sizeof(OSThread));
|
||||||
//! allocate the stack
|
//! allocate the stack
|
||||||
pThreadStack = (u8 *) memalign(0x20, iStackSize);
|
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
|
||||||
//! create the thread
|
//! create the thread
|
||||||
if(pThread && pThreadStack)
|
if(pThread && pThreadStack)
|
||||||
OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
|
OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
|
||||||
@ -49,7 +49,7 @@ public:
|
|||||||
shutdownThread();
|
shutdownThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
static CThread *create(CThread::Callback callback, void *callbackArg, s32 iAttr = eAttributeNone, s32 iPriority = 16, s32 iStackSize = 0x8000) {
|
static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
|
||||||
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
|
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,17 +77,17 @@ public:
|
|||||||
if(pThread) OSSetThreadPriority(pThread, prio);
|
if(pThread) OSSetThreadPriority(pThread, prio);
|
||||||
}
|
}
|
||||||
//! Check if thread is suspended
|
//! Check if thread is suspended
|
||||||
virtual bool isThreadSuspended(void) const {
|
virtual BOOL isThreadSuspended(void) const {
|
||||||
if(pThread) return OSIsThreadSuspended(pThread);
|
if(pThread) return OSIsThreadSuspended(pThread);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//! Check if thread is terminated
|
//! Check if thread is terminated
|
||||||
virtual bool isThreadTerminated(void) const {
|
virtual BOOL isThreadTerminated(void) const {
|
||||||
if(pThread) return OSIsThreadTerminated(pThread);
|
if(pThread) return OSIsThreadTerminated(pThread);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//! Check if thread is running
|
//! Check if thread is running
|
||||||
virtual bool isThreadRunning(void) const {
|
virtual BOOL isThreadRunning(void) const {
|
||||||
return !isThreadSuspended() && !isThreadRunning();
|
return !isThreadSuspended() && !isThreadRunning();
|
||||||
}
|
}
|
||||||
//! Shutdown thread
|
//! Shutdown thread
|
||||||
@ -125,7 +125,7 @@ private:
|
|||||||
}
|
}
|
||||||
int iAttributes;
|
int iAttributes;
|
||||||
OSThread *pThread;
|
OSThread *pThread;
|
||||||
u8 *pThreadStack;
|
uint8_t *pThreadStack;
|
||||||
Callback pCallback;
|
Callback pCallback;
|
||||||
void *pCallbackArg;
|
void *pCallbackArg;
|
||||||
};
|
};
|
||||||
|
@ -32,16 +32,16 @@
|
|||||||
|
|
||||||
class StringTools{
|
class StringTools{
|
||||||
public:
|
public:
|
||||||
static bool EndsWith(const std::string& a, const std::string& b);
|
static BOOL EndsWith(const std::string& a, const std::string& b);
|
||||||
static const char * byte_to_binary(s32 x);
|
static const char * byte_to_binary(int32_t x);
|
||||||
static std::string removeCharFromString(std::string& input,char toBeRemoved);
|
static std::string removeCharFromString(std::string& input,char toBeRemoved);
|
||||||
static const char * fmt(const char * format, ...);
|
static const char * fmt(const char * format, ...);
|
||||||
static const wchar_t * wfmt(const char * format, ...);
|
static const wchar_t * wfmt(const char * format, ...);
|
||||||
static s32 strprintf(std::string &str, const char * format, ...);
|
static int32_t strprintf(std::string &str, const char * format, ...);
|
||||||
static std::string strfmt(const char * format, ...);
|
static std::string strfmt(const char * format, ...);
|
||||||
static bool char2wchar_t(const char * src, wchar_t * dest);
|
static BOOL char2wchar_t(const char * src, wchar_t * dest);
|
||||||
static s32 strtokcmp(const char * string, const char * compare, const char * separator);
|
static int32_t strtokcmp(const char * string, const char * compare, const char * separator);
|
||||||
static s32 strextcmp(const char * string, const char * extension, char seperator);
|
static int32_t strextcmp(const char * string, const char * extension, char seperator);
|
||||||
|
|
||||||
static const char * FullpathToFilename(const char *path){
|
static const char * FullpathToFilename(const char *path){
|
||||||
if(!path) return path;
|
if(!path) return path;
|
||||||
@ -61,10 +61,10 @@ class StringTools{
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void RemoveDoubleSlashs(std::string &str){
|
static void RemoveDoubleSlashs(std::string &str){
|
||||||
u32 length = str.size();
|
uint32_t length = str.size();
|
||||||
|
|
||||||
//! clear path of double slashes
|
//! clear path of double slashes
|
||||||
for(u32 i = 1; i < length; ++i)
|
for(uint32_t i = 1; i < length; ++i)
|
||||||
{
|
{
|
||||||
if(str[i-1] == '/' && str[i] == '/')
|
if(str[i-1] == '/' && str[i] == '/')
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _TCPSERVER_H_
|
#ifndef _TCPSERVER_H_
|
||||||
#define _TCPSERVER_H_
|
#define _TCPSERVER_H_
|
||||||
|
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
|
||||||
#include <nsysnet/socket.h>
|
#include <nsysnet/socket.h>
|
||||||
#include <system/CThread.h>
|
#include <system/CThread.h>
|
||||||
@ -12,22 +12,22 @@
|
|||||||
|
|
||||||
class TCPServer {
|
class TCPServer {
|
||||||
public:
|
public:
|
||||||
TCPServer(s32 port, s32 priority);
|
TCPServer(int32_t port, int32_t priority);
|
||||||
virtual ~TCPServer();
|
virtual ~TCPServer();
|
||||||
|
|
||||||
bool isConnected() {
|
BOOL isConnected() {
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
bool shouldExit() {
|
BOOL shouldExit() {
|
||||||
return (exitThread == 1);
|
return (exitThread == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 getClientFD() {
|
int32_t getClientFD() {
|
||||||
return clientfd;
|
return clientfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 getSocketFD() {
|
int32_t getSocketFD() {
|
||||||
return sockfd;
|
return sockfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ private:
|
|||||||
static void DoTCPThread(CThread *thread, void *arg);
|
static void DoTCPThread(CThread *thread, void *arg);
|
||||||
virtual void DoTCPThreadInternal();
|
virtual void DoTCPThreadInternal();
|
||||||
|
|
||||||
virtual bool acceptConnection() = 0;
|
virtual BOOL acceptConnection() = 0;
|
||||||
|
|
||||||
virtual void onConnectionClosed(){
|
virtual void onConnectionClosed(){
|
||||||
DEBUG_FUNCTION_LINE("Default onConnectionClosed \n");
|
DEBUG_FUNCTION_LINE("Default onConnectionClosed \n");
|
||||||
@ -50,16 +50,16 @@ private:
|
|||||||
/**
|
/**
|
||||||
Called when a connection has be accepted.
|
Called when a connection has be accepted.
|
||||||
**/
|
**/
|
||||||
virtual bool whileLoop() = 0;
|
virtual BOOL whileLoop() = 0;
|
||||||
|
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
volatile s32 sockfd = -1;
|
volatile int32_t sockfd = -1;
|
||||||
volatile s32 clientfd = -1;
|
volatile int32_t clientfd = -1;
|
||||||
|
|
||||||
s32 port = 0;
|
int32_t port = 0;
|
||||||
volatile bool connected = false;
|
volatile BOOL connected = false;
|
||||||
|
|
||||||
volatile s32 exitThread = 0;
|
volatile int32_t exitThread = 0;
|
||||||
CThread *pThread = NULL;
|
CThread *pThread = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@ extern "C" {
|
|||||||
|
|
||||||
unsigned int elf_get_section(unsigned char *data, const char *name, unsigned int * size, unsigned int * addr, int fail_on_not_found);
|
unsigned int elf_get_section(unsigned char *data, const char *name, unsigned int * size, unsigned int * addr, int fail_on_not_found);
|
||||||
|
|
||||||
bool elf_copy_section(unsigned char * elf_data, const char * section_name, bool errorOnFailure);
|
BOOL elf_copy_section(unsigned char * elf_data, const char * section_name, BOOL errorOnFailure);
|
||||||
|
|
||||||
u32 elf_copy_common_sections(unsigned char * elf_data);
|
uint32_t elf_copy_common_sections(unsigned char * elf_data);
|
||||||
|
|
||||||
u32 elf_get_entry_addr(unsigned char * elf_data);
|
uint32_t elf_get_entry_addr(unsigned char * elf_data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ CFile::CFile(const std::string & filepath, eOpenTypes mode) {
|
|||||||
this->open(filepath, mode);
|
this->open(filepath, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const u8 * mem, s32 size) {
|
CFile::CFile(const uint8_t * mem, int32_t size) {
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
this->open(mem, size);
|
this->open(mem, size);
|
||||||
}
|
}
|
||||||
@ -25,10 +25,10 @@ CFile::~CFile() {
|
|||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CFile::open(const std::string & filepath, eOpenTypes mode) {
|
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
||||||
this->close();
|
this->close();
|
||||||
|
|
||||||
s32 openMode = 0;
|
int32_t openMode = 0;
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
default:
|
default:
|
||||||
@ -61,7 +61,7 @@ s32 CFile::open(const std::string & filepath, eOpenTypes mode) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CFile::open(const u8 * mem, s32 size) {
|
int32_t CFile::open(const uint8_t * mem, int32_t size) {
|
||||||
this->close();
|
this->close();
|
||||||
|
|
||||||
mem_file = mem;
|
mem_file = mem;
|
||||||
@ -80,17 +80,17 @@ void CFile::close() {
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CFile::read(u8 * ptr, size_t size) {
|
int32_t CFile::read(uint8_t * ptr, size_t size) {
|
||||||
if(iFd >= 0) {
|
if(iFd >= 0) {
|
||||||
s32 ret = ::read(iFd, ptr,size);
|
int32_t ret = ::read(iFd, ptr,size);
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
pos += ret;
|
pos += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 readsize = size;
|
int32_t readsize = size;
|
||||||
|
|
||||||
if(readsize > (s64) (filesize-pos))
|
if(readsize > (int64_t) (filesize-pos))
|
||||||
readsize = filesize-pos;
|
readsize = filesize-pos;
|
||||||
|
|
||||||
if(readsize <= 0)
|
if(readsize <= 0)
|
||||||
@ -105,11 +105,11 @@ s32 CFile::read(u8 * ptr, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CFile::write(const u8 * ptr, size_t size) {
|
int32_t CFile::write(const uint8_t * ptr, size_t size) {
|
||||||
if(iFd >= 0) {
|
if(iFd >= 0) {
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
while(done < size) {
|
while(done < size) {
|
||||||
s32 ret = ::write(iFd, ptr, size - done);
|
int32_t ret = ::write(iFd, ptr, size - done);
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -123,9 +123,9 @@ s32 CFile::write(const u8 * ptr, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CFile::seek(long int offset, s32 origin) {
|
int32_t CFile::seek(long int offset, int32_t origin) {
|
||||||
s32 ret = 0;
|
int32_t ret = 0;
|
||||||
s64 newPos = pos;
|
int64_t newPos = pos;
|
||||||
|
|
||||||
if(origin == SEEK_SET) {
|
if(origin == SEEK_SET) {
|
||||||
newPos = offset;
|
newPos = offset;
|
||||||
@ -153,15 +153,15 @@ s32 CFile::seek(long int offset, s32 origin) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CFile::fwrite(const char *format, ...) {
|
int32_t CFile::fwrite(const char *format, ...) {
|
||||||
char tmp[512];
|
char tmp[512];
|
||||||
tmp[0] = 0;
|
tmp[0] = 0;
|
||||||
s32 result = -1;
|
int32_t result = -1;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vsprintf(tmp, format, va) >= 0)) {
|
if((vsprintf(tmp, format, va) >= 0)) {
|
||||||
result = this->write((u8 *)tmp, strlen(tmp));
|
result = this->write((uint8_t *)tmp, strlen(tmp));
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ DirList::DirList() {
|
|||||||
Depth = 0;
|
Depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirList::DirList(const std::string & path, const char *filter, u32 flags, u32 maxDepth) {
|
DirList::DirList(const std::string & path, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
||||||
this->LoadPath(path, filter, flags, maxDepth);
|
this->LoadPath(path, filter, flags, maxDepth);
|
||||||
this->SortList();
|
this->SortList();
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ DirList::~DirList() {
|
|||||||
ClearList();
|
ClearList();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags, u32 maxDepth) {
|
BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
||||||
if(folder.empty()) return false;
|
if(folder.empty()) return false;
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
@ -59,7 +59,7 @@ bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags
|
|||||||
Depth = maxDepth;
|
Depth = maxDepth;
|
||||||
|
|
||||||
std::string folderpath(folder);
|
std::string folderpath(folder);
|
||||||
u32 length = folderpath.size();
|
uint32_t length = folderpath.size();
|
||||||
|
|
||||||
//! clear path of double slashes
|
//! clear path of double slashes
|
||||||
StringTools::RemoveDoubleSlashs(folderpath);
|
StringTools::RemoveDoubleSlashs(folderpath);
|
||||||
@ -76,7 +76,7 @@ bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags
|
|||||||
return InternalLoadPath(folderpath);
|
return InternalLoadPath(folderpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirList::InternalLoadPath(std::string &folderpath) {
|
BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
||||||
if(folderpath.size() < 3)
|
if(folderpath.size() < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ bool DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
while ((dirent = readdir(dir)) != 0) {
|
while ((dirent = readdir(dir)) != 0) {
|
||||||
bool isDir = dirent->d_type & DT_DIR;
|
BOOL isDir = dirent->d_type & DT_DIR;
|
||||||
const char *filename = dirent->d_name;
|
const char *filename = dirent->d_name;
|
||||||
|
|
||||||
if(isDir) {
|
if(isDir) {
|
||||||
@ -96,7 +96,7 @@ bool DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if((Flags & CheckSubfolders) && (Depth > 0)) {
|
if((Flags & CheckSubfolders) && (Depth > 0)) {
|
||||||
s32 length = folderpath.size();
|
int32_t length = folderpath.size();
|
||||||
if(length > 2 && folderpath[length-1] != '/') {
|
if(length > 2 && folderpath[length-1] != '/') {
|
||||||
folderpath += '/';
|
folderpath += '/';
|
||||||
}
|
}
|
||||||
@ -130,11 +130,11 @@ bool DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::AddEntrie(const std::string &filepath, const char * filename, bool isDir) {
|
void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL isDir) {
|
||||||
if(!filename)
|
if(!filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
s32 pos = FileInfo.size();
|
int32_t pos = FileInfo.size();
|
||||||
|
|
||||||
FileInfo.resize(pos+1);
|
FileInfo.resize(pos+1);
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DirList::ClearList() {
|
void DirList::ClearList() {
|
||||||
for(u32 i = 0; i < FileInfo.size(); ++i) {
|
for(uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||||
if(FileInfo[i].FilePath) {
|
if(FileInfo[i].FilePath) {
|
||||||
free(FileInfo[i].FilePath);
|
free(FileInfo[i].FilePath);
|
||||||
FileInfo[i].FilePath = NULL;
|
FileInfo[i].FilePath = NULL;
|
||||||
@ -160,14 +160,14 @@ void DirList::ClearList() {
|
|||||||
std::vector<DirEntry>().swap(FileInfo);
|
std::vector<DirEntry>().swap(FileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * DirList::GetFilename(s32 ind) const {
|
const char * DirList::GetFilename(int32_t ind) const {
|
||||||
if (!valid(ind))
|
if (!valid(ind))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
|
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SortCallback(const DirEntry & f1, const DirEntry & f2) {
|
static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) {
|
||||||
if(f1.isDir && !(f2.isDir)) return true;
|
if(f1.isDir && !(f2.isDir)) return true;
|
||||||
if(!(f1.isDir) && f2.isDir) return false;
|
if(!(f1.isDir) && f2.isDir) return false;
|
||||||
|
|
||||||
@ -185,12 +185,12 @@ void DirList::SortList() {
|
|||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
|
void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
|
||||||
if(FileInfo.size() > 1)
|
if(FileInfo.size() > 1)
|
||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 DirList::GetFilesize(s32 index) const {
|
uint64_t DirList::GetFilesize(int32_t index) const {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *path = GetFilepath(index);
|
const char *path = GetFilepath(index);
|
||||||
|
|
||||||
@ -200,11 +200,11 @@ u64 DirList::GetFilesize(s32 index) const {
|
|||||||
return st.st_size;
|
return st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 DirList::GetFileIndex(const char *filename) const {
|
int32_t DirList::GetFileIndex(const char *filename) const {
|
||||||
if(!filename)
|
if(!filename)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (u32 i = 0; i < FileInfo.size(); ++i) {
|
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||||
if (strcasecmp(GetFilename(i), filename) == 0)
|
if (strcasecmp(GetFilename(i), filename) == 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -7,28 +7,28 @@
|
|||||||
#include <fs/CFile.hpp>
|
#include <fs/CFile.hpp>
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
|
|
||||||
s32 FSUtils::LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size) {
|
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
|
||||||
//! always initialze input
|
//! always initialze input
|
||||||
*inbuffer = NULL;
|
*inbuffer = NULL;
|
||||||
if(size)
|
if(size)
|
||||||
*size = 0;
|
*size = 0;
|
||||||
|
|
||||||
s32 iFd = open(filepath, O_RDONLY);
|
int32_t iFd = open(filepath, O_RDONLY);
|
||||||
if (iFd < 0)
|
if (iFd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
u32 filesize = lseek(iFd, 0, SEEK_END);
|
uint32_t filesize = lseek(iFd, 0, SEEK_END);
|
||||||
lseek(iFd, 0, SEEK_SET);
|
lseek(iFd, 0, SEEK_SET);
|
||||||
|
|
||||||
u8 *buffer = (u8 *) malloc(filesize);
|
uint8_t *buffer = (uint8_t *) malloc(filesize);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
close(iFd);
|
close(iFd);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 blocksize = 0x4000;
|
uint32_t blocksize = 0x4000;
|
||||||
u32 done = 0;
|
uint32_t done = 0;
|
||||||
s32 readBytes = 0;
|
int32_t readBytes = 0;
|
||||||
|
|
||||||
while(done < filesize) {
|
while(done < filesize) {
|
||||||
if(done + blocksize > filesize) {
|
if(done + blocksize > filesize) {
|
||||||
@ -58,7 +58,7 @@ s32 FSUtils::LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size) {
|
|||||||
return filesize;
|
return filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 FSUtils::CheckFile(const char * filepath) {
|
int32_t FSUtils::CheckFile(const char * filepath) {
|
||||||
if(!filepath)
|
if(!filepath)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -81,16 +81,16 @@ s32 FSUtils::CheckFile(const char * filepath) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 FSUtils::CreateSubfolder(const char * fullpath) {
|
int32_t FSUtils::CreateSubfolder(const char * fullpath) {
|
||||||
if(!fullpath)
|
if(!fullpath)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
s32 result = 0;
|
int32_t result = 0;
|
||||||
|
|
||||||
char dirnoslash[strlen(fullpath)+1];
|
char dirnoslash[strlen(fullpath)+1];
|
||||||
strcpy(dirnoslash, fullpath);
|
strcpy(dirnoslash, fullpath);
|
||||||
|
|
||||||
s32 pos = strlen(dirnoslash)-1;
|
int32_t pos = strlen(dirnoslash)-1;
|
||||||
while(dirnoslash[pos] == '/') {
|
while(dirnoslash[pos] == '/') {
|
||||||
dirnoslash[pos] = '\0';
|
dirnoslash[pos] = '\0';
|
||||||
pos--;
|
pos--;
|
||||||
@ -129,15 +129,15 @@ s32 FSUtils::CreateSubfolder(const char * fullpath) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FSUtils::saveBufferToFile(const char * path, void * buffer, u32 size) {
|
BOOL FSUtils::saveBufferToFile(const char * path, void * buffer, uint32_t size) {
|
||||||
s32 res = open(path, O_CREAT | O_TRUNC | O_WRONLY);
|
int32_t res = open(path, O_CREAT | O_TRUNC | O_WRONLY);
|
||||||
close(res);
|
close(res);
|
||||||
CFile file(path, CFile::WriteOnly);
|
CFile file(path, CFile::WriteOnly);
|
||||||
if (!file.isOpen()) {
|
if (!file.isOpen()) {
|
||||||
DEBUG_FUNCTION_LINE("Failed to open %s\n",path);
|
DEBUG_FUNCTION_LINE("Failed to open %s\n",path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
file.write((const u8*) buffer,size);
|
file.write((const uint8_t*) buffer,size);
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ char* strdup (const char* s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _MSG {
|
typedef struct _MSG {
|
||||||
u32 id;
|
uint32_t id;
|
||||||
char* msgstr;
|
char* msgstr;
|
||||||
struct _MSG *next;
|
struct _MSG *next;
|
||||||
} MSG;
|
} MSG;
|
||||||
@ -50,16 +50,16 @@ static MSG *baseMSG = 0;
|
|||||||
/* Defines the so called `hashpjw' function by P.J. Weinberger
|
/* Defines the so called `hashpjw' function by P.J. Weinberger
|
||||||
[see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
|
[see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
|
||||||
1986, 1987 Bell Telephone Laboratories, Inc.] */
|
1986, 1987 Bell Telephone Laboratories, Inc.] */
|
||||||
static inline u32 hash_string(const char *str_param) {
|
static inline uint32_t hash_string(const char *str_param) {
|
||||||
u32 hval, g;
|
uint32_t hval, g;
|
||||||
const char *str = str_param;
|
const char *str = str_param;
|
||||||
|
|
||||||
/* Compute the hash value for the given string. */
|
/* Compute the hash value for the given string. */
|
||||||
hval = 0;
|
hval = 0;
|
||||||
while (*str != '\0') {
|
while (*str != '\0') {
|
||||||
hval <<= 4;
|
hval <<= 4;
|
||||||
hval += (u8) *str++;
|
hval += (uint8_t) *str++;
|
||||||
g = hval & ((u32) 0xf << (HASHWORDBITS - 4));
|
g = hval & ((uint32_t) 0xf << (HASHWORDBITS - 4));
|
||||||
if (g != 0) {
|
if (g != 0) {
|
||||||
hval ^= g >> (HASHWORDBITS - 8);
|
hval ^= g >> (HASHWORDBITS - 8);
|
||||||
hval ^= g;
|
hval ^= g;
|
||||||
@ -158,7 +158,7 @@ terminate:
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MSG *findMSG(u32 id) {
|
static MSG *findMSG(uint32_t id) {
|
||||||
MSG *msg;
|
MSG *msg;
|
||||||
for (msg = baseMSG; msg; msg = msg->next) {
|
for (msg = baseMSG; msg; msg = msg->next) {
|
||||||
if (msg->id == id) return msg;
|
if (msg->id == id) return msg;
|
||||||
@ -167,7 +167,7 @@ static MSG *findMSG(u32 id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static MSG *setMSG(const char *msgid, const char *msgstr) {
|
static MSG *setMSG(const char *msgid, const char *msgstr) {
|
||||||
u32 id = hash_string(msgid);
|
uint32_t id = hash_string(msgid);
|
||||||
MSG *msg = findMSG(id);
|
MSG *msg = findMSG(id);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
msg = (MSG *) malloc(sizeof(MSG));
|
msg = (MSG *) malloc(sizeof(MSG));
|
||||||
@ -196,7 +196,7 @@ extern "C" void gettextCleanUp(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" bool gettextLoadLanguage(const char* langFile) {
|
extern "C" BOOL gettextLoadLanguage(const char* langFile) {
|
||||||
char *lastID = NULL;
|
char *lastID = NULL;
|
||||||
gettextCleanUp();
|
gettextCleanUp();
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ extern "C" bool gettextLoadLanguage(const char* langFile) {
|
|||||||
|
|
||||||
std::string strBuffer;
|
std::string strBuffer;
|
||||||
strBuffer.resize(file.size());
|
strBuffer.resize(file.size());
|
||||||
file.read((u8 *) &strBuffer[0], strBuffer.size());
|
file.read((uint8_t *) &strBuffer[0], strBuffer.size());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
//! remove all windows crap signs
|
//! remove all windows crap signs
|
||||||
|
@ -4,18 +4,18 @@
|
|||||||
#include <coreinit/thread.h>
|
#include <coreinit/thread.h>
|
||||||
#include <nn/ac/ac_c.h>
|
#include <nn/ac/ac_c.h>
|
||||||
|
|
||||||
static u32 hostIpAddress __attribute__((section(".data"))) = 0;
|
static uint32_t hostIpAddress __attribute__((section(".data"))) = 0;
|
||||||
static volatile int socket_lock __attribute__((section(".data"))) = 0;
|
static volatile int socket_lock __attribute__((section(".data"))) = 0;
|
||||||
|
|
||||||
void initNetwork(){
|
void initNetwork(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 recvwait(s32 sock, void *buffer, s32 len) {
|
int32_t recvwait(int32_t sock, void *buffer, int32_t len) {
|
||||||
while(socket_lock) {
|
while(socket_lock) {
|
||||||
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
||||||
}
|
}
|
||||||
s32 ret;
|
int32_t ret;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
ret = recv(sock, buffer, len, 0);
|
ret = recv(sock, buffer, len, 0);
|
||||||
if(ret < 0) {
|
if(ret < 0) {
|
||||||
@ -29,30 +29,30 @@ s32 recvwait(s32 sock, void *buffer, s32 len) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 recvbyte(s32 sock) {
|
uint8_t recvbyte(int32_t sock) {
|
||||||
unsigned char buffer[1];
|
unsigned char buffer[1];
|
||||||
s32 ret;
|
int32_t ret;
|
||||||
|
|
||||||
ret = recvwait(sock, buffer, 1);
|
ret = recvwait(sock, buffer, 1);
|
||||||
if (ret < 0) return ret;
|
if (ret < 0) return ret;
|
||||||
return buffer[0];
|
return buffer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 recvword(s32 sock) {
|
uint32_t recvword(int32_t sock) {
|
||||||
u32 result;
|
uint32_t result;
|
||||||
s32 ret;
|
int32_t ret;
|
||||||
|
|
||||||
ret = recvwait(sock, &result, 4);
|
ret = recvwait(sock, &result, 4);
|
||||||
if (ret < 0) return ret;
|
if (ret < 0) return ret;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 checkbyte(s32 sock) {
|
int32_t checkbyte(int32_t sock) {
|
||||||
while(socket_lock) {
|
while(socket_lock) {
|
||||||
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
||||||
}
|
}
|
||||||
unsigned char buffer[1];
|
unsigned char buffer[1];
|
||||||
s32 ret;
|
int32_t ret;
|
||||||
|
|
||||||
ret = recv(sock, buffer, 1, MSG_DONTWAIT);
|
ret = recv(sock, buffer, 1, MSG_DONTWAIT);
|
||||||
socket_lock = 0;
|
socket_lock = 0;
|
||||||
@ -61,11 +61,11 @@ s32 checkbyte(s32 sock) {
|
|||||||
return buffer[0];
|
return buffer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 sendwait(s32 sock, const void *buffer, s32 len) {
|
int32_t sendwait(int32_t sock, const void *buffer, int32_t len) {
|
||||||
while(socket_lock) {
|
while(socket_lock) {
|
||||||
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
||||||
}
|
}
|
||||||
s32 ret;
|
int32_t ret;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
// For some reason the send blocks/crashes if the buffer is too big..
|
// For some reason the send blocks/crashes if the buffer is too big..
|
||||||
int cur_length = len <= 0x30 ? len : 0x30;
|
int cur_length = len <= 0x30 ? len : 0x30;
|
||||||
@ -81,7 +81,7 @@ s32 sendwait(s32 sock, const void *buffer, s32 len) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 sendbyte(s32 sock, unsigned char byte) {
|
int32_t sendbyte(int32_t sock, unsigned char byte) {
|
||||||
unsigned char buffer[1];
|
unsigned char buffer[1];
|
||||||
buffer[0] = byte;
|
buffer[0] = byte;
|
||||||
return sendwait(sock, buffer, 1);
|
return sendwait(sock, buffer, 1);
|
||||||
|
@ -36,16 +36,16 @@
|
|||||||
#include <utils/StringTools.h>
|
#include <utils/StringTools.h>
|
||||||
|
|
||||||
|
|
||||||
bool StringTools::EndsWith(const std::string& a, const std::string& b) {
|
BOOL StringTools::EndsWith(const std::string& a, const std::string& b) {
|
||||||
if (b.size() > a.size()) return false;
|
if (b.size() > a.size()) return false;
|
||||||
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
|
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * StringTools::byte_to_binary(s32 x) {
|
const char * StringTools::byte_to_binary(int32_t x) {
|
||||||
static char b[9];
|
static char b[9];
|
||||||
b[0] = '\0';
|
b[0] = '\0';
|
||||||
|
|
||||||
s32 z;
|
int32_t z;
|
||||||
for (z = 128; z > 0; z >>= 1) {
|
for (z = 128; z > 0; z >>= 1) {
|
||||||
strcat(b, ((x & z) == z) ? "1" : "0");
|
strcat(b, ((x & z) == z) ? "1" : "0");
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ const char * StringTools::fmt(const char * format, ...) {
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vsprintf(strChar, format, va) >= 0)) {
|
if((vsprintf(strChar, format, va) >= 0)) {
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return (const char *) strChar;
|
return (const char *) strChar;
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ const wchar_t * StringTools::wfmt(const char * format, ...) {
|
|||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vsprintf(tmp, format, va) >= 0)) {
|
if((vsprintf(tmp, format, va) >= 0)) {
|
||||||
int bt;
|
int bt;
|
||||||
s32 strlength = strlen(tmp);
|
int32_t strlength = strlen(tmp);
|
||||||
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 );
|
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 );
|
||||||
|
|
||||||
if(bt > 0) {
|
if(bt > 0) {
|
||||||
@ -109,10 +109,10 @@ const wchar_t * StringTools::wfmt(const char * format, ...) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 StringTools::strprintf(std::string &str, const char * format, ...) {
|
int32_t StringTools::strprintf(std::string &str, const char * format, ...) {
|
||||||
static char tmp[512];
|
static char tmp[512];
|
||||||
tmp[0] = 0;
|
tmp[0] = 0;
|
||||||
s32 result = 0;
|
int32_t result = 0;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
@ -140,7 +140,7 @@ std::string StringTools::strfmt(const char * format, ...) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
|
BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
|
||||||
if(!strChar || !dest)
|
if(!strChar || !dest)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ bool StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 StringTools::strtokcmp(const char * string, const char * compare, const char * separator) {
|
int32_t StringTools::strtokcmp(const char * string, const char * compare, const char * separator) {
|
||||||
if(!string || !compare)
|
if(!string || !compare)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ s32 StringTools::strtokcmp(const char * string, const char * compare, const char
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 StringTools::strextcmp(const char * string, const char * extension, char seperator) {
|
int32_t StringTools::strextcmp(const char * string, const char * extension, char seperator) {
|
||||||
if(!string || !extension)
|
if(!string || !extension)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
|
|||||||
std::string value = inValue;
|
std::string value = inValue;
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
while (true) {
|
while (true) {
|
||||||
u32 index = value.find(splitter);
|
uint32_t index = value.find(splitter);
|
||||||
if (index == std::string::npos) {
|
if (index == std::string::npos) {
|
||||||
result.push_back(value);
|
result.push_back(value);
|
||||||
break;
|
break;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#define wiiu_errno (*__gh_errno_ptr())
|
#define wiiu_errno (*__gh_errno_ptr())
|
||||||
|
|
||||||
TCPServer::TCPServer(s32 port,s32 priority) {
|
TCPServer::TCPServer(int32_t port,int32_t priority) {
|
||||||
this->port = port;
|
this->port = port;
|
||||||
this->sockfd = -1;
|
this->sockfd = -1;
|
||||||
this->clientfd = -1;
|
this->clientfd = -1;
|
||||||
@ -51,7 +51,7 @@ void TCPServer::ErrorHandling() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::DoTCPThreadInternal() {
|
void TCPServer::DoTCPThreadInternal() {
|
||||||
s32 ret;
|
int32_t ret;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
connected = false;
|
connected = false;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -68,7 +68,7 @@ void TCPServer::DoTCPThreadInternal() {
|
|||||||
ErrorHandling();
|
ErrorHandling();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s32 enable = 1;
|
int32_t enable = 1;
|
||||||
|
|
||||||
setsockopt(this->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
|
setsockopt(this->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <utils/elf_utils.h>
|
#include <utils/elf_utils.h>
|
||||||
|
|
||||||
|
|
||||||
u32 elf_get_section(u8 *data, const char *name, u32 * size, u32 * addr, int fail_on_not_found) {
|
uint32_t elf_get_section(uint8_t *data, const char *name, uint32_t * size, uint32_t * addr, int fail_on_not_found) {
|
||||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data;
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data;
|
||||||
|
|
||||||
if ( !data
|
if ( !data
|
||||||
@ -37,12 +37,12 @@ u32 elf_get_section(u8 *data, const char *name, u32 * size, u32 * addr, int fail
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool elf_copy_section(u8 * elf_data, const char * section_name) {
|
BOOL elf_copy_section(uint8_t * elf_data, const char * section_name) {
|
||||||
u32 section_addr = 0;
|
uint32_t section_addr = 0;
|
||||||
u32 section_len = 0;
|
uint32_t section_len = 0;
|
||||||
u32 section_offset = elf_get_section(elf_data, section_name, §ion_len, §ion_addr, false);
|
uint32_t section_offset = elf_get_section(elf_data, section_name, §ion_len, §ion_addr, false);
|
||||||
if(section_offset > 0) {
|
if(section_offset > 0) {
|
||||||
u8 *main_section = elf_data + section_offset;
|
uint8_t *main_section = elf_data + section_offset;
|
||||||
memcpy((void*) section_addr,(void*) main_section, section_len);
|
memcpy((void*) section_addr,(void*) main_section, section_len);
|
||||||
|
|
||||||
DCFlushRange((void*)section_addr, section_len);
|
DCFlushRange((void*)section_addr, section_len);
|
||||||
@ -52,7 +52,7 @@ bool elf_copy_section(u8 * elf_data, const char * section_name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 elf_copy_common_sections(u8 * elf_data) {
|
uint32_t elf_copy_common_sections(uint8_t * elf_data) {
|
||||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) elf_data;
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) elf_data;
|
||||||
if ( !elf_data
|
if ( !elf_data
|
||||||
|| !IS_ELF (*ehdr)
|
|| !IS_ELF (*ehdr)
|
||||||
@ -61,7 +61,7 @@ u32 elf_copy_common_sections(u8 * elf_data) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool error = false;
|
BOOL error = false;
|
||||||
|
|
||||||
if(!elf_copy_section(elf_data, ".text")) {
|
if(!elf_copy_section(elf_data, ".text")) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -74,7 +74,7 @@ u32 elf_copy_common_sections(u8 * elf_data) {
|
|||||||
return elf_get_entry_addr(elf_data);
|
return elf_get_entry_addr(elf_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 elf_get_entry_addr(u8 * elf_data) {
|
uint32_t elf_get_entry_addr(uint8_t * elf_data) {
|
||||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) elf_data;
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) elf_data;
|
||||||
if ( !elf_data
|
if ( !elf_data
|
||||||
|| !IS_ELF (*ehdr)
|
|| !IS_ELF (*ehdr)
|
||||||
@ -82,6 +82,6 @@ u32 elf_get_entry_addr(u8 * elf_data) {
|
|||||||
|| (ehdr->e_machine != EM_PPC)) {
|
|| (ehdr->e_machine != EM_PPC)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
u8 * source_addr = (u8 *) elf_data;
|
uint8_t * source_addr = (uint8_t *) elf_data;
|
||||||
return ehdr->e_entry;
|
return ehdr->e_entry;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user