diff --git a/examples/gpu/source/gs.c b/examples/gpu/source/gs.c
index 4eabd45..4f27d09 100644
--- a/examples/gpu/source/gs.c
+++ b/examples/gpu/source/gs.c
@@ -24,7 +24,7 @@ bufferMatrix_s bufferMatrixList[BUFFERMATRIXLIST_SIZE];
int bufferMatrixListLength;
//----------------------
-// GS SYSTEM STUFF
+// GS SYSTEM STUFF
//----------------------
void initBufferMatrixList()
@@ -74,7 +74,7 @@ void gsLinearFree(void* mem)
}
//----------------------
-// MATRIX STACK STUFF
+// MATRIX STACK STUFF
//----------------------
static mtx44 gsMatrixStacks[GS_MATRIXTYPES][GS_MATRIXSTACK_SIZE];
@@ -149,7 +149,7 @@ int gsMatrixMode(GS_MATRIX m)
}
//------------------------
-// MATRIX TRANSFORM STUFF
+// MATRIX TRANSFORM STUFF
//------------------------
int gsMultMatrix(float* data)
@@ -208,7 +208,7 @@ void gsTranslate(float x, float y, float z)
}
//----------------------
-// MATRIX RENDER STUFF
+// MATRIX RENDER STUFF
//----------------------
static void gsSetUniformMatrix(u32 startreg, float* m)
@@ -279,7 +279,7 @@ void gsAdjustBufferMatrices(mtx44 transformation)
}
//----------------------
-// VBO STUFF
+// VBO STUFF
//----------------------
int gsVboInit(gsVbo_s* vbo)
diff --git a/examples/gpu/source/main.c b/examples/gpu/source/main.c
index 3662ccd..c03849d 100644
--- a/examples/gpu/source/main.c
+++ b/examples/gpu/source/main.c
@@ -1,6 +1,6 @@
-///////////////////////////////////////
-// GPU example //
-///////////////////////////////////////
+//////////////////////////////////////
+// GPU example //
+//////////////////////////////////////
//this example is meant to show how to use the GPU to render a 3D object
//it also shows how to do stereoscopic 3D
diff --git a/examples/sdmc/source/main.c b/examples/sdmc/source/main.c
index 7c91ab4..b2c0f0f 100644
--- a/examples/sdmc/source/main.c
+++ b/examples/sdmc/source/main.c
@@ -1,6 +1,6 @@
-///////////////////////////////////////
-// SDMC example //
-///////////////////////////////////////
+//////////////////////////////////////
+// SDMC example //
+//////////////////////////////////////
//this example shows you how to load a binary image file from the SD card and display it on the lower screen
//for this to work you should copy test.bin to same folder as your .3dsx
diff --git a/libctru/include/3ds/console.h b/libctru/include/3ds/console.h
index 816eb02..d3b1085 100644
--- a/libctru/include/3ds/console.h
+++ b/libctru/include/3ds/console.h
@@ -1,7 +1,7 @@
/*! \file console.h
- \brief 3ds stdio support.
+ \brief 3ds stdio support.
@@ -74,7 +74,7 @@ typedef struct PrintConsole
int prevCursorY; /*!< Internal state */
int consoleWidth; /*!< Width of the console hardware layer in characters */
- int consoleHeight; /*!< Height of the console hardware layer in characters */
+ int consoleHeight; /*!< Height of the console hardware layer in characters */
int windowX; /*!< Window X location in characters (not implemented) */
int windowY; /*!< Window Y location in characters (not implemented) */
diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h
index 15db7b7..3335e74 100644
--- a/libctru/include/3ds/services/apt.h
+++ b/libctru/include/3ds/services/apt.h
@@ -23,17 +23,17 @@ typedef enum{
}APP_STATUS;
enum {
- APTSIGNAL_HOMEBUTTON = 1,
+ APTSIGNAL_HOMEBUTTON = 1,
// 2: sleep-mode related?
- APTSIGNAL_PREPARESLEEP = 3,
+ APTSIGNAL_PREPARESLEEP = 3,
// 4: triggered when ptm:s GetShellStatus() returns 5.
- APTSIGNAL_ENTERSLEEP = 5,
- APTSIGNAL_WAKEUP = 6,
- APTSIGNAL_ENABLE = 7,
- APTSIGNAL_POWERBUTTON = 8,
- APTSIGNAL_UTILITY = 9,
- APTSIGNAL_SLEEPSYSTEM = 10,
- APTSIGNAL_ERROR = 11
+ APTSIGNAL_ENTERSLEEP = 5,
+ APTSIGNAL_WAKEUP = 6,
+ APTSIGNAL_ENABLE = 7,
+ APTSIGNAL_POWERBUTTON = 8,
+ APTSIGNAL_UTILITY = 9,
+ APTSIGNAL_SLEEPSYSTEM = 10,
+ APTSIGNAL_ERROR = 11
};
@@ -82,4 +82,3 @@ Result APT_DoAppJump(Handle* handle, u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0P
Result APT_PrepareToStartLibraryApplet(Handle* handle, NS_APPID appID);
Result APT_StartLibraryApplet(Handle* handle, NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize);
Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize);//This should be used for launching library applets, this uses the above APT_StartLibraryApplet/APT_PrepareToStartLibraryApplet funcs + apt*Session(). parambuf is used for APT params input, when the applet closes the output param block is copied here. This is not usable from the homebrew launcher. This is broken: when the applet does get launched at all, the applet process doesn't actually get terminated when the applet gets closed.
-
diff --git a/libctru/include/3ds/services/fs.h b/libctru/include/3ds/services/fs.h
index a20fb9b..199e582 100644
--- a/libctru/include/3ds/services/fs.h
+++ b/libctru/include/3ds/services/fs.h
@@ -3,67 +3,67 @@
/*! @file FS.h
*
- * Filesystem Services
+ * Filesystem Services
*/
/*! @defgroup fs_open_flags FS Open Flags
*
- * @sa FSUSER_OpenFile
- * @sa FSUSER_OpenFileDirectly
+ * @sa FSUSER_OpenFile
+ * @sa FSUSER_OpenFileDirectly
*
- * @{
+ * @{
*/
/*! Open file for read. */
-#define FS_OPEN_READ (1<<0)
+#define FS_OPEN_READ (1<<0)
/*! Open file for write. */
-#define FS_OPEN_WRITE (1<<1)
+#define FS_OPEN_WRITE (1<<1)
/*! Create file if it doesn't exist. */
-#define FS_OPEN_CREATE (1<<2)
+#define FS_OPEN_CREATE (1<<2)
/* @} */
/*! @defgroup fs_create_attributes FS Create Attributes
*
- * @sa FSUSER_OpenFile
- * @sa FSUSER_OpenFileDirectly
+ * @sa FSUSER_OpenFile
+ * @sa FSUSER_OpenFileDirectly
*
- * @{
+ * @{
*/
/*! No attributes. */
-#define FS_ATTRIBUTE_NONE (0x00000000)
+#define FS_ATTRIBUTE_NONE (0x00000000)
/*! Create with read-only attribute. */
-#define FS_ATTRIBUTE_READONLY (0x00000001)
+#define FS_ATTRIBUTE_READONLY (0x00000001)
/*! Create with archive attribute. */
-#define FS_ATTRIBUTE_ARCHIVE (0x00000100)
+#define FS_ATTRIBUTE_ARCHIVE (0x00000100)
/*! Create with hidden attribute. */
-#define FS_ATTRIBUTE_HIDDEN (0x00010000)
+#define FS_ATTRIBUTE_HIDDEN (0x00010000)
/*! Create with directory attribute. */
-#define FS_ATTRIBUTE_DIRECTORY (0x01000000)
+#define FS_ATTRIBUTE_DIRECTORY (0x01000000)
/*! @} */
/*! @defgroup fs_write_flush_flags FS Flush Flags
*
- * @sa FSFILE_Write
+ * @sa FSFILE_Write
*
- * @{
+ * @{
*/
/*! Don't flush */
-#define FS_WRITE_NOFLUSH (0x00000000)
+#define FS_WRITE_NOFLUSH (0x00000000)
/*! Flush */
-#define FS_WRITE_FLUSH (0x00010001)
+#define FS_WRITE_FLUSH (0x00010001)
/* @} */
/*! FS path type */
typedef enum
{
- PATH_INVALID = 0, //!< Specifies an invalid path.
- PATH_EMPTY = 1, //!< Specifies an empty path.
- PATH_BINARY = 2, //!< Specifies a binary path, which is non-text based.
- PATH_CHAR = 3, //!< Specifies a text based path with a 8-bit byte per character.
- PATH_WCHAR = 4, //!< Specifies a text based path with a 16-bit short per character.
+ PATH_INVALID = 0, //!< Specifies an invalid path.
+ PATH_EMPTY = 1, //!< Specifies an empty path.
+ PATH_BINARY = 2, //!< Specifies a binary path, which is non-text based.
+ PATH_CHAR = 3, //!< Specifies a text based path with a 8-bit byte per character.
+ PATH_WCHAR = 4, //!< Specifies a text based path with a 16-bit short per character.
} FS_pathType;
/*! FS archive ids */
@@ -86,51 +86,51 @@ typedef enum
/*! FS path */
typedef struct
{
- FS_pathType type; //!< FS path type.
- u32 size; //!< FS path size.
- const u8 *data; //!< Pointer to FS path data.
+ FS_pathType type; //!< FS path type.
+ u32 size; //!< FS path size.
+ const u8 *data; //!< Pointer to FS path data.
} FS_path;
/*! FS archive */
typedef struct
{
- u32 id; //!< Archive ID.
- FS_path lowPath; //!< FS path.
- Handle handleLow; //!< High word of handle.
- Handle handleHigh; //!< Low word of handle.
+ u32 id; //!< Archive ID.
+ FS_path lowPath; //!< FS path.
+ Handle handleLow; //!< High word of handle.
+ Handle handleHigh; //!< Low word of handle.
} FS_archive;
/*! Directory entry */
typedef struct
{
- // 0x00
- u16 name[0x106]; //!< UTF-16 encoded name
- // 0x20C
- u8 shortName[0x09]; //!< 8.3 file name
- // 0x215
- u8 unknown1; //!< ???
- // 0x216
- u8 shortExt[0x04]; //!< 8.3 file extension (set to spaces for directories)
- // 0x21A
- u8 unknown2; //!< ???
- // 0x21B
- u8 unknown3; //!< ???
- // 0x21C
- u8 isDirectory; //!< directory bit
- // 0x21D
- u8 isHidden; //!< hidden bit
- // 0x21E
- u8 isArchive; //!< archive bit
- // 0x21F
- u8 isReadOnly; //!< read-only bit
- // 0x220
- u64 fileSize; //!< file size
+ // 0x00
+ u16 name[0x106]; //!< UTF-16 encoded name
+ // 0x20C
+ u8 shortName[0x09]; //!< 8.3 file name
+ // 0x215
+ u8 unknown1; //!< ???
+ // 0x216
+ u8 shortExt[0x04]; //!< 8.3 file extension (set to spaces for directories)
+ // 0x21A
+ u8 unknown2; //!< ???
+ // 0x21B
+ u8 unknown3; //!< ???
+ // 0x21C
+ u8 isDirectory; //!< directory bit
+ // 0x21D
+ u8 isHidden; //!< hidden bit
+ // 0x21E
+ u8 isArchive; //!< archive bit
+ // 0x21F
+ u8 isReadOnly; //!< read-only bit
+ // 0x220
+ u64 fileSize; //!< file size
} FS_dirent;
Result fsInit(void);
Result fsExit(void);
-FS_path FS_makePath(FS_pathType type, const char *path);
+FS_path FS_makePath(FS_pathType type, const char *path);
Result FSUSER_Initialize(Handle* handle);
Result FSUSER_OpenArchive(Handle* handle, FS_archive* archive);
diff --git a/libctru/include/3ds/services/hid.h b/libctru/include/3ds/services/hid.h
index 87a99cf..fe719d2 100644
--- a/libctru/include/3ds/services/hid.h
+++ b/libctru/include/3ds/services/hid.h
@@ -6,35 +6,35 @@
typedef enum
{
- KEY_A = BIT(0),
- KEY_B = BIT(1),
- KEY_SELECT = BIT(2),
- KEY_START = BIT(3),
- KEY_DRIGHT = BIT(4),
- KEY_DLEFT = BIT(5),
- KEY_DUP = BIT(6),
- KEY_DDOWN = BIT(7),
- KEY_R = BIT(8),
- KEY_L = BIT(9),
- KEY_X = BIT(10),
- KEY_Y = BIT(11),
- KEY_ZL = BIT(14), // (new 3DS only)
- KEY_ZR = BIT(15), // (new 3DS only)
- KEY_TOUCH = BIT(20), // Not actually provided by HID
- KEY_CSTICK_RIGHT = BIT(24), // c-stick (new 3DS only)
- KEY_CSTICK_LEFT = BIT(25), // c-stick (new 3DS only)
- KEY_CSTICK_UP = BIT(26), // c-stick (new 3DS only)
- KEY_CSTICK_DOWN = BIT(27), // c-stick (new 3DS only)
- KEY_CPAD_RIGHT = BIT(28), // circle pad
- KEY_CPAD_LEFT = BIT(29), // circle pad
- KEY_CPAD_UP = BIT(30), // circle pad
- KEY_CPAD_DOWN = BIT(31), // circle pad
+ KEY_A = BIT(0),
+ KEY_B = BIT(1),
+ KEY_SELECT = BIT(2),
+ KEY_START = BIT(3),
+ KEY_DRIGHT = BIT(4),
+ KEY_DLEFT = BIT(5),
+ KEY_DUP = BIT(6),
+ KEY_DDOWN = BIT(7),
+ KEY_R = BIT(8),
+ KEY_L = BIT(9),
+ KEY_X = BIT(10),
+ KEY_Y = BIT(11),
+ KEY_ZL = BIT(14), // (new 3DS only)
+ KEY_ZR = BIT(15), // (new 3DS only)
+ KEY_TOUCH = BIT(20), // Not actually provided by HID
+ KEY_CSTICK_RIGHT = BIT(24), // c-stick (new 3DS only)
+ KEY_CSTICK_LEFT = BIT(25), // c-stick (new 3DS only)
+ KEY_CSTICK_UP = BIT(26), // c-stick (new 3DS only)
+ KEY_CSTICK_DOWN = BIT(27), // c-stick (new 3DS only)
+ KEY_CPAD_RIGHT = BIT(28), // circle pad
+ KEY_CPAD_LEFT = BIT(29), // circle pad
+ KEY_CPAD_UP = BIT(30), // circle pad
+ KEY_CPAD_DOWN = BIT(31), // circle pad
// Generic catch-all directions
- KEY_UP = KEY_DUP | KEY_CPAD_UP,
- KEY_DOWN = KEY_DDOWN | KEY_CPAD_DOWN,
- KEY_LEFT = KEY_DLEFT | KEY_CPAD_LEFT,
- KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT,
+ KEY_UP = KEY_DUP | KEY_CPAD_UP,
+ KEY_DOWN = KEY_DDOWN | KEY_CPAD_DOWN,
+ KEY_LEFT = KEY_DLEFT | KEY_CPAD_LEFT,
+ KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT,
} PAD_KEY;
typedef struct
@@ -90,12 +90,12 @@ void hidGyroRead(angularRate* rate);
void hidWaitForEvent(HID_Event id, bool nextEvent);
// libnds compatibility defines
-#define scanKeys hidScanInput
-#define keysHeld hidKeysHeld
-#define keysDown hidKeysDown
-#define keysUp hidKeysUp
-#define touchRead hidTouchRead
-#define circleRead hidCircleRead
+#define scanKeys hidScanInput
+#define keysHeld hidKeysHeld
+#define keysDown hidKeysDown
+#define keysUp hidKeysUp
+#define touchRead hidTouchRead
+#define circleRead hidCircleRead
Result HIDUSER_GetHandles(Handle* outMemHandle, Handle *eventpad0, Handle *eventpad1, Handle *eventaccel, Handle *eventgyro, Handle *eventdebugpad);
Result HIDUSER_EnableAccelerometer();
diff --git a/libctru/include/3ds/svc.h b/libctru/include/3ds/svc.h
index 271408f..703b659 100644
--- a/libctru/include/3ds/svc.h
+++ b/libctru/include/3ds/svc.h
@@ -1,45 +1,45 @@
/*
- svc.h _ Syscall wrappers.
+ svc.h _ Syscall wrappers.
*/
#pragma once
typedef enum {
- MEMOP_FREE =1, // Free heap
- MEMOP_ALLOC=3, // Allocate heap
- MEMOP_MAP =4, // Mirror mapping
- MEMOP_UNMAP=5, // Mirror unmapping
- MEMOP_PROT =6, // Change protection
+ MEMOP_FREE =1, // Free heap
+ MEMOP_ALLOC =3, // Allocate heap
+ MEMOP_MAP =4, // Mirror mapping
+ MEMOP_UNMAP =5, // Mirror unmapping
+ MEMOP_PROT =6, // Change protection
MEMOP_FREE_LINEAR =0x10001, // Free linear heap
- MEMOP_ALLOC_LINEAR=0x10003 // Allocate linear heap
+ MEMOP_ALLOC_LINEAR=0x10003 // Allocate linear heap
} MemOp;
typedef enum {
- MEMPERM_READ = 1,
- MEMPERM_WRITE = 2,
- MEMPERM_EXECUTE = 4,
- MEMPERM_DONTCARE = 0x10000000,
- MEMPERM_MAX = 0xFFFFFFFF //force 4-byte
+ MEMPERM_READ = 1,
+ MEMPERM_WRITE = 2,
+ MEMPERM_EXECUTE = 4,
+ MEMPERM_DONTCARE = 0x10000000,
+ MEMPERM_MAX = 0xFFFFFFFF //force 4-byte
} MemPerm;
typedef struct {
- u32 base_addr;
- u32 size;
- u32 perm;
- u32 state;
+ u32 base_addr;
+ u32 size;
+ u32 perm;
+ u32 state;
} MemInfo;
typedef struct {
- u32 flags;
+ u32 flags;
} PageInfo;
typedef enum {
- ARBITER_FREE =0,
- ARBITER_ACQUIRE =1,
- ARBITER_KERNEL2 =2,
- ARBITER_ACQUIRE_TIMEOUT=3,
- ARBITER_KERNEL4 =4,
+ ARBITER_FREE =0,
+ ARBITER_ACQUIRE =1,
+ ARBITER_KERNEL2 =2,
+ ARBITER_ACQUIRE_TIMEOUT =3,
+ ARBITER_KERNEL4 =4,
} ArbitrationType;
static inline void* getThreadLocalStorage(void)
@@ -54,38 +54,38 @@ static inline u32* getThreadCommandBuffer(void)
return (u32*)((u8*)getThreadLocalStorage() + 0x80);
}
-s32 svcControlMemory(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm);
-s32 svcQueryMemory(MemInfo* info, PageInfo* out, u32 addr);
-void __attribute__((noreturn)) svcExitProcess();
-s32 svcCreateThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stack_top, s32 thread_priority, s32 processor_id);
-void __attribute__((noreturn)) svcExitThread();
-void svcSleepThread(s64 ns);
-s32 svcSetThreadPriority(Handle thread, s32 prio);
-s32 svcCreateMutex(Handle* mutex, bool initially_locked);
-s32 svcReleaseMutex(Handle handle);
-s32 svcCreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count);
-s32 svcReleaseSemaphore(s32* count, Handle semaphore, s32 release_count);
-s32 svcCreateEvent(Handle* event, u8 reset_type);
-s32 svcSignalEvent(Handle handle);
-s32 svcClearEvent(Handle handle);
-s32 svcCreateTimer(Handle* timer, u8 reset_type);
-s32 svcSetTimer(Handle timer, s64 initial, s64 interval);
-s32 svcCancelTimer(Handle timer);
-s32 svcClearTimer(Handle timer);
-s32 svcCreateMemoryBlock(Handle* memblock, u32 addr, u32 size, MemPerm my_perm, MemPerm other_perm);
-s32 svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm);
-s32 svcUnmapMemoryBlock(Handle memblock, u32 addr);
-s32 svcCreateAddressArbiter(Handle *arbiter);
-s32 svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 nanoseconds);
-s32 svcWaitSynchronization(Handle handle, s64 nanoseconds);
-s32 svcWaitSynchronizationN(s32* out, Handle* handles, s32 handles_num, bool wait_all, s64 nanoseconds);
-s32 svcCloseHandle(Handle handle);
-s32 svcDuplicateHandle(Handle* out, Handle original);
-u64 svcGetSystemTick();
-s32 svcGetSystemInfo(s64* out, u32 type, s32 param);
-s32 svcGetProcessInfo(s64* out, Handle process, u32 type);
-s32 svcConnectToPort(volatile Handle* out, const char* portName);
-s32 svcSendSyncRequest(Handle session);
-s32 svcGetProcessId(u32 *out, Handle handle);
-s32 svcGetThreadId(u32 *out, Handle handle);
-s32 svcOutputDebugString(const char* str, int length);
+s32 svcControlMemory(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm);
+s32 svcQueryMemory(MemInfo* info, PageInfo* out, u32 addr);
+void __attribute__((noreturn)) svcExitProcess();
+s32 svcCreateThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stack_top, s32 thread_priority, s32 processor_id);
+void __attribute__((noreturn)) svcExitThread();
+void svcSleepThread(s64 ns);
+s32 svcSetThreadPriority(Handle thread, s32 prio);
+s32 svcCreateMutex(Handle* mutex, bool initially_locked);
+s32 svcReleaseMutex(Handle handle);
+s32 svcCreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count);
+s32 svcReleaseSemaphore(s32* count, Handle semaphore, s32 release_count);
+s32 svcCreateEvent(Handle* event, u8 reset_type);
+s32 svcSignalEvent(Handle handle);
+s32 svcClearEvent(Handle handle);
+s32 svcCreateTimer(Handle* timer, u8 reset_type);
+s32 svcSetTimer(Handle timer, s64 initial, s64 interval);
+s32 svcCancelTimer(Handle timer);
+s32 svcClearTimer(Handle timer);
+s32 svcCreateMemoryBlock(Handle* memblock, u32 addr, u32 size, MemPerm my_perm, MemPerm other_perm);
+s32 svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm);
+s32 svcUnmapMemoryBlock(Handle memblock, u32 addr);
+s32 svcCreateAddressArbiter(Handle *arbiter);
+s32 svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 nanoseconds);
+s32 svcWaitSynchronization(Handle handle, s64 nanoseconds);
+s32 svcWaitSynchronizationN(s32* out, Handle* handles, s32 handles_num, bool wait_all, s64 nanoseconds);
+s32 svcCloseHandle(Handle handle);
+s32 svcDuplicateHandle(Handle* out, Handle original);
+u64 svcGetSystemTick();
+s32 svcGetSystemInfo(s64* out, u32 type, s32 param);
+s32 svcGetProcessInfo(s64* out, Handle process, u32 type);
+s32 svcConnectToPort(volatile Handle* out, const char* portName);
+s32 svcSendSyncRequest(Handle session);
+s32 svcGetProcessId(u32 *out, Handle handle);
+s32 svcGetThreadId(u32 *out, Handle handle);
+s32 svcOutputDebugString(const char* str, int length);
diff --git a/libctru/include/3ds/util/rbtree.h b/libctru/include/3ds/util/rbtree.h
index 73110f0..6fc5d01 100644
--- a/libctru/include/3ds/util/rbtree.h
+++ b/libctru/include/3ds/util/rbtree.h
@@ -4,25 +4,25 @@
#include
#define rbtree_item(ptr, type, member) \
- ((type*)(((char*)ptr) - offsetof(type, member)))
+ ((type*)(((char*)ptr) - offsetof(type, member)))
-typedef struct rbtree rbtree_t;
-typedef struct rbtree_node rbtree_node_t;
+typedef struct rbtree rbtree_t;
+typedef struct rbtree_node rbtree_node_t;
typedef void (*rbtree_node_destructor_t)(rbtree_node_t *Node);
-typedef int (*rbtree_node_comparator_t)(const rbtree_node_t *lhs,
- const rbtree_node_t *rhs);
+typedef int (*rbtree_node_comparator_t)(const rbtree_node_t *lhs,
+ const rbtree_node_t *rhs);
struct rbtree_node
{
- uintptr_t parent_color;
- rbtree_node_t *child[2];
+ uintptr_t parent_color;
+ rbtree_node_t *child[2];
};
struct rbtree
{
- rbtree_node_t *root;
- rbtree_node_comparator_t comparator;
- size_t size;
+ rbtree_node_t *root;
+ rbtree_node_comparator_t comparator;
+ size_t size;
};
#ifdef __cplusplus
@@ -30,8 +30,8 @@ extern "C" {
#endif
void
-rbtree_init(rbtree_t *tree,
- rbtree_node_comparator_t comparator);
+rbtree_init(rbtree_t *tree,
+ rbtree_node_comparator_t comparator);
int
rbtree_empty(const rbtree_t *tree);
@@ -41,16 +41,16 @@ rbtree_size(const rbtree_t *tree);
__attribute__((warn_unused_result))
rbtree_node_t*
-rbtree_insert(rbtree_t *tree,
- rbtree_node_t *node);
+rbtree_insert(rbtree_t *tree,
+ rbtree_node_t *node);
void
-rbtree_insert_multi(rbtree_t *tree,
- rbtree_node_t *node);
+rbtree_insert_multi(rbtree_t *tree,
+ rbtree_node_t *node);
rbtree_node_t*
-rbtree_find(const rbtree_t *tree,
- const rbtree_node_t *node);
+rbtree_find(const rbtree_t *tree,
+ const rbtree_node_t *node);
rbtree_node_t*
rbtree_min(const rbtree_t *tree);
@@ -65,13 +65,13 @@ rbtree_node_t*
rbtree_node_prev(const rbtree_node_t *node);
rbtree_node_t*
-rbtree_remove(rbtree_t *tree,
- rbtree_node_t *node,
- rbtree_node_destructor_t destructor);
+rbtree_remove(rbtree_t *tree,
+ rbtree_node_t *node,
+ rbtree_node_destructor_t destructor);
void
-rbtree_clear(rbtree_t *tree,
- rbtree_node_destructor_t destructor);
+rbtree_clear(rbtree_t *tree,
+ rbtree_node_destructor_t destructor);
#ifdef __cplusplus
}
diff --git a/libctru/source/allocator/mem_pool.cpp b/libctru/source/allocator/mem_pool.cpp
index a2c312d..3d71031 100644
--- a/libctru/source/allocator/mem_pool.cpp
+++ b/libctru/source/allocator/mem_pool.cpp
@@ -63,9 +63,9 @@ bool MemPool::Allocate(MemChunk& chunk, u32 size, int align)
if (nSize)
{
// We need to add the tail chunk that wasn't used to the list
- auto n = MemBlock::Create(nAddr, nSize);
- if (n) InsertAfter(b, n);
- else chunk.size += nSize; // we have no choice but to waste the space.
+ auto n = MemBlock::Create(nAddr, nSize);
+ if (n) InsertAfter(b, n);
+ else chunk.size += nSize; // we have no choice but to waste the space.
}
}
return true;
@@ -76,9 +76,9 @@ bool MemPool::Allocate(MemChunk& chunk, u32 size, int align)
void MemPool::Deallocate(const MemChunk& chunk)
{
- u8* cAddr = chunk.addr;
- auto cSize = chunk.size;
- bool done = false;
+ u8* cAddr = chunk.addr;
+ auto cSize = chunk.size;
+ bool done = false;
// Try to merge the chunk somewhere into the list
for (auto b = first; !done && b; b = b->next)
@@ -121,7 +121,7 @@ void MemPool::Dump(const char* title)
{
printf("<%s> VRAM Pool Dump\n", title);
for (auto b = first; b; b = b->next)
- printf(" - %p (%u bytes)\n", b->base, b->size);
+ printf(" - %p (%u bytes)\n", b->base, b->size);
}
*/
diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c
index 0688804..e69b6e1 100644
--- a/libctru/source/gfx.c
+++ b/libctru/source/gfx.c
@@ -31,17 +31,17 @@ void gfxSet3D(bool enable)
}
void gfxSetScreenFormat(gfxScreen_t screen, GSP_FramebufferFormats format) {
- if(screen==GFX_TOP)
- topFormat = format;
- else
- botFormat = format;
+ if(screen==GFX_TOP)
+ topFormat = format;
+ else
+ botFormat = format;
}
GSP_FramebufferFormats gfxGetScreenFormat(gfxScreen_t screen) {
- if(screen==GFX_TOP)
- return topFormat;
- else
- return botFormat;
+ if(screen==GFX_TOP)
+ return topFormat;
+ else
+ return botFormat;
}
void gfxSetDoubleBuffering( gfxScreen_t screen, bool doubleBuffering) {
@@ -49,18 +49,18 @@ void gfxSetDoubleBuffering( gfxScreen_t screen, bool doubleBuffering) {
}
static u32 __get_bytes_per_pixel(GSP_FramebufferFormats format) {
- switch(format) {
- case GSP_RGBA8_OES:
- return 4;
- case GSP_BGR8_OES:
- return 3;
- case GSP_RGB565_OES:
- case GSP_RGB5_A1_OES:
- case GSP_RGBA4_OES:
- return 2;
- }
+ switch(format) {
+ case GSP_RGBA8_OES:
+ return 4;
+ case GSP_BGR8_OES:
+ return 3;
+ case GSP_RGB565_OES:
+ case GSP_RGB5_A1_OES:
+ case GSP_RGBA4_OES:
+ return 2;
+ }
- return 3;
+ return 3;
}
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
diff --git a/libctru/source/sdmc_dev.c b/libctru/source/sdmc_dev.c
index d02c962..66a8850 100644
--- a/libctru/source/sdmc_dev.c
+++ b/libctru/source/sdmc_dev.c
@@ -14,91 +14,91 @@
/*! @internal
*
- * @file sdmc_dev.c
+ * @file sdmc_dev.c
*
- * SDMC Device
+ * SDMC Device
*/
-static int sdmc_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
-static int sdmc_close(struct _reent *r, int fd);
-static ssize_t sdmc_write(struct _reent *r, int fd, const char *ptr, size_t len);
-static ssize_t sdmc_read(struct _reent *r, int fd, char *ptr, size_t len);
-static off_t sdmc_seek(struct _reent *r, int fd, off_t pos, int dir);
-static int sdmc_fstat(struct _reent *r, int fd, struct stat *st);
-static int sdmc_stat(struct _reent *r, const char *file, struct stat *st);
-static int sdmc_link(struct _reent *r, const char *existing, const char *newLink);
-static int sdmc_unlink(struct _reent *r, const char *name);
-static int sdmc_chdir(struct _reent *r, const char *name);
-static int sdmc_rename(struct _reent *r, const char *oldName, const char *newName);
-static int sdmc_mkdir(struct _reent *r, const char *path, int mode);
-static DIR_ITER* sdmc_diropen(struct _reent *r, DIR_ITER *dirState, const char *path);
-static int sdmc_dirreset(struct _reent *r, DIR_ITER *dirState);
-static int sdmc_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
-static int sdmc_dirclose(struct _reent *r, DIR_ITER *dirState);
-static int sdmc_statvfs(struct _reent *r, const char *path, struct statvfs *buf);
-static int sdmc_ftruncate(struct _reent *r, int fd, off_t len);
-static int sdmc_fsync(struct _reent *r, int fd);
-static int sdmc_chmod(struct _reent *r, const char *path, mode_t mode);
-static int sdmc_fchmod(struct _reent *r, int fd, mode_t mode);
+static int sdmc_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
+static int sdmc_close(struct _reent *r, int fd);
+static ssize_t sdmc_write(struct _reent *r, int fd, const char *ptr, size_t len);
+static ssize_t sdmc_read(struct _reent *r, int fd, char *ptr, size_t len);
+static off_t sdmc_seek(struct _reent *r, int fd, off_t pos, int dir);
+static int sdmc_fstat(struct _reent *r, int fd, struct stat *st);
+static int sdmc_stat(struct _reent *r, const char *file, struct stat *st);
+static int sdmc_link(struct _reent *r, const char *existing, const char *newLink);
+static int sdmc_unlink(struct _reent *r, const char *name);
+static int sdmc_chdir(struct _reent *r, const char *name);
+static int sdmc_rename(struct _reent *r, const char *oldName, const char *newName);
+static int sdmc_mkdir(struct _reent *r, const char *path, int mode);
+static DIR_ITER* sdmc_diropen(struct _reent *r, DIR_ITER *dirState, const char *path);
+static int sdmc_dirreset(struct _reent *r, DIR_ITER *dirState);
+static int sdmc_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
+static int sdmc_dirclose(struct _reent *r, DIR_ITER *dirState);
+static int sdmc_statvfs(struct _reent *r, const char *path, struct statvfs *buf);
+static int sdmc_ftruncate(struct _reent *r, int fd, off_t len);
+static int sdmc_fsync(struct _reent *r, int fd);
+static int sdmc_chmod(struct _reent *r, const char *path, mode_t mode);
+static int sdmc_fchmod(struct _reent *r, int fd, mode_t mode);
/*! @cond INTERNAL */
/*! Open file struct */
typedef struct
{
- Handle fd; /*! CTRU handle */
- int flags; /*! Flags used in open(2) */
- u64 offset; /*! Current file offset */
+ Handle fd; /*! CTRU handle */
+ int flags; /*! Flags used in open(2) */
+ u64 offset; /*! Current file offset */
} sdmc_file_t;
/*! Open directory struct */
typedef struct
{
- Handle fd; /*! CTRU handle */
- FS_dirent entry_data; /*! Temporary storage for reading entries */
+ Handle fd; /*! CTRU handle */
+ FS_dirent entry_data; /*! Temporary storage for reading entries */
} sdmc_dir_t;
/*! SDMC devoptab */
static devoptab_t
sdmc_devoptab =
{
- .name = "sdmc",
- .structSize = sizeof(sdmc_file_t),
- .open_r = sdmc_open,
- .close_r = sdmc_close,
- .write_r = sdmc_write,
- .read_r = sdmc_read,
- .seek_r = sdmc_seek,
- .fstat_r = sdmc_fstat,
- .stat_r = sdmc_stat,
- .link_r = sdmc_link,
- .unlink_r = sdmc_unlink,
- .chdir_r = sdmc_chdir,
- .rename_r = sdmc_rename,
- .mkdir_r = sdmc_mkdir,
- .dirStateSize = sizeof(sdmc_dir_t),
- .diropen_r = sdmc_diropen,
- .dirreset_r = sdmc_dirreset,
- .dirnext_r = sdmc_dirnext,
- .dirclose_r = sdmc_dirclose,
- .statvfs_r = sdmc_statvfs,
- .ftruncate_r = sdmc_ftruncate,
- .fsync_r = sdmc_fsync,
- .deviceData = NULL,
- .chmod_r = sdmc_chmod,
- .fchmod_r = sdmc_fchmod,
+ .name = "sdmc",
+ .structSize = sizeof(sdmc_file_t),
+ .open_r = sdmc_open,
+ .close_r = sdmc_close,
+ .write_r = sdmc_write,
+ .read_r = sdmc_read,
+ .seek_r = sdmc_seek,
+ .fstat_r = sdmc_fstat,
+ .stat_r = sdmc_stat,
+ .link_r = sdmc_link,
+ .unlink_r = sdmc_unlink,
+ .chdir_r = sdmc_chdir,
+ .rename_r = sdmc_rename,
+ .mkdir_r = sdmc_mkdir,
+ .dirStateSize = sizeof(sdmc_dir_t),
+ .diropen_r = sdmc_diropen,
+ .dirreset_r = sdmc_dirreset,
+ .dirnext_r = sdmc_dirnext,
+ .dirclose_r = sdmc_dirclose,
+ .statvfs_r = sdmc_statvfs,
+ .ftruncate_r = sdmc_ftruncate,
+ .fsync_r = sdmc_fsync,
+ .deviceData = NULL,
+ .chmod_r = sdmc_chmod,
+ .fchmod_r = sdmc_fchmod,
};
/*! SDMC archive handle */
static FS_archive sdmcArchive =
{
- .id = ARCH_SDMC,
- .lowPath =
- {
- .type = PATH_EMPTY,
- .size = 1,
- .data = (u8*)"",
- },
+ .id = ARCH_SDMC,
+ .lowPath =
+ {
+ .type = PATH_EMPTY,
+ .size = 1,
+ .data = (u8*)"",
+ },
};
/*! @endcond */
@@ -108,22 +108,22 @@ static char __fixedpath[PATH_MAX+1];
static const char *sdmc_fixpath(const char *path)
{
- // Move the path pointer to the start of the actual path
- if (strchr (path, ':') != NULL)
- {
- path = strchr (path, ':') + 1;
- }
+ // Move the path pointer to the start of the actual path
+ if (strchr (path, ':') != NULL)
+ {
+ path = strchr (path, ':') + 1;
+ }
- if (strchr (path, ':') != NULL) return NULL;
+ if (strchr (path, ':') != NULL) return NULL;
- if (path[0]=='/') return path;
+ if (path[0]=='/') return path;
- strncpy(__fixedpath,__cwd,PATH_MAX);
- strncat(__fixedpath,path,PATH_MAX);
- __fixedpath[PATH_MAX] = 0;
+ strncpy(__fixedpath,__cwd,PATH_MAX);
+ strncat(__fixedpath,path,PATH_MAX);
+ __fixedpath[PATH_MAX] = 0;
- return __fixedpath;
+ return __fixedpath;
}
@@ -135,849 +135,849 @@ static bool sdmcInitialised = false;
/*! Initialize SDMC device */
Result sdmcInit(void)
{
- Result rc = 0;
+ Result rc = 0;
- if (sdmcInitialised) return rc;
+ if (sdmcInitialised) return rc;
- rc = FSUSER_OpenArchive(NULL, &sdmcArchive);
+ rc = FSUSER_OpenArchive(NULL, &sdmcArchive);
- if(rc == 0)
- {
+ if(rc == 0)
+ {
- int dev = AddDevice(&sdmc_devoptab);
+ int dev = AddDevice(&sdmc_devoptab);
- if (dev != -1) {
- setDefaultDevice(dev);
- if (__system_argc != 0 && __system_argv[0] != NULL)
- {
- if (FindDevice(__system_argv[0]) == dev)
- {
- strncpy(__fixedpath,__system_argv[0],PATH_MAX);
- char *last_slash = strrchr(__fixedpath,'/');
- if (last_slash != NULL) {
- last_slash[0] = 0;
- chdir(__fixedpath);
- }
- }
- }
- }
- }
+ if (dev != -1) {
+ setDefaultDevice(dev);
+ if (__system_argc != 0 && __system_argv[0] != NULL)
+ {
+ if (FindDevice(__system_argv[0]) == dev)
+ {
+ strncpy(__fixedpath,__system_argv[0],PATH_MAX);
+ char *last_slash = strrchr(__fixedpath,'/');
+ if (last_slash != NULL) {
+ last_slash[0] = 0;
+ chdir(__fixedpath);
+ }
+ }
+ }
+ }
+ }
- sdmcInitialised = true;
+ sdmcInitialised = true;
- return rc;
+ return rc;
}
/*! Clean up SDMC device */
Result sdmcExit(void)
{
- Result rc = 0;
+ Result rc = 0;
- if (!sdmcInitialised) return rc;
+ if (!sdmcInitialised) return rc;
- rc = FSUSER_CloseArchive(NULL, &sdmcArchive);
- if(rc == 0)
- RemoveDevice("sdmc");
+ rc = FSUSER_CloseArchive(NULL, &sdmcArchive);
+ if(rc == 0)
+ RemoveDevice("sdmc");
- sdmcInitialised = false;
+ sdmcInitialised = false;
- return rc;
+ return rc;
}
/*! Open a file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[out] fileStruct Pointer to file struct to fill in
- * @param[in] path Path to open
- * @param[in] flags Open flags from open(2)
- * @param[in] mode Permissions to set on create
+ * @param[in,out] r newlib reentrancy struct
+ * @param[out] fileStruct Pointer to file struct to fill in
+ * @param[in] path Path to open
+ * @param[in] flags Open flags from open(2)
+ * @param[in] mode Permissions to set on create
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_open(struct _reent *r,
- void *fileStruct,
- const char *path,
- int flags,
- int mode)
+ void *fileStruct,
+ const char *path,
+ int flags,
+ int mode)
{
- Handle fd;
- Result rc;
- u32 sdmc_flags = 0;
- u32 attributes = FS_ATTRIBUTE_NONE;
- const char *pathptr = NULL;
+ Handle fd;
+ Result rc;
+ u32 sdmc_flags = 0;
+ u32 attributes = FS_ATTRIBUTE_NONE;
+ const char *pathptr = NULL;
- pathptr = sdmc_fixpath(path);
+ pathptr = sdmc_fixpath(path);
- if(pathptr==NULL)
- {
- r->_errno=EINVAL;
- return -1;
- }
+ if(pathptr==NULL)
+ {
+ r->_errno=EINVAL;
+ return -1;
+ }
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fileStruct;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fileStruct;
- /* check access mode */
- switch(flags & O_ACCMODE)
- {
- /* read-only: do not allow O_APPEND */
- case O_RDONLY:
- sdmc_flags |= FS_OPEN_READ;
- if(flags & O_APPEND)
- {
- r->_errno = EINVAL;
- return -1;
- }
- break;
+ /* check access mode */
+ switch(flags & O_ACCMODE)
+ {
+ /* read-only: do not allow O_APPEND */
+ case O_RDONLY:
+ sdmc_flags |= FS_OPEN_READ;
+ if(flags & O_APPEND)
+ {
+ r->_errno = EINVAL;
+ return -1;
+ }
+ break;
- /* write-only */
- case O_WRONLY:
- sdmc_flags |= FS_OPEN_WRITE;
- break;
+ /* write-only */
+ case O_WRONLY:
+ sdmc_flags |= FS_OPEN_WRITE;
+ break;
- /* read and write */
- case O_RDWR:
- sdmc_flags |= (FS_OPEN_READ | FS_OPEN_WRITE);
- break;
+ /* read and write */
+ case O_RDWR:
+ sdmc_flags |= (FS_OPEN_READ | FS_OPEN_WRITE);
+ break;
- /* an invalid option was supplied */
- default:
- r->_errno = EINVAL;
- return -1;
- }
+ /* an invalid option was supplied */
+ default:
+ r->_errno = EINVAL;
+ return -1;
+ }
- /* create file */
- if(flags & O_CREAT)
- sdmc_flags |= FS_OPEN_CREATE;
+ /* create file */
+ if(flags & O_CREAT)
+ sdmc_flags |= FS_OPEN_CREATE;
- /* Test O_EXCL. */
- if((flags & O_CREAT) && (flags & O_EXCL))
- {
- rc = FSUSER_CreateFile(NULL, sdmcArchive, FS_makePath(PATH_CHAR, pathptr), 0);
- if(rc != 0)
- {
- r->_errno = rc;
- if(rc == 0x82044BE)
- r->_errno = EEXIST;
- if(rc == 0x86044D2)
- r->_errno = ENOSPC;
- return -1;
- }
- }
+ /* Test O_EXCL. */
+ if((flags & O_CREAT) && (flags & O_EXCL))
+ {
+ rc = FSUSER_CreateFile(NULL, sdmcArchive, FS_makePath(PATH_CHAR, pathptr), 0);
+ if(rc != 0)
+ {
+ r->_errno = rc;
+ if(rc == 0x82044BE)
+ r->_errno = EEXIST;
+ if(rc == 0x86044D2)
+ r->_errno = ENOSPC;
+ return -1;
+ }
+ }
- /* set attributes */
- /*if(!(mode & S_IWUSR))
- attributes |= FS_ATTRIBUTE_READONLY;*/
+ /* set attributes */
+ /*if(!(mode & S_IWUSR))
+ attributes |= FS_ATTRIBUTE_READONLY;*/
- /* open the file */
- rc = FSUSER_OpenFile(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr),
- sdmc_flags, attributes);
- if(rc == 0)
- {
- if((flags & O_ACCMODE) != O_RDONLY && (flags & O_TRUNC))
- {
- rc = FSFILE_SetSize(fd, 0);
- if(rc != 0)
- {
- FSFILE_Close(fd);
- r->_errno = rc;
- return -1;
- }
- }
- file->fd = fd;
- file->flags = (flags & (O_ACCMODE|O_APPEND|O_SYNC));
- file->offset = 0;
- return 0;
- }
+ /* open the file */
+ rc = FSUSER_OpenFile(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr),
+ sdmc_flags, attributes);
+ if(rc == 0)
+ {
+ if((flags & O_ACCMODE) != O_RDONLY && (flags & O_TRUNC))
+ {
+ rc = FSFILE_SetSize(fd, 0);
+ if(rc != 0)
+ {
+ FSFILE_Close(fd);
+ r->_errno = rc;
+ return -1;
+ }
+ }
+ file->fd = fd;
+ file->flags = (flags & (O_ACCMODE|O_APPEND|O_SYNC));
+ file->offset = 0;
+ return 0;
+ }
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Close an open file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] fd Pointer to sdmc_file_t
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] fd Pointer to sdmc_file_t
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_close(struct _reent *r,
- int fd)
+ int fd)
{
- Result rc;
+ Result rc;
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fd;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fd;
- rc = FSFILE_Close(file->fd);
- if(rc == 0)
- return 0;
+ rc = FSFILE_Close(file->fd);
+ if(rc == 0)
+ return 0;
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Write to an open file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in,out] fd Pointer to sdmc_file_t
- * @param[in] ptr Pointer to data to write
- * @param[in] len Length of data to write
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in,out] fd Pointer to sdmc_file_t
+ * @param[in] ptr Pointer to data to write
+ * @param[in] len Length of data to write
*
- * @returns number of bytes written
- * @returns -1 for error
+ * @returns number of bytes written
+ * @returns -1 for error
*/
static ssize_t
sdmc_write(struct _reent *r,
- int fd,
- const char *ptr,
- size_t len)
+ int fd,
+ const char *ptr,
+ size_t len)
{
- Result rc;
- u32 bytes;
- u32 sync = 0;
- u64 offset;
+ Result rc;
+ u32 bytes;
+ u32 sync = 0;
+ u64 offset;
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fd;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fd;
- /* check that the file was opened with write access */
- if((file->flags & O_ACCMODE) == O_RDONLY)
- {
- r->_errno = EBADF;
- return -1;
- }
+ /* check that the file was opened with write access */
+ if((file->flags & O_ACCMODE) == O_RDONLY)
+ {
+ r->_errno = EBADF;
+ return -1;
+ }
- /* check if this is synchronous or not */
- if(file->flags & O_SYNC)
- sync = 0x10001;
+ /* check if this is synchronous or not */
+ if(file->flags & O_SYNC)
+ sync = 0x10001;
- /* initialize offset */
- offset = file->offset;
- if(file->flags & O_APPEND)
- {
- /* append means write from the end of the file */
- rc = FSFILE_GetSize(file->fd, &offset);
- if(rc != 0)
- {
- r->_errno = rc;
- return -1;
- }
- }
+ /* initialize offset */
+ offset = file->offset;
+ if(file->flags & O_APPEND)
+ {
+ /* append means write from the end of the file */
+ rc = FSFILE_GetSize(file->fd, &offset);
+ if(rc != 0)
+ {
+ r->_errno = rc;
+ return -1;
+ }
+ }
- /* TODO: Copy to internal buffer and write in chunks.
- * You cannot write from read-only memory.
- */
+ /* TODO: Copy to internal buffer and write in chunks.
+ * You cannot write from read-only memory.
+ */
- /* write the data */
- rc = FSFILE_Write(file->fd, &bytes, offset, (u32*)ptr, (u32)len, sync);
- if(rc == 0)
- {
- /* update current file offset; if O_APPEND, this moves it to the
- * new end-of-file
- */
- file->offset = offset + bytes;
- return (ssize_t)bytes;
- }
+ /* write the data */
+ rc = FSFILE_Write(file->fd, &bytes, offset, (u32*)ptr, (u32)len, sync);
+ if(rc == 0)
+ {
+ /* update current file offset; if O_APPEND, this moves it to the
+ * new end-of-file
+ */
+ file->offset = offset + bytes;
+ return (ssize_t)bytes;
+ }
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Read from an open file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in,out] fd Pointer to sdmc_file_t
- * @param[out] ptr Pointer to buffer to read into
- * @param[in] len Length of data to read
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in,out] fd Pointer to sdmc_file_t
+ * @param[out] ptr Pointer to buffer to read into
+ * @param[in] len Length of data to read
*
- * @returns number of bytes read
- * @returns -1 for error
+ * @returns number of bytes read
+ * @returns -1 for error
*/
static ssize_t
sdmc_read(struct _reent *r,
- int fd,
- char *ptr,
- size_t len)
+ int fd,
+ char *ptr,
+ size_t len)
{
- Result rc;
- u32 bytes;
+ Result rc;
+ u32 bytes;
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fd;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fd;
- /* check that the file was opened with read access */
- if((file->flags & O_ACCMODE) == O_WRONLY)
- {
- r->_errno = EBADF;
- return -1;
- }
+ /* check that the file was opened with read access */
+ if((file->flags & O_ACCMODE) == O_WRONLY)
+ {
+ r->_errno = EBADF;
+ return -1;
+ }
- /* read the data */
- rc = FSFILE_Read(file->fd, &bytes, file->offset, (u32*)ptr, (u32)len);
- if(rc == 0)
- {
- /* update current file offset */
- file->offset += bytes;
- return (ssize_t)bytes;
- }
+ /* read the data */
+ rc = FSFILE_Read(file->fd, &bytes, file->offset, (u32*)ptr, (u32)len);
+ if(rc == 0)
+ {
+ /* update current file offset */
+ file->offset += bytes;
+ return (ssize_t)bytes;
+ }
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Update an open file's current offset
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in,out] fd Pointer to sdmc_file_t
- * @param[in] pos Offset to seek to
- * @param[in] whence Where to seek from
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in,out] fd Pointer to sdmc_file_t
+ * @param[in] pos Offset to seek to
+ * @param[in] whence Where to seek from
*
- * @returns new offset for success
- * @returns -1 for error
+ * @returns new offset for success
+ * @returns -1 for error
*/
static off_t
sdmc_seek(struct _reent *r,
- int fd,
- off_t pos,
- int whence)
+ int fd,
+ off_t pos,
+ int whence)
{
- Result rc;
- u64 offset;
+ Result rc;
+ u64 offset;
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fd;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fd;
- /* find the offset to see from */
- switch(whence)
- {
- /* set absolute position; start offset is 0 */
- case SEEK_SET:
- offset = 0;
- break;
+ /* find the offset to see from */
+ switch(whence)
+ {
+ /* set absolute position; start offset is 0 */
+ case SEEK_SET:
+ offset = 0;
+ break;
- /* set position relative to the current position */
- case SEEK_CUR:
- offset = file->offset;
- break;
+ /* set position relative to the current position */
+ case SEEK_CUR:
+ offset = file->offset;
+ break;
- /* set position relative to the end of the file */
- case SEEK_END:
- rc = FSFILE_GetSize(file->fd, &offset);
- if(rc != 0)
- {
- r->_errno = rc;
- return -1;
- }
- break;
+ /* set position relative to the end of the file */
+ case SEEK_END:
+ rc = FSFILE_GetSize(file->fd, &offset);
+ if(rc != 0)
+ {
+ r->_errno = rc;
+ return -1;
+ }
+ break;
- /* an invalid option was provided */
- default:
- r->_errno = EINVAL;
- return -1;
- }
+ /* an invalid option was provided */
+ default:
+ r->_errno = EINVAL;
+ return -1;
+ }
- /* TODO: A better check that prevents overflow. */
- if(pos < 0 && offset < -pos)
- {
- /* don't allow seek to before the beginning of the file */
- r->_errno = EINVAL;
- return -1;
- }
+ /* TODO: A better check that prevents overflow. */
+ if(pos < 0 && offset < -pos)
+ {
+ /* don't allow seek to before the beginning of the file */
+ r->_errno = EINVAL;
+ return -1;
+ }
- /* update the current offset */
- file->offset = offset + pos;
- return file->offset;
+ /* update the current offset */
+ file->offset = offset + pos;
+ return file->offset;
}
/*! Get file stats from an open file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] fd Pointer to sdmc_file_t
- * @param[out] st Pointer to file stats to fill
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] fd Pointer to sdmc_file_t
+ * @param[out] st Pointer to file stats to fill
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_fstat(struct _reent *r,
- int fd,
- struct stat *st)
+ int fd,
+ struct stat *st)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Get file stats
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] file Path to file
- * @param[out] st Pointer to file stats to fill
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] file Path to file
+ * @param[out] st Pointer to file stats to fill
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
-sdmc_stat(struct _reent *r,
- const char *file,
- struct stat *st)
+sdmc_stat(struct _reent *r,
+ const char *file,
+ struct stat *st)
{
- Handle fd;
- Result rc;
- const char *pathptr = NULL;
+ Handle fd;
+ Result rc;
+ const char *pathptr = NULL;
- pathptr = sdmc_fixpath(file);
+ pathptr = sdmc_fixpath(file);
- if(pathptr==NULL)
- {
- r->_errno=EINVAL;
- return -1;
- }
+ if(pathptr==NULL)
+ {
+ r->_errno=EINVAL;
+ return -1;
+ }
- if( (rc = FSUSER_OpenFile(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr),
- FS_OPEN_READ, FS_ATTRIBUTE_NONE))==0)
- {
- u64 tmpsize = 0;
- rc = FSFILE_GetSize(fd, &tmpsize);
+ if( (rc = FSUSER_OpenFile(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr),
+ FS_OPEN_READ, FS_ATTRIBUTE_NONE))==0)
+ {
+ u64 tmpsize = 0;
+ rc = FSFILE_GetSize(fd, &tmpsize);
- FSFILE_Close(fd);
+ FSFILE_Close(fd);
- if(rc==0)
- {
- memset(st, 0, sizeof(struct stat));
- st->st_size = (off_t)tmpsize;
- st->st_nlink = 1;
- st->st_uid = 1;
- st->st_gid = 2;
- st->st_mode = S_IFREG | S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH;
- return 0;
- }
- }
- if( (rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr))) == 0 )
- {
- memset(st, 0, sizeof(struct stat));
- st->st_nlink = 1;
- st->st_uid = 1;
- st->st_gid = 2;
- st->st_mode = S_IFDIR | S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH;
- return 0;
- }
+ if(rc==0)
+ {
+ memset(st, 0, sizeof(struct stat));
+ st->st_size = (off_t)tmpsize;
+ st->st_nlink = 1;
+ st->st_uid = 1;
+ st->st_gid = 2;
+ st->st_mode = S_IFREG | S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH;
+ return 0;
+ }
+ }
+ if( (rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr))) == 0 )
+ {
+ memset(st, 0, sizeof(struct stat));
+ st->st_nlink = 1;
+ st->st_uid = 1;
+ st->st_gid = 2;
+ st->st_mode = S_IFDIR | S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH;
+ return 0;
+ }
- r->_errno = EBADF;
- return -1;
+ r->_errno = EBADF;
+ return -1;
}
/*! Hard link a file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] existing Path of file to link
- * @param[in] newLink Path of new link
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] existing Path of file to link
+ * @param[in] newLink Path of new link
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_link(struct _reent *r,
- const char *existing,
- const char *newLink)
+ const char *existing,
+ const char *newLink)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Unlink a file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] name Path of file to unlink
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] name Path of file to unlink
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_unlink(struct _reent *r,
- const char *name)
+ const char *name)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Change current working directory
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] name Path to new working directory
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] name Path to new working directory
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_chdir(struct _reent *r,
- const char *name)
+ const char *name)
{
- Handle fd;
- Result rc;
- const char *pathptr = NULL;
+ Handle fd;
+ Result rc;
+ const char *pathptr = NULL;
- pathptr = sdmc_fixpath(name);
+ pathptr = sdmc_fixpath(name);
- if(pathptr==NULL)
- {
- r->_errno=EINVAL;
- return -1;
- }
+ if(pathptr==NULL)
+ {
+ r->_errno=EINVAL;
+ return -1;
+ }
- rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
- if(rc == 0)
- {
- FSDIR_Close(fd);
- strncpy(__cwd,pathptr,PATH_MAX);
- }
- else
- {
- r->_errno=EINVAL;
- return -1;
- }
+ rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
+ if(rc == 0)
+ {
+ FSDIR_Close(fd);
+ strncpy(__cwd,pathptr,PATH_MAX);
+ }
+ else
+ {
+ r->_errno=EINVAL;
+ return -1;
+ }
- return 0;
+ return 0;
}
/*! Rename a file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] oldName Path to rename from
- * @param[in] newName Path to rename to
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] oldName Path to rename from
+ * @param[in] newName Path to rename to
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_rename(struct _reent *r,
- const char *oldName,
- const char *newName)
+ const char *oldName,
+ const char *newName)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Create a directory
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] path Path of directory to create
- * @param[in] mode Permissions of created directory
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] path Path of directory to create
+ * @param[in] mode Permissions of created directory
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_mkdir(struct _reent *r,
- const char *path,
- int mode)
+ const char *path,
+ int mode)
{
- Result rc;
- const char *pathptr = NULL;
+ Result rc;
+ const char *pathptr = NULL;
- pathptr = sdmc_fixpath(path);
+ pathptr = sdmc_fixpath(path);
- if(pathptr==NULL)
- {
- r->_errno=EINVAL;
- return -1;
- }
+ if(pathptr==NULL)
+ {
+ r->_errno=EINVAL;
+ return -1;
+ }
- /* TODO: Use mode to set directory attributes. */
+ /* TODO: Use mode to set directory attributes. */
- rc = FSUSER_CreateDirectory(NULL, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
- if(rc == 0)
- return 0;
+ rc = FSUSER_CreateDirectory(NULL, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
+ if(rc == 0)
+ return 0;
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Open a directory
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] dirState Pointer to open directory state
- * @param[in] path Path of directory to open
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] dirState Pointer to open directory state
+ * @param[in] path Path of directory to open
*
- * @returns dirState for success
- * @returns NULL for error
+ * @returns dirState for success
+ * @returns NULL for error
*/
static DIR_ITER*
sdmc_diropen(struct _reent *r,
- DIR_ITER *dirState,
- const char *path)
+ DIR_ITER *dirState,
+ const char *path)
{
- Handle fd;
- Result rc;
- const char *pathptr = NULL;
+ Handle fd;
+ Result rc;
+ const char *pathptr = NULL;
- pathptr = sdmc_fixpath(path);
+ pathptr = sdmc_fixpath(path);
- if(pathptr==NULL)
- {
- r->_errno=EINVAL;
- return NULL;
- }
+ if(pathptr==NULL)
+ {
+ r->_errno=EINVAL;
+ return NULL;
+ }
- /* get pointer to our data */
- sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
+ /* get pointer to our data */
+ sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
- /* open the directory */
- rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
- if(rc == 0)
- {
- dir->fd = fd;
- memset(&dir->entry_data, 0, sizeof(dir->entry_data));
- return dirState;
- }
+ /* open the directory */
+ rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
+ if(rc == 0)
+ {
+ dir->fd = fd;
+ memset(&dir->entry_data, 0, sizeof(dir->entry_data));
+ return dirState;
+ }
- r->_errno = rc;
- return NULL;
+ r->_errno = rc;
+ return NULL;
}
/*! Reset an open directory to its intial state
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] dirState Pointer to open directory state
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] dirState Pointer to open directory state
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_dirreset(struct _reent *r,
- DIR_ITER *dirState)
+ DIR_ITER *dirState)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Fetch the next entry of an open directory
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] dirState Pointer to open directory state
- * @param[out] filename Buffer to store entry name
- * @param[out] filestat Buffer to store entry attributes
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] dirState Pointer to open directory state
+ * @param[out] filename Buffer to store entry name
+ * @param[out] filestat Buffer to store entry attributes
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_dirnext(struct _reent *r,
- DIR_ITER *dirState,
- char *filename,
- struct stat *filestat)
+ DIR_ITER *dirState,
+ char *filename,
+ struct stat *filestat)
{
- Result rc;
- u32 entries;
- u16 *name;
+ Result rc;
+ u32 entries;
+ u16 *name;
- /* get pointer to our data */
- sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
+ /* get pointer to our data */
+ sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
- /* fetch the next entry */
- rc = FSDIR_Read(dir->fd, &entries, 1, &dir->entry_data);
- if(rc == 0)
- {
- if(entries == 0)
- {
- /* there are no more entries; ENOENT signals end-of-directory */
- r->_errno = ENOENT;
- return -1;
- }
+ /* fetch the next entry */
+ rc = FSDIR_Read(dir->fd, &entries, 1, &dir->entry_data);
+ if(rc == 0)
+ {
+ if(entries == 0)
+ {
+ /* there are no more entries; ENOENT signals end-of-directory */
+ r->_errno = ENOENT;
+ return -1;
+ }
- /* fill in the stat info */
- filestat->st_ino = 0;
- if(dir->entry_data.isDirectory)
- filestat->st_mode = S_IFDIR;
- else
- filestat->st_mode = S_IFREG;
+ /* fill in the stat info */
+ filestat->st_ino = 0;
+ if(dir->entry_data.isDirectory)
+ filestat->st_mode = S_IFDIR;
+ else
+ filestat->st_mode = S_IFREG;
- /* copy the name */
- name = dir->entry_data.name;
- while(*name)
- *filename++ = *name++;
- *filename = 0;
+ /* copy the name */
+ name = dir->entry_data.name;
+ while(*name)
+ *filename++ = *name++;
+ *filename = 0;
- return 0;
- }
+ return 0;
+ }
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Close an open directory
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] dirState Pointer to open directory state
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] dirState Pointer to open directory state
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_dirclose(struct _reent *r,
- DIR_ITER *dirState)
+ DIR_ITER *dirState)
{
- Result rc;
+ Result rc;
- /* get pointer to our data */
- sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
+ /* get pointer to our data */
+ sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
- /* close the directory */
- rc = FSDIR_Close(dir->fd);
- if(rc == 0)
- return 0;
+ /* close the directory */
+ rc = FSDIR_Close(dir->fd);
+ if(rc == 0)
+ return 0;
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Get filesystem statistics
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] path Path to filesystem to get statistics of
- * @param[out] buf Buffer to fill
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] path Path to filesystem to get statistics of
+ * @param[out] buf Buffer to fill
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
-sdmc_statvfs(struct _reent *r,
- const char *path,
- struct statvfs *buf)
+sdmc_statvfs(struct _reent *r,
+ const char *path,
+ struct statvfs *buf)
{
- Result rc;
- u32 clusterSize, numClusters, freeClusters;
- u8 writable = 0;
+ Result rc;
+ u32 clusterSize, numClusters, freeClusters;
+ u8 writable = 0;
- rc = FSUSER_GetSdmcArchiveResource(NULL,
- NULL,
- &clusterSize,
- &numClusters,
- &freeClusters);
+ rc = FSUSER_GetSdmcArchiveResource(NULL,
+ NULL,
+ &clusterSize,
+ &numClusters,
+ &freeClusters);
- if(rc == 0)
- {
- buf->f_bsize = clusterSize;
- buf->f_frsize = clusterSize;
- buf->f_blocks = numClusters;
- buf->f_bfree = freeClusters;
- buf->f_bavail = freeClusters;
- buf->f_files = 0; //??? how to get
- buf->f_ffree = freeClusters;
- buf->f_favail = freeClusters;
- buf->f_fsid = 0; //??? how to get
- buf->f_flag = ST_NOSUID;
- buf->f_namemax = 0; //??? how to get
+ if(rc == 0)
+ {
+ buf->f_bsize = clusterSize;
+ buf->f_frsize = clusterSize;
+ buf->f_blocks = numClusters;
+ buf->f_bfree = freeClusters;
+ buf->f_bavail = freeClusters;
+ buf->f_files = 0; //??? how to get
+ buf->f_ffree = freeClusters;
+ buf->f_favail = freeClusters;
+ buf->f_fsid = 0; //??? how to get
+ buf->f_flag = ST_NOSUID;
+ buf->f_namemax = 0; //??? how to get
- rc = FSUSER_IsSdmcWritable(NULL, &writable);
- if(rc != 0 || !writable)
- buf->f_flag |= ST_RDONLY;
+ rc = FSUSER_IsSdmcWritable(NULL, &writable);
+ if(rc != 0 || !writable)
+ buf->f_flag |= ST_RDONLY;
- return 0;
- }
+ return 0;
+ }
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Truncate an open file
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] fd Pointer to sdmc_file_t
- * @param[in] len Length to truncate file to
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] fd Pointer to sdmc_file_t
+ * @param[in] len Length to truncate file to
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_ftruncate(struct _reent *r,
- int fd,
- off_t len)
+ int fd,
+ off_t len)
{
- Result rc;
+ Result rc;
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fd;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fd;
- /* make sure length is non-negative */
- if(len < 0)
- {
- r->_errno = EINVAL;
- return -1;
- }
+ /* make sure length is non-negative */
+ if(len < 0)
+ {
+ r->_errno = EINVAL;
+ return -1;
+ }
- /* set the new file size */
- rc = FSFILE_SetSize(file->fd, len);
- if(rc == 0)
- return 0;
+ /* set the new file size */
+ rc = FSFILE_SetSize(file->fd, len);
+ if(rc == 0)
+ return 0;
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Synchronize a file to media
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] fd Pointer to sdmc_file_t
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] fd Pointer to sdmc_file_t
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_fsync(struct _reent *r,
- int fd)
+ int fd)
{
- Result rc;
+ Result rc;
- /* get pointer to our data */
- sdmc_file_t *file = (sdmc_file_t*)fd;
+ /* get pointer to our data */
+ sdmc_file_t *file = (sdmc_file_t*)fd;
- rc = FSFILE_Flush(file->fd);
- if(rc == 0)
- return 0;
+ rc = FSFILE_Flush(file->fd);
+ if(rc == 0)
+ return 0;
- r->_errno = rc;
- return -1;
+ r->_errno = rc;
+ return -1;
}
/*! Change a file's mode
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] path Path to file to update
- * @param[in] mode New mode to set
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] path Path to file to update
+ * @param[in] mode New mode to set
*
- * @returns 0 for success
- * @returns -1 for error
+ * @returns 0 for success
+ * @returns -1 for error
*/
static int
sdmc_chmod(struct _reent *r,
- const char *path,
- mode_t mode)
+ const char *path,
+ mode_t mode)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
/*! Change an open file's mode
*
- * @param[in,out] r newlib reentrancy struct
- * @param[in] fd Pointer to sdmc_file_t
- * @param[in] mode New mode to set
+ * @param[in,out] r newlib reentrancy struct
+ * @param[in] fd Pointer to sdmc_file_t
+ * @param[in] mode New mode to set
*
- * @returns 0 for success
- * @returns -1 for failure
+ * @returns 0 for success
+ * @returns -1 for failure
*/
static int
sdmc_fchmod(struct _reent *r,
- int fd,
- mode_t mode)
+ int fd,
+ mode_t mode)
{
- r->_errno = ENOSYS;
- return -1;
+ r->_errno = ENOSYS;
+ return -1;
}
diff --git a/libctru/source/services/fs.c b/libctru/source/services/fs.c
index 2c610b3..8338f06 100644
--- a/libctru/source/services/fs.c
+++ b/libctru/source/services/fs.c
@@ -6,9 +6,9 @@
/*! @internal
*
- * @file fs.c
+ * @file fs.c
*
- * Filesystem Services
+ * Filesystem Services
*/
/*! FSUSER handle */
@@ -19,23 +19,23 @@ Handle __get_handle_from_list(char* name);
/*! Create an FS_path from a type and data pointer.
*
- * @param[in] type Path type.
- * @param[in] path Pointer to path data.
+ * @param[in] type Path type.
+ * @param[in] path Pointer to path data.
*
- * @returns FS_path
+ * @returns FS_path
*
- * @sa FS_pathType
+ * @sa FS_pathType
*/
FS_path
FS_makePath(FS_pathType type,
- const char *path)
+ const char *path)
{
return (FS_path){type, strlen(path)+1, (const u8*)path};
}
/*! Initialize FS service
*
- * @returns error
+ * @returns error
*/
static bool fsInitialised = false;
@@ -57,7 +57,7 @@ fsInit(void)
/*! Deinitialize FS service
*
- * @returns error
+ * @returns error
*/
Result
fsExit(void)
@@ -71,27 +71,27 @@ fsExit(void)
/*! Initialize FS service handle
*
- * If @a handle is NULL, this initializes @ref fsuHandle.
+ * If @a handle is NULL, this initializes @ref fsuHandle.
*
- * @param[in] handle fs:USER service handle
+ * @param[in] handle fs:USER service handle
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08010002]
- * 1 | 0x20 (ProcessID header)
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08010002]
+ * 1 | 0x20 (ProcessID header)
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
FSUSER_Initialize(Handle* handle)
@@ -118,53 +118,53 @@ FSUSER_Initialize(Handle* handle)
/*! Open a file
*
- * @param[in] handle fs:USER handle
- * @param[out] out Output handle
- * @param[in] archive Open archive
- * @param[in] fileLowPath File path
- * @param[in] openFlags Open flags
- * @param[in] attributes Create attributes
+ * @param[in] handle fs:USER handle
+ * @param[out] out Output handle
+ * @param[in] archive Open archive
+ * @param[in] fileLowPath File path
+ * @param[in] openFlags Open flags
+ * @param[in] attributes Create attributes
*
- * @note This requires @a archive to have been opened
+ * @note This requires @a archive to have been opened
*
- * @returns error
+ * @returns error
*
- * @sa fs_open_flags
- * @sa fs_create_attributes
+ * @sa fs_open_flags
+ * @sa fs_create_attributes
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x080201C2]
- * 1 | Transaction (usually 0)
- * 2 | archive.handleLow
- * 3 | archive.handleHigh
- * 4 | fileLowPath.type
- * 5 | fileLowPath.size
- * 6 | openFlags
- * 7 | attributes
- * 8 | (fileLowPath.size << 14) \| 0x2
- * 9 | fileLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x080201C2]
+ * 1 | Transaction (usually 0)
+ * 2 | archive.handleLow
+ * 3 | archive.handleHigh
+ * 4 | fileLowPath.type
+ * 5 | fileLowPath.size
+ * 6 | openFlags
+ * 7 | attributes
+ * 8 | (fileLowPath.size << 14) \| 0x2
+ * 9 | fileLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | ???
- * 3 | File handle
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | ???
+ * 3 | File handle
*/
Result
-FSUSER_OpenFile(Handle *handle,
- Handle *out,
- FS_archive archive,
- FS_path fileLowPath,
- u32 openFlags,
- u32 attributes)
+FSUSER_OpenFile(Handle *handle,
+ Handle *out,
+ FS_archive archive,
+ FS_path fileLowPath,
+ u32 openFlags,
+ u32 attributes)
{
if(!handle)
handle = &fsuHandle;
@@ -194,56 +194,56 @@ FSUSER_OpenFile(Handle *handle,
/*! Open a file
*
- * @param[in] handle fs:USER handle
- * @param[out] out Output handle
- * @param[in] archive Open archive
- * @param[in] fileLowPath File path
- * @param[in] openFlags Open flags
- * @param[in] attributes Create attributes
+ * @param[in] handle fs:USER handle
+ * @param[out] out Output handle
+ * @param[in] archive Open archive
+ * @param[in] fileLowPath File path
+ * @param[in] openFlags Open flags
+ * @param[in] attributes Create attributes
*
- * @note This does not require @a archive to have been opened
+ * @note This does not require @a archive to have been opened
*
- * @returns error
+ * @returns error
*
- * @sa fs_open_flags
- * @sa fs_create_attributes
+ * @sa fs_open_flags
+ * @sa fs_create_attributes
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08030204]
- * 1 | Transaction (usually 0)
- * 2 | archive.id
- * 3 | archive.lowPath.type
- * 4 | archive.lowPath.Size
- * 5 | fileLowPath.type
- * 6 | fileLowPath.size
- * 7 | openFlags
- * 8 | attributes
- * 9 | (archive.lowPath.size << 14 \| 0x802
- * 10 | archive.lowPath.data
- * 11 | (fileLowPath.size << 14) \| 0x2
- * 12 | fileLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08030204]
+ * 1 | Transaction (usually 0)
+ * 2 | archive.id
+ * 3 | archive.lowPath.type
+ * 4 | archive.lowPath.Size
+ * 5 | fileLowPath.type
+ * 6 | fileLowPath.size
+ * 7 | openFlags
+ * 8 | attributes
+ * 9 | (archive.lowPath.size << 14 \| 0x802
+ * 10 | archive.lowPath.data
+ * 11 | (fileLowPath.size << 14) \| 0x2
+ * 12 | fileLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | ???
- * 3 | File handle
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | ???
+ * 3 | File handle
*/
Result
-FSUSER_OpenFileDirectly(Handle *handle,
- Handle *out,
- FS_archive archive,
- FS_path fileLowPath,
- u32 openFlags,
- u32 attributes)
+FSUSER_OpenFileDirectly(Handle *handle,
+ Handle *out,
+ FS_archive archive,
+ FS_path fileLowPath,
+ u32 openFlags,
+ u32 attributes)
{
if(!handle)
handle = &fsuHandle;
@@ -276,38 +276,38 @@ FSUSER_OpenFileDirectly(Handle *handle,
/*! Delete a file
*
- * @param[in] handle fs:USER handle
- * @param[in] archive Open archive
- * @param[in] fileLowPath File path
+ * @param[in] handle fs:USER handle
+ * @param[in] archive Open archive
+ * @param[in] fileLowPath File path
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08040142]
- * 1 | 0
- * 2 | archive.handleLow
- * 3 | archive.handleHigh
- * 4 | fileLowPath.type
- * 5 | fileLowPath.size
- * 6 | (fileLowPath.size << 14) \| 0x2
- * 7 | fileLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08040142]
+ * 1 | 0
+ * 2 | archive.handleLow
+ * 3 | archive.handleHigh
+ * 4 | fileLowPath.type
+ * 5 | fileLowPath.size
+ * 6 | (fileLowPath.size << 14) \| 0x2
+ * 7 | fileLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_DeleteFile(Handle *handle,
- FS_archive archive,
- FS_path fileLowPath)
+FSUSER_DeleteFile(Handle *handle,
+ FS_archive archive,
+ FS_path fileLowPath)
{
if(!handle)
handle = &fsuHandle;
@@ -332,48 +332,48 @@ FSUSER_DeleteFile(Handle *handle,
/*! Renames or moves a file.
*
- * @param[in] handle fs:USER handle
- * @param[in] srcArchive Open archive of source
- * @param[in] srcFileLowPath File path to source
- * @param[in] destArchive Open archive of destination
- * @param[in] destFileLowPath File path to destination
+ * @param[in] handle fs:USER handle
+ * @param[in] srcArchive Open archive of source
+ * @param[in] srcFileLowPath File path to source
+ * @param[in] destArchive Open archive of destination
+ * @param[in] destFileLowPath File path to destination
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08050244]
- * 1 | 0
- * 2 | srcArchive.handleLow
- * 3 | srcArchive.handleHigh
- * 4 | srcFileLowPath.type
- * 5 | srcFileLowPath.size
- * 6 | destArchive.handleLow
- * 7 | destArchive.handleHigh
- * 8 | destFileLowPath.type
- * 9 | destFileLowPath.size
- * 10 | (srcFileLowPath.size << 14) \| 0x402
- * 11 | srcFileLowPath.data
- * 12 | (destFileLowPath.size << 14) \| 0x802
- * 13 | destFileLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08050244]
+ * 1 | 0
+ * 2 | srcArchive.handleLow
+ * 3 | srcArchive.handleHigh
+ * 4 | srcFileLowPath.type
+ * 5 | srcFileLowPath.size
+ * 6 | destArchive.handleLow
+ * 7 | destArchive.handleHigh
+ * 8 | destFileLowPath.type
+ * 9 | destFileLowPath.size
+ * 10 | (srcFileLowPath.size << 14) \| 0x402
+ * 11 | srcFileLowPath.data
+ * 12 | (destFileLowPath.size << 14) \| 0x802
+ * 13 | destFileLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_RenameFile(Handle *handle,
- FS_archive srcArchive,
- FS_path srcFileLowPath,
- FS_archive destArchive,
- FS_path destFileLowPath)
+FSUSER_RenameFile(Handle *handle,
+ FS_archive srcArchive,
+ FS_path srcFileLowPath,
+ FS_archive destArchive,
+ FS_path destFileLowPath)
{
if(!handle)
handle = &fsuHandle;
@@ -404,38 +404,38 @@ FSUSER_RenameFile(Handle *handle,
/*! Delete a directory
*
- * @param[in] handle fs:USER handle
- * @param[in] archive Open archive
- * @param[in] dirLowPath Directory path
+ * @param[in] handle fs:USER handle
+ * @param[in] archive Open archive
+ * @param[in] dirLowPath Directory path
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08060142]
- * 1 | 0
- * 2 | archive.handleLow
- * 3 | archive.handleHigh
- * 4 | dirLowPath.type
- * 5 | dirLowPath.size
- * 6 | (dirLowPath.size << 14) \| 0x2
- * 7 | dirLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08060142]
+ * 1 | 0
+ * 2 | archive.handleLow
+ * 3 | archive.handleHigh
+ * 4 | dirLowPath.type
+ * 5 | dirLowPath.size
+ * 6 | (dirLowPath.size << 14) \| 0x2
+ * 7 | dirLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_DeleteDirectory(Handle *handle,
- FS_archive archive,
- FS_path dirLowPath)
+FSUSER_DeleteDirectory(Handle *handle,
+ FS_archive archive,
+ FS_path dirLowPath)
{
if(!handle)
handle = &fsuHandle;
@@ -467,59 +467,59 @@ FSUSER_DeleteDirectoryRecursively(void)
/*! Create a File
*
- * @param[in] handle fs:USER handle
- * @param[in] archive Open archive
- * @param[in] fileLowPath File path
- * @param[in] fileSize Size of new file in bytes
+ * @param[in] handle fs:USER handle
+ * @param[in] archive Open archive
+ * @param[in] fileLowPath File path
+ * @param[in] fileSize Size of new file in bytes
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08060142]
- * 1 | 0
- * 2 | archive.handleLow
- * 3 | archive.handleHigh
- * 4 | fileLowPath.type
- * 5 | fileLowPath.size
- * 6 | 0
- * 7 | fileSize
- * 8 | 0
- * 9 | (fileLowPath.size << 14) \| 0x2
- * 10 | fileLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08060142]
+ * 1 | 0
+ * 2 | archive.handleLow
+ * 3 | archive.handleHigh
+ * 4 | fileLowPath.type
+ * 5 | fileLowPath.size
+ * 6 | 0
+ * 7 | fileSize
+ * 8 | 0
+ * 9 | (fileLowPath.size << 14) \| 0x2
+ * 10 | fileLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_CreateFile(Handle* handle,
- FS_archive archive,
- FS_path fileLowPath,
- u32 fileSize)
+FSUSER_CreateFile(Handle* handle,
+ FS_archive archive,
+ FS_path fileLowPath,
+ u32 fileSize)
{
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer();
- cmdbuf[0] = 0x08080202;
- cmdbuf[1] = 0;
- cmdbuf[2] = archive.handleLow;
- cmdbuf[3] = archive.handleHigh;
- cmdbuf[4] = fileLowPath.type;
- cmdbuf[5] = fileLowPath.size;
- cmdbuf[6] = 0;
- cmdbuf[7] = fileSize;
- cmdbuf[8] = 0;
- cmdbuf[9] = (fileLowPath.size << 14) | 0x2;
+ cmdbuf[0] = 0x08080202;
+ cmdbuf[1] = 0;
+ cmdbuf[2] = archive.handleLow;
+ cmdbuf[3] = archive.handleHigh;
+ cmdbuf[4] = fileLowPath.type;
+ cmdbuf[5] = fileLowPath.size;
+ cmdbuf[6] = 0;
+ cmdbuf[7] = fileSize;
+ cmdbuf[8] = 0;
+ cmdbuf[9] = (fileLowPath.size << 14) | 0x2;
cmdbuf[10] = (u32)fileLowPath.data;
Result ret = 0;
@@ -531,39 +531,39 @@ FSUSER_CreateFile(Handle* handle,
/*! Create a directory
*
- * @param[in] handle fs:USER handle
- * @param[in] archive Open archive
- * @param[in] dirLowPath Directory path to create
+ * @param[in] handle fs:USER handle
+ * @param[in] archive Open archive
+ * @param[in] dirLowPath Directory path to create
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08090182]
- * 1 | 0
- * 2 | archive.handleLow
- * 3 | archive.handleHigh
- * 4 | dirLowPath.type
- * 5 | dirLowPath.size
- * 6 | 0
- * 7 | (dirLowPath.size << 14) \| 0x2
- * 8 | dirLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08090182]
+ * 1 | 0
+ * 2 | archive.handleLow
+ * 3 | archive.handleHigh
+ * 4 | dirLowPath.type
+ * 5 | dirLowPath.size
+ * 6 | 0
+ * 7 | (dirLowPath.size << 14) \| 0x2
+ * 8 | dirLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_CreateDirectory(Handle *handle,
- FS_archive archive,
- FS_path dirLowPath)
+FSUSER_CreateDirectory(Handle *handle,
+ FS_archive archive,
+ FS_path dirLowPath)
{
if(!handle)
handle = &fsuHandle;
@@ -589,48 +589,48 @@ FSUSER_CreateDirectory(Handle *handle,
/*! Renames or moves a directory.
*
- * @param[in] handle fs:USER handle
- * @param[in] srcArchive Open archive of source
- * @param[in] srcDirLowPath Dir path to source
- * @param[in] destArchive Open archive of destination
- * @param[in] destDirLowPath Dir path to destination
+ * @param[in] handle fs:USER handle
+ * @param[in] srcArchive Open archive of source
+ * @param[in] srcDirLowPath Dir path to source
+ * @param[in] destArchive Open archive of destination
+ * @param[in] destDirLowPath Dir path to destination
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x080A0244]
- * 1 | 0
- * 2 | srcArchive.handleLow
- * 3 | srcArchive.handleHigh
- * 4 | srcDirLowPath.type
- * 5 | srcDirLowPath.size
- * 6 | destArchive.handleLow
- * 7 | destArchive.handleHigh
- * 8 | destDirLowPath.type
- * 9 | destDirLowPath.size
- * 10 | (srcDirLowPath.size << 14) \| 0x402
- * 11 | srcDirLowPath.data
- * 12 | (destDirLowPath.size << 14) \| 0x802
- * 13 | destDirLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x080A0244]
+ * 1 | 0
+ * 2 | srcArchive.handleLow
+ * 3 | srcArchive.handleHigh
+ * 4 | srcDirLowPath.type
+ * 5 | srcDirLowPath.size
+ * 6 | destArchive.handleLow
+ * 7 | destArchive.handleHigh
+ * 8 | destDirLowPath.type
+ * 9 | destDirLowPath.size
+ * 10 | (srcDirLowPath.size << 14) \| 0x402
+ * 11 | srcDirLowPath.data
+ * 12 | (destDirLowPath.size << 14) \| 0x802
+ * 13 | destDirLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_RenameDirectory(Handle *handle,
- FS_archive srcArchive,
- FS_path srcDirLowPath,
- FS_archive destArchive,
- FS_path destDirLowPath)
+FSUSER_RenameDirectory(Handle *handle,
+ FS_archive srcArchive,
+ FS_path srcDirLowPath,
+ FS_archive destArchive,
+ FS_path destDirLowPath)
{
if(!handle)
handle = &fsuHandle;
@@ -661,40 +661,40 @@ FSUSER_RenameDirectory(Handle *handle,
/*! Open a directory
*
- * @param[in] handle fs:USER handle
- * @param[out] out Output handle
- * @param[in] archive Open archive
- * @param[in] dirLowPath Directory path
+ * @param[in] handle fs:USER handle
+ * @param[out] out Output handle
+ * @param[in] archive Open archive
+ * @param[in] dirLowPath Directory path
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x080B0102]
- * 1 | archive.handleLow
- * 2 | archive.handleHigh
- * 3 | dirLowPath.type
- * 4 | dirLowPath.size
- * 5 | (dirLowPath.size << 14) \| 0x2
- * 6 | dirLowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x080B0102]
+ * 1 | archive.handleLow
+ * 2 | archive.handleHigh
+ * 3 | dirLowPath.type
+ * 4 | dirLowPath.size
+ * 5 | (dirLowPath.size << 14) \| 0x2
+ * 6 | dirLowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Directory handle
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Directory handle
*/
Result
-FSUSER_OpenDirectory(Handle *handle,
- Handle *out,
- FS_archive archive,
- FS_path dirLowPath)
+FSUSER_OpenDirectory(Handle *handle,
+ Handle *out,
+ FS_archive archive,
+ FS_path dirLowPath)
{
if(!handle)
handle = &fsuHandle;
@@ -721,36 +721,36 @@ FSUSER_OpenDirectory(Handle *handle,
/*! Open an archive
*
- * @param[in] handle fs:USER handle
- * @param[in,out] archive Archive to open
+ * @param[in] handle fs:USER handle
+ * @param[in,out] archive Archive to open
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x080C00C2]
- * 1 | archive->id
- * 2 | archive->lowPath.type
- * 3 | archive->lowPath.size
- * 4 | (archive->lowPath.size << 14) \| 0x2
- * 5 | archive->lowPath.data
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x080C00C2]
+ * 1 | archive->id
+ * 2 | archive->lowPath.type
+ * 3 | archive->lowPath.size
+ * 4 | (archive->lowPath.size << 14) \| 0x2
+ * 5 | archive->lowPath.data
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | archive->handleLow
- * 3 | archive->handleHigh
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | archive->handleLow
+ * 3 | archive->handleHigh
*/
Result
-FSUSER_OpenArchive(Handle *handle,
- FS_archive *archive)
+FSUSER_OpenArchive(Handle *handle,
+ FS_archive *archive)
{
if(!archive)
return -2;
@@ -771,7 +771,7 @@ FSUSER_OpenArchive(Handle *handle,
if((ret = svcSendSyncRequest(*handle)))
return ret;
- archive->handleLow = cmdbuf[2];
+ archive->handleLow = cmdbuf[2];
archive->handleHigh = cmdbuf[3];
return cmdbuf[1];
@@ -780,31 +780,31 @@ FSUSER_OpenArchive(Handle *handle,
/*! Close an open archive
*
- * @param[in] handle fs:USER handle
- * @param[in,out] archive Archive to close
+ * @param[in] handle fs:USER handle
+ * @param[in,out] archive Archive to close
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x080B0102]
- * 1 | archive->handleLow
- * 2 | archive->handleHigh
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x080B0102]
+ * 1 | archive->handleLow
+ * 2 | archive->handleHigh
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
-FSUSER_CloseArchive(Handle *handle,
- FS_archive *archive)
+FSUSER_CloseArchive(Handle *handle,
+ FS_archive *archive)
{
if(!archive)
return -2;
@@ -827,39 +827,39 @@ FSUSER_CloseArchive(Handle *handle,
/*! Get SD FAT information
*
- * @param[in] handle fs:USER handle
- * @param[out] sectorSize Sector size (bytes)
- * @param[out] clusterSize Cluster size (bytes)
- * @param[out] numClusters Total number of clusters
- * @param[out] freeClusters Number of free clusters
+ * @param[in] handle fs:USER handle
+ * @param[out] sectorSize Sector size (bytes)
+ * @param[out] clusterSize Cluster size (bytes)
+ * @param[out] numClusters Total number of clusters
+ * @param[out] freeClusters Number of free clusters
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08140000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08140000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Sector (bytes)
- * 3 | Cluster (bytes)
- * 4 | Partition capacity (clusters)
- * 5 | Free space (clusters)
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Sector (bytes)
+ * 3 | Cluster (bytes)
+ * 4 | Partition capacity (clusters)
+ * 5 | Free space (clusters)
*/
Result
FSUSER_GetSdmcArchiveResource(Handle *handle,
- u32 *sectorSize,
- u32 *clusterSize,
- u32 *numClusters,
- u32 *freeClusters)
+ u32 *sectorSize,
+ u32 *clusterSize,
+ u32 *numClusters,
+ u32 *freeClusters)
{
if(!handle)
handle = &fsuHandle;
@@ -889,30 +889,30 @@ FSUSER_GetSdmcArchiveResource(Handle *handle,
/*! Check if SD card is detected
*
- * @param[in] handle fs:USER handle
- * @param[out] detected Output detected state
+ * @param[in] handle fs:USER handle
+ * @param[out] detected Output detected state
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08170000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08170000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Whether SD is detected
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Whether SD is detected
*/
Result
FSUSER_IsSdmcDetected(Handle *handle,
- u8 *detected)
+ u8 *detected)
{
if(!handle)
handle = &fsuHandle;
@@ -933,30 +933,30 @@ FSUSER_IsSdmcDetected(Handle *handle,
/*! Check if SD card is writable
*
- * @param[in] handle fs:USER handle
- * @param[out] writable Output writable state
+ * @param[in] handle fs:USER handle
+ * @param[out] writable Output writable state
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08180000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08180000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Whether SD is writable
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Whether SD is writable
*/
Result
FSUSER_IsSdmcWritable(Handle *handle,
- u8 *writable)
+ u8 *writable)
{
if(!handle)
handle = &fsuHandle;
@@ -977,24 +977,24 @@ FSUSER_IsSdmcWritable(Handle *handle,
/*! Close an open file
*
- * @param[in] handle Open file handle
+ * @param[in] handle Open file handle
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08080000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08080000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
FSFILE_Close(Handle handle)
@@ -1015,41 +1015,41 @@ FSFILE_Close(Handle handle)
/*! Read data from an open file
*
- * @param[in] handle Open file handle
- * @param[out] bytesRead Number of bytes read
- * @param[in] offset File offset to read from
- * @param[out] buffer Buffer to read into
- * @param[in] size Number of bytes to read
+ * @param[in] handle Open file handle
+ * @param[out] bytesRead Number of bytes read
+ * @param[in] offset File offset to read from
+ * @param[out] buffer Buffer to read into
+ * @param[in] size Number of bytes to read
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x080200C2]
- * 1 | offset (low word)
- * 2 | offset (high word)
- * 3 | size
- * 4 | (size << 4) \| 0xC
- * 5 | buffer
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x080200C2]
+ * 1 | offset (low word)
+ * 2 | offset (high word)
+ * 3 | size
+ * 4 | (size << 4) \| 0xC
+ * 5 | buffer
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Number of bytes read
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Number of bytes read
*/
Result
FSFILE_Read(Handle handle,
- u32 *bytesRead,
- u64 offset,
- void *buffer,
- u32 size)
+ u32 *bytesRead,
+ u64 offset,
+ void *buffer,
+ u32 size)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1072,52 +1072,52 @@ FSFILE_Read(Handle handle,
/*! Write data to an open file
*
- * @param[in] handle Open file handle
- * @param[out] bytesWritten Number of bytes written
- * @param[in] offset File offset to write to
- * @param[in] buffer Buffer to write from
- * @param[in] size Number of bytes to write
- * @param[in] flushFlags Flush flags
+ * @param[in] handle Open file handle
+ * @param[out] bytesWritten Number of bytes written
+ * @param[in] offset File offset to write to
+ * @param[in] buffer Buffer to write from
+ * @param[in] size Number of bytes to write
+ * @param[in] flushFlags Flush flags
*
- * @returns error
+ * @returns error
*
- * @sa fs_write_flush_flags
+ * @sa fs_write_flush_flags
*
- * @warning
- * Using invalid flushFlags can corrupt the archive you're writing to.
+ * @warning
+ * Using invalid flushFlags can corrupt the archive you're writing to.
*
- * @warning
- * Data should not be in read-only memory.
+ * @warning
+ * Data should not be in read-only memory.
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08030102]
- * 1 | offset (low word)
- * 2 | offset (high word)
- * 3 | size
- * 4 | flushFlags
- * 5 | (size << 4) \| 0xA
- * 6 | buffer
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08030102]
+ * 1 | offset (low word)
+ * 2 | offset (high word)
+ * 3 | size
+ * 4 | flushFlags
+ * 5 | (size << 4) \| 0xA
+ * 6 | buffer
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Number of bytes written
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Number of bytes written
*/
Result
-FSFILE_Write(Handle handle,
- u32 *bytesWritten,
- u64 offset,
- const void *buffer,
- u32 size,
- u32 flushFlags)
+FSFILE_Write(Handle handle,
+ u32 *bytesWritten,
+ u64 offset,
+ const void *buffer,
+ u32 size,
+ u32 flushFlags)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1141,31 +1141,31 @@ FSFILE_Write(Handle handle,
/*! Get the size of an open file
*
- * @param[in] handle Open file handle
- * @param[out] size Output size
+ * @param[in] handle Open file handle
+ * @param[out] size Output size
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08040000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08040000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | File size (lower word)
- * 3 | File size (upper word)
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | File size (lower word)
+ * 3 | File size (upper word)
*/
Result
FSFILE_GetSize(Handle handle,
- u64 *size)
+ u64 *size)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1183,31 +1183,31 @@ FSFILE_GetSize(Handle handle,
/*! Set the size of an open file
*
- * @param[in] handle Open file handle
- * @param[in] size Size to set
+ * @param[in] handle Open file handle
+ * @param[in] size Size to set
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08050080]
- * 1 | size (lower word)
- * 2 | size (upper word)
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08050080]
+ * 1 | size (lower word)
+ * 2 | size (upper word)
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
FSFILE_SetSize(Handle handle,
- u64 size)
+ u64 size)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1225,30 +1225,30 @@ FSFILE_SetSize(Handle handle,
/*! Get attributes for an open file
*
- * @param[in] handle Open file handle
- * @param[out] attributes Output attributes
+ * @param[in] handle Open file handle
+ * @param[out] attributes Output attributes
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08060000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08060000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Attributes
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Attributes
*/
Result
FSFILE_GetAttributes(Handle handle,
- u32 *attributes)
+ u32 *attributes)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1266,30 +1266,30 @@ FSFILE_GetAttributes(Handle handle,
/*! Set attributes for an open file
*
- * @param[in] handle Open file handle
- * @param[in] attributes Attributes to set
+ * @param[in] handle Open file handle
+ * @param[in] attributes Attributes to set
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08070040]
- * 1 | Attributes
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08070040]
+ * 1 | Attributes
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
FSFILE_SetAttributes(Handle handle,
- u32 attributes)
+ u32 attributes)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1305,24 +1305,24 @@ FSFILE_SetAttributes(Handle handle,
/*! Flush an open file
*
- * @param[in] handle Open file handle
+ * @param[in] handle Open file handle
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08090000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08090000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
FSFILE_Flush(Handle handle)
@@ -1340,37 +1340,37 @@ FSFILE_Flush(Handle handle)
/*! Read a directory entry from an open directory
*
- * @param[in] handle Open directory handle
- * @param[out] entriesRead Output number of entries read
- * @param[in] entryCount Number of entries to read
- * @param[out] buffer Output buffer
+ * @param[in] handle Open directory handle
+ * @param[out] entriesRead Output number of entries read
+ * @param[in] entryCount Number of entries to read
+ * @param[out] buffer Output buffer
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08010042]
- * 1 | entryCount
- * 2 | ((entrycount*0x228) << 4) \| 0xC
- * 3 | buffer
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08010042]
+ * 1 | entryCount
+ * 2 | ((entrycount*0x228) << 4) \| 0xC
+ * 3 | buffer
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
- * 2 | Number of entries read
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
+ * 2 | Number of entries read
*/
Result
-FSDIR_Read(Handle handle,
- u32 *entriesRead,
- u32 entryCount,
- FS_dirent *buffer)
+FSDIR_Read(Handle handle,
+ u32 *entriesRead,
+ u32 entryCount,
+ FS_dirent *buffer)
{
u32 *cmdbuf = getThreadCommandBuffer();
@@ -1391,24 +1391,24 @@ FSDIR_Read(Handle handle,
/*! Close an open directory
*
- * @param[in] handle Open directory handle
+ * @param[in] handle Open directory handle
*
- * @returns error
+ * @returns error
*
- * @internal
+ * @internal
*
- * #### Request
+ * #### Request
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code [0x08020000]
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code [0x08020000]
*
- * #### Response
+ * #### Response
*
- * Index Word | Description
- * -----------|-------------------------
- * 0 | Header code
- * 1 | Result code
+ * Index Word | Description
+ * ------------|-------------------------
+ * 0 | Header code
+ * 1 | Result code
*/
Result
FSDIR_Close(Handle handle)
diff --git a/libctru/source/services/httpc.c b/libctru/source/services/httpc.c
index a9f1eb9..e9d2bed 100644
--- a/libctru/source/services/httpc.c
+++ b/libctru/source/services/httpc.c
@@ -39,14 +39,14 @@ Result httpcOpenContext(httpcContext *context, char* url, u32 use_defaultproxy)
if(ret!=0) {
HTTPC_CloseContext(__httpc_servhandle, context->httphandle);
return ret;
- }
+ }
ret = HTTPC_InitializeConnectionSession(context->servhandle, context->httphandle);
if(ret!=0) {
HTTPC_CloseContext(__httpc_servhandle, context->httphandle);
svcCloseHandle(context->servhandle);
return ret;
- }
+ }
if(use_defaultproxy==0)return 0;
@@ -55,7 +55,7 @@ Result httpcOpenContext(httpcContext *context, char* url, u32 use_defaultproxy)
HTTPC_CloseContext(__httpc_servhandle, context->httphandle);
svcCloseHandle(context->servhandle);
return ret;
- }
+ }
return 0;
}
diff --git a/libctru/source/services/soc/soc_fcntl.c b/libctru/source/services/soc/soc_fcntl.c
index fcc873b..7fcd53d 100644
--- a/libctru/source/services/soc/soc_fcntl.c
+++ b/libctru/source/services/soc/soc_fcntl.c
@@ -5,8 +5,8 @@
#define O_NONBLOCK_3DS 0x4
-#define ALL_3DS (O_NONBLOCK_3DS)
-#define ALL_FLAGS (O_NONBLOCK)
+#define ALL_3DS (O_NONBLOCK_3DS)
+#define ALL_FLAGS (O_NONBLOCK)
static int from_3ds(int flags)
{
diff --git a/libctru/source/services/soc/soc_gethostbyname.c b/libctru/source/services/soc/soc_gethostbyname.c
index 4932378..e84eda4 100644
--- a/libctru/source/services/soc/soc_gethostbyname.c
+++ b/libctru/source/services/soc/soc_gethostbyname.c
@@ -2,9 +2,9 @@
#include
#define MAX_HOSTENT_RESULTS 16
-static struct hostent SOC_hostent;
-static char *SOC_hostent_results[MAX_HOSTENT_RESULTS+1];
-static char *SOC_hostent_alias = NULL;
+static struct hostent SOC_hostent;
+static char *SOC_hostent_results[MAX_HOSTENT_RESULTS+1];
+static char *SOC_hostent_alias = NULL;
int h_errno = 0;
@@ -30,11 +30,11 @@ struct hostent* gethostbyname(const char *name)
if(( ret = svcSendSyncRequest(SOCU_handle))!=0)return NULL;
cmdbuf[0x100>>2] = saved_threadstorage[0];
- cmdbuf[0x104>>2] = saved_threadstorage[1];
+ cmdbuf[0x104>>2] = saved_threadstorage[1];
ret = (int)cmdbuf[1];
if(ret==0)ret = _net_convert_error(cmdbuf[2]);
- if(ret<0)SOCU_errno = ret;
+ if(ret<0)SOCU_errno = ret;
/* TODO: set h_errno based on SOCU_errno */
if(ret<0)return NULL;
@@ -44,11 +44,11 @@ struct hostent* gethostbyname(const char *name)
if(num_results > MAX_HOSTENT_RESULTS)
num_results = MAX_HOSTENT_RESULTS;
- SOC_hostent.h_name = (char*)outbuf + 8;
- SOC_hostent.h_aliases = &SOC_hostent_alias;
- SOC_hostent.h_addrtype = AF_INET;
- SOC_hostent.h_length = 4;
- SOC_hostent.h_addr_list = SOC_hostent_results;
+ SOC_hostent.h_name = (char*)outbuf + 8;
+ SOC_hostent.h_aliases = &SOC_hostent_alias;
+ SOC_hostent.h_addrtype = AF_INET;
+ SOC_hostent.h_length = 4;
+ SOC_hostent.h_addr_list = SOC_hostent_results;
SOC_hostent_alias = NULL;
diff --git a/libctru/source/services/soc/soc_inet_aton.c b/libctru/source/services/soc/soc_inet_aton.c
index 57f2bd4..15374d7 100644
--- a/libctru/source/services/soc/soc_inet_aton.c
+++ b/libctru/source/services/soc/soc_inet_aton.c
@@ -5,11 +5,11 @@
int inet_aton(const char *cp, struct in_addr *inp)
{
- int base;
- uint32_t val;
- int c;
- char bytes[4];
- size_t num_bytes = 0;
+ int base;
+ uint32_t val;
+ int c;
+ char bytes[4];
+ size_t num_bytes = 0;
c = *cp;
for(;;) {
@@ -31,12 +31,12 @@ int inet_aton(const char *cp, struct in_addr *inp)
if(base == 8 && c >= '8') return 0;
val *= base;
val += c - '0';
- c = *++cp;
+ c = *++cp;
}
else if(base == 16 && isxdigit(c)) {
val *= base;
val += c + 10 - (islower(c) ? 'a' : 'A');
- c = *++cp;
+ c = *++cp;
}
else break;
}
diff --git a/libctru/source/services/soc/soc_ioctl.c b/libctru/source/services/soc/soc_ioctl.c
index 4125646..5be7ffb 100644
--- a/libctru/source/services/soc/soc_ioctl.c
+++ b/libctru/source/services/soc/soc_ioctl.c
@@ -28,8 +28,8 @@ int ioctl(int fd, int request, ...)
return -1;
}
- if(*value) ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- else ret = fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
+ if(*value) ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+ else ret = fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
if(ret != 0)
errno = SOC_GetErrno();
diff --git a/libctru/source/services/soc/soc_poll.c b/libctru/source/services/soc/soc_poll.c
index 8cf5b34..90f7a31 100644
--- a/libctru/source/services/soc/soc_poll.c
+++ b/libctru/source/services/soc/soc_poll.c
@@ -24,7 +24,7 @@ int poll(struct pollfd *fds, nfds_t nfsd, int timeout)
if((ret = svcSendSyncRequest(SOCU_handle)) != 0)return ret;
cmdbuf[0x100>>2] = saved_threadstorage[0];
- cmdbuf[0x104>>2] = saved_threadstorage[1];
+ cmdbuf[0x104>>2] = saved_threadstorage[1];
ret = (int)cmdbuf[1];
if(ret==0)ret = _net_convert_error(cmdbuf[2]);
diff --git a/libctru/source/services/soc/soc_select.c b/libctru/source/services/soc/soc_select.c
index d2cd911..9f66bc0 100644
--- a/libctru/source/services/soc/soc_select.c
+++ b/libctru/source/services/soc/soc_select.c
@@ -28,9 +28,9 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
if((readfds && FD_ISSET(i, readfds))
|| (writefds && FD_ISSET(i, writefds))
|| (exceptfds && FD_ISSET(i, exceptfds))) {
- pollinfo[j].fd = i;
- pollinfo[j].events = 0;
- pollinfo[j].revents = 0;
+ pollinfo[j].fd = i;
+ pollinfo[j].events = 0;
+ pollinfo[j].revents = 0;
if(readfds && FD_ISSET(i, readfds))
pollinfo[j].events |= POLLIN;
diff --git a/libctru/source/srv.c b/libctru/source/srv.c
index 366eca6..4cdcb6a 100644
--- a/libctru/source/srv.c
+++ b/libctru/source/srv.c
@@ -1,5 +1,5 @@
/*
- srv.c _ Service manager.
+ srv.c _ Service manager.
*/
#include
@@ -9,15 +9,15 @@
/*
- The homebrew loader can choose to supply a list of service handles that have
- been "stolen" from other processes that have been compromised. This allows us
- to access services that are normally restricted from the current process.
+ The homebrew loader can choose to supply a list of service handles that have
+ been "stolen" from other processes that have been compromised. This allows us
+ to access services that are normally restricted from the current process.
- For every service requested by the application, we shall first check if the
- list given to us contains the requested service and if so use it. If we don't
- find the service in that list, we ask the service manager and hope for the
- best.
- */
+ For every service requested by the application, we shall first check if the
+ list given to us contains the requested service and if so use it. If we don't
+ find the service in that list, we ask the service manager and hope for the
+ best.
+ */
typedef struct {
u32 num;
@@ -100,9 +100,9 @@ Result srvExit()
Result srvRegisterClient()
{
Result rc = 0;
-
+
u32* cmdbuf = getThreadCommandBuffer();
-
+
cmdbuf[0] = 0x10002;
cmdbuf[1] = 0x20;
@@ -116,7 +116,7 @@ Result srvGetServiceHandle(Handle* out, const char* name)
Result rc = 0;
/* Look in service-list given to us by loader. If we find find a match,
- we return it. */
+ we return it. */
Handle h = __get_handle_from_list(name);
if(h != 0) {
@@ -129,7 +129,7 @@ Result srvGetServiceHandle(Handle* out, const char* name)
strcpy((char*) &cmdbuf[1], name);
cmdbuf[3] = strlen(name);
cmdbuf[4] = 0x0;
-
+
if((rc = svcSendSyncRequest(g_srv_handle)))return rc;
*out = cmdbuf[3];
@@ -138,11 +138,11 @@ Result srvGetServiceHandle(Handle* out, const char* name)
// Old srv:pm interface, will only work on systems where srv:pm was a port (<7.X)
Result srvPmInit()
-{
+{
Result rc = 0;
-
+
if((rc = svcConnectToPort(&g_srv_handle, "srv:pm")))return rc;
-
+
if((rc = srvRegisterClient())) {
svcCloseHandle(g_srv_handle);
g_srv_handle = 0;
@@ -154,7 +154,7 @@ Result srvPmInit()
Result srvRegisterProcess(u32 procid, u32 count, void *serviceaccesscontrol)
{
Result rc = 0;
-
+
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x04030082; // <7.x
@@ -162,22 +162,22 @@ Result srvRegisterProcess(u32 procid, u32 count, void *serviceaccesscontrol)
cmdbuf[2] = count;
cmdbuf[3] = (count << 16) | 2;
cmdbuf[4] = (u32)serviceaccesscontrol;
-
+
if((rc = svcSendSyncRequest(g_srv_handle))) return rc;
-
+
return cmdbuf[1];
}
Result srvUnregisterProcess(u32 procid)
{
Result rc = 0;
-
+
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x04040040; // <7.x
cmdbuf[1] = procid;
-
+
if((rc = svcSendSyncRequest(g_srv_handle))) return rc;
-
+
return cmdbuf[1];
}
diff --git a/libctru/source/util/rbtree_clear.c b/libctru/source/util/rbtree_clear.c
index fd945f1..bec440b 100644
--- a/libctru/source/util/rbtree_clear.c
+++ b/libctru/source/util/rbtree_clear.c
@@ -2,33 +2,33 @@
#include "rbtree_internal.h"
void
-rbtree_clear(rbtree_t *tree,
- rbtree_node_destructor_t destructor)
+rbtree_clear(rbtree_t *tree,
+ rbtree_node_destructor_t destructor)
{
- rbtree_node_t *node = tree->root;
+ rbtree_node_t *node = tree->root;
- while(tree->root != NULL)
- {
- while(node->child[LEFT] != NULL)
- node = node->child[LEFT];
+ while(tree->root != NULL)
+ {
+ while(node->child[LEFT] != NULL)
+ node = node->child[LEFT];
- if(node->child[RIGHT] != NULL)
- node = node->child[RIGHT];
- else
- {
- rbtree_node_t *parent = get_parent(node);
+ if(node->child[RIGHT] != NULL)
+ node = node->child[RIGHT];
+ else
+ {
+ rbtree_node_t *parent = get_parent(node);
- if(parent == NULL)
- tree->root = NULL;
- else
- parent->child[node != parent->child[LEFT]] = NULL;
+ if(parent == NULL)
+ tree->root = NULL;
+ else
+ parent->child[node != parent->child[LEFT]] = NULL;
- if(destructor != NULL)
- (*destructor)(node);
+ if(destructor != NULL)
+ (*destructor)(node);
- node = parent;
- }
- }
+ node = parent;
+ }
+ }
- tree->size = 0;
+ tree->size = 0;
}
diff --git a/libctru/source/util/rbtree_find.c b/libctru/source/util/rbtree_find.c
index 2bcf06b..2ae1d8f 100644
--- a/libctru/source/util/rbtree_find.c
+++ b/libctru/source/util/rbtree_find.c
@@ -2,29 +2,29 @@
#include "rbtree_internal.h"
rbtree_node_t*
-rbtree_find(const rbtree_t *tree,
- const rbtree_node_t *node)
+rbtree_find(const rbtree_t *tree,
+ const rbtree_node_t *node)
{
- rbtree_node_t *tmp = tree->root;
- rbtree_node_t *save = NULL;
+ rbtree_node_t *tmp = tree->root;
+ rbtree_node_t *save = NULL;
- while(tmp != NULL)
- {
- int rc = (*tree->comparator)(node, tmp);
- if(rc < 0)
- {
- tmp = tmp->child[LEFT];
- }
- else if(rc > 0)
- {
- tmp = tmp->child[RIGHT];
- }
- else
- {
- save = tmp;
- tmp = tmp->child[LEFT];
- }
- }
+ while(tmp != NULL)
+ {
+ int rc = (*tree->comparator)(node, tmp);
+ if(rc < 0)
+ {
+ tmp = tmp->child[LEFT];
+ }
+ else if(rc > 0)
+ {
+ tmp = tmp->child[RIGHT];
+ }
+ else
+ {
+ save = tmp;
+ tmp = tmp->child[LEFT];
+ }
+ }
- return save;
+ return save;
}
diff --git a/libctru/source/util/rbtree_init.c b/libctru/source/util/rbtree_init.c
index a8c30d5..12483f0 100644
--- a/libctru/source/util/rbtree_init.c
+++ b/libctru/source/util/rbtree_init.c
@@ -1,10 +1,10 @@
#include <3ds/util/rbtree.h>
void
-rbtree_init(rbtree_t *tree,
- rbtree_node_comparator_t comparator)
+rbtree_init(rbtree_t *tree,
+ rbtree_node_comparator_t comparator)
{
- tree->root = NULL;
- tree->comparator = comparator;
- tree->size = 0;
+ tree->root = NULL;
+ tree->comparator = comparator;
+ tree->size = 0;
}
diff --git a/libctru/source/util/rbtree_insert.c b/libctru/source/util/rbtree_insert.c
index 29950ec..98a7c0e 100644
--- a/libctru/source/util/rbtree_insert.c
+++ b/libctru/source/util/rbtree_insert.c
@@ -2,95 +2,95 @@
#include "rbtree_internal.h"
static rbtree_node_t*
-do_insert(rbtree_t *tree,
- rbtree_node_t *node,
- int multi)
+do_insert(rbtree_t *tree,
+ rbtree_node_t *node,
+ int multi)
{
- rbtree_node_t *original = node;
- rbtree_node_t **tmp = &tree->root;
- rbtree_node_t *parent = NULL;
- rbtree_node_t *save = NULL;
+ rbtree_node_t *original = node;
+ rbtree_node_t **tmp = &tree->root;
+ rbtree_node_t *parent = NULL;
+ rbtree_node_t *save = NULL;
- while(*tmp != NULL)
- {
- int cmp = (*(tree->comparator))(node, *tmp);
- parent = *tmp;
+ while(*tmp != NULL)
+ {
+ int cmp = (*(tree->comparator))(node, *tmp);
+ parent = *tmp;
- if(cmp < 0)
- tmp = &((*tmp)->child[LEFT]);
- else if(cmp > 0)
- tmp = &((*tmp)->child[RIGHT]);
- else
- {
- if(!multi)
- save = *tmp;
+ if(cmp < 0)
+ tmp = &((*tmp)->child[LEFT]);
+ else if(cmp > 0)
+ tmp = &((*tmp)->child[RIGHT]);
+ else
+ {
+ if(!multi)
+ save = *tmp;
- tmp = &((*tmp)->child[LEFT]);
- }
- }
+ tmp = &((*tmp)->child[LEFT]);
+ }
+ }
- if(save != NULL)
- {
- return save;
- }
+ if(save != NULL)
+ {
+ return save;
+ }
- *tmp = node;
+ *tmp = node;
- node->child[LEFT] = node->child[RIGHT] = NULL;
- set_parent(node, parent);
+ node->child[LEFT] = node->child[RIGHT] = NULL;
+ set_parent(node, parent);
- set_red(node);
+ set_red(node);
- while(is_red((parent = get_parent(node))))
- {
- rbtree_node_t *grandparent = get_parent(parent);
- int left = (parent == grandparent->child[LEFT]);
- rbtree_node_t *uncle = grandparent->child[left];
+ while(is_red((parent = get_parent(node))))
+ {
+ rbtree_node_t *grandparent = get_parent(parent);
+ int left = (parent == grandparent->child[LEFT]);
+ rbtree_node_t *uncle = grandparent->child[left];
- if(is_red(uncle))
- {
- set_black(uncle);
- set_black(parent);
- set_red(grandparent);
+ if(is_red(uncle))
+ {
+ set_black(uncle);
+ set_black(parent);
+ set_red(grandparent);
- node = grandparent;
- }
- else
- {
- if(parent->child[left] == node)
- {
- rbtree_node_t *tmp;
+ node = grandparent;
+ }
+ else
+ {
+ if(parent->child[left] == node)
+ {
+ rbtree_node_t *tmp;
- rbtree_rotate(tree, parent, left);
+ rbtree_rotate(tree, parent, left);
- tmp = parent;
- parent = node;
- node = tmp;
- }
+ tmp = parent;
+ parent = node;
+ node = tmp;
+ }
- set_black(parent);
- set_red(grandparent);
- rbtree_rotate(tree, grandparent, !left);
- }
- }
+ set_black(parent);
+ set_red(grandparent);
+ rbtree_rotate(tree, grandparent, !left);
+ }
+ }
- set_black(tree->root);
+ set_black(tree->root);
- tree->size += 1;
+ tree->size += 1;
- return original;
+ return original;
}
rbtree_node_t*
-rbtree_insert(rbtree_t *tree,
- rbtree_node_t *node)
+rbtree_insert(rbtree_t *tree,
+ rbtree_node_t *node)
{
- return do_insert(tree, node, 0);
+ return do_insert(tree, node, 0);
}
void
-rbtree_insert_multi(rbtree_t *tree,
- rbtree_node_t *node)
+rbtree_insert_multi(rbtree_t *tree,
+ rbtree_node_t *node)
{
- do_insert(tree, node, 1);
+ do_insert(tree, node, 1);
}
diff --git a/libctru/source/util/rbtree_internal.h b/libctru/source/util/rbtree_internal.h
index 6d0d0a9..1c61657 100644
--- a/libctru/source/util/rbtree_internal.h
+++ b/libctru/source/util/rbtree_internal.h
@@ -1,64 +1,64 @@
#pragma once
-#define LEFT 0
-#define RIGHT 1
+#define LEFT 0
+#define RIGHT 1
typedef enum rbtree_color
{
- RED = 0,
- BLACK = 1,
+ RED = 0,
+ BLACK = 1,
} rbtree_color_t;
-#define COLOR_MASK (RED|BLACK)
+#define COLOR_MASK (RED|BLACK)
static inline void
set_black(rbtree_node_t *node)
{
- node->parent_color &= ~COLOR_MASK;
- node->parent_color |= BLACK;
+ node->parent_color &= ~COLOR_MASK;
+ node->parent_color |= BLACK;
}
static inline void
set_red(rbtree_node_t *node)
{
- node->parent_color &= ~COLOR_MASK;
- node->parent_color |= RED;
+ node->parent_color &= ~COLOR_MASK;
+ node->parent_color |= RED;
}
static inline rbtree_color_t
get_color(const rbtree_node_t *node)
{
- if(node == NULL)
- return BLACK;
- return (rbtree_color_t)(node->parent_color & COLOR_MASK);
+ if(node == NULL)
+ return BLACK;
+ return (rbtree_color_t)(node->parent_color & COLOR_MASK);
}
static inline int
is_black(const rbtree_node_t *node)
{
- return get_color(node) == BLACK;
+ return get_color(node) == BLACK;
}
static inline int
is_red(const rbtree_node_t *node)
{
- return get_color(node) == RED;
+ return get_color(node) == RED;
}
static inline rbtree_node_t*
get_parent(const rbtree_node_t *node)
{
- return (rbtree_node_t*)(node->parent_color & ~COLOR_MASK);
+ return (rbtree_node_t*)(node->parent_color & ~COLOR_MASK);
}
static inline void
-set_parent(rbtree_node_t *node,
- const rbtree_node_t *parent)
+set_parent(rbtree_node_t *node,
+ const rbtree_node_t *parent)
{
- node->parent_color = (get_color(node)) | ((uintptr_t)parent);
+ node->parent_color = (get_color(node)) | ((uintptr_t)parent);
}
void
-rbtree_rotate(rbtree_t *tree,
- rbtree_node_t *node,
- int left);
+rbtree_rotate(rbtree_t *tree,
+ rbtree_node_t *node,
+ int left);
diff --git a/libctru/source/util/rbtree_iterator.c b/libctru/source/util/rbtree_iterator.c
index 424658d..dec2938 100644
--- a/libctru/source/util/rbtree_iterator.c
+++ b/libctru/source/util/rbtree_iterator.c
@@ -2,40 +2,40 @@
#include "rbtree_internal.h"
static inline rbtree_node_t*
-do_iterate(const rbtree_node_t *node,
- int next)
+do_iterate(const rbtree_node_t *node,
+ int next)
{
- rbtree_node_t *it = (rbtree_node_t*)node;
+ rbtree_node_t *it = (rbtree_node_t*)node;
- if(it->child[next] != NULL)
- {
- it = it->child[next];
- while(it->child[!next] != NULL)
- it = it->child[!next];
- }
- else
- {
- rbtree_node_t *parent = get_parent(node);
- while(parent != NULL && it == parent->child[next])
- {
- it = parent;
- parent = get_parent(it);
- }
+ if(it->child[next] != NULL)
+ {
+ it = it->child[next];
+ while(it->child[!next] != NULL)
+ it = it->child[!next];
+ }
+ else
+ {
+ rbtree_node_t *parent = get_parent(node);
+ while(parent != NULL && it == parent->child[next])
+ {
+ it = parent;
+ parent = get_parent(it);
+ }
- it = parent;
- }
+ it = parent;
+ }
- return it;
+ return it;
}
rbtree_node_t*
rbtree_node_next(const rbtree_node_t *node)
{
- return do_iterate(node, RIGHT);
+ return do_iterate(node, RIGHT);
}
rbtree_node_t*
rbtree_node_prev(const rbtree_node_t *node)
{
- return do_iterate(node, LEFT);
+ return do_iterate(node, LEFT);
}
diff --git a/libctru/source/util/rbtree_minmax.c b/libctru/source/util/rbtree_minmax.c
index f74293c..c571ba7 100644
--- a/libctru/source/util/rbtree_minmax.c
+++ b/libctru/source/util/rbtree_minmax.c
@@ -2,36 +2,36 @@
#include "rbtree_internal.h"
static inline rbtree_node_t*
-do_minmax(const rbtree_t *tree,
- int max)
+do_minmax(const rbtree_t *tree,
+ int max)
{
- rbtree_node_t *node = tree->root;
+ rbtree_node_t *node = tree->root;
- if(node == NULL)
- return NULL;
+ if(node == NULL)
+ return NULL;
- while(node->child[max] != NULL)
- node = node->child[max];
+ while(node->child[max] != NULL)
+ node = node->child[max];
- return node;
+ return node;
}
rbtree_node_t*
rbtree_min(const rbtree_t *tree)
{
- rbtree_node_t *node;
+ rbtree_node_t *node;
- node = do_minmax(tree, LEFT);
+ node = do_minmax(tree, LEFT);
- return node;
+ return node;
}
rbtree_node_t*
rbtree_max(const rbtree_t *tree)
{
- rbtree_node_t *node;
+ rbtree_node_t *node;
- node = do_minmax(tree, RIGHT);
+ node = do_minmax(tree, RIGHT);
- return node;
+ return node;
}
diff --git a/libctru/source/util/rbtree_remove.c b/libctru/source/util/rbtree_remove.c
index 8a0359a..78243a3 100644
--- a/libctru/source/util/rbtree_remove.c
+++ b/libctru/source/util/rbtree_remove.c
@@ -2,139 +2,139 @@
#include "rbtree_internal.h"
static void
-recolor(rbtree_t *tree,
- rbtree_node_t *parent,
- rbtree_node_t *node)
+recolor(rbtree_t *tree,
+ rbtree_node_t *parent,
+ rbtree_node_t *node)
{
- rbtree_node_t *sibling;
+ rbtree_node_t *sibling;
- while(is_black(node) && node != tree->root)
- {
- int left = (node == parent->child[LEFT]);
+ while(is_black(node) && node != tree->root)
+ {
+ int left = (node == parent->child[LEFT]);
- sibling = parent->child[left];
+ sibling = parent->child[left];
- if(is_red(sibling))
- {
- set_black(sibling);
- set_red(parent);
- rbtree_rotate(tree, parent, left);
- sibling = parent->child[left];
- }
+ if(is_red(sibling))
+ {
+ set_black(sibling);
+ set_red(parent);
+ rbtree_rotate(tree, parent, left);
+ sibling = parent->child[left];
+ }
- if(is_black(sibling->child[LEFT]) && is_black(sibling->child[RIGHT]))
- {
- set_red(sibling);
- node = parent;
- parent = get_parent(node);
- }
- else
- {
- if(is_black(sibling->child[left]))
- {
- set_black(sibling->child[!left]);
- set_red(sibling);
- rbtree_rotate(tree, sibling, !left);
- sibling = parent->child[left];
- }
+ if(is_black(sibling->child[LEFT]) && is_black(sibling->child[RIGHT]))
+ {
+ set_red(sibling);
+ node = parent;
+ parent = get_parent(node);
+ }
+ else
+ {
+ if(is_black(sibling->child[left]))
+ {
+ set_black(sibling->child[!left]);
+ set_red(sibling);
+ rbtree_rotate(tree, sibling, !left);
+ sibling = parent->child[left];
+ }
- if(is_black(parent))
- set_black(sibling);
- else
- set_red(sibling);
- set_black(parent);
- set_black(sibling->child[left]);
+ if(is_black(parent))
+ set_black(sibling);
+ else
+ set_red(sibling);
+ set_black(parent);
+ set_black(sibling->child[left]);
- rbtree_rotate(tree, parent, left);
+ rbtree_rotate(tree, parent, left);
- node = tree->root;
- }
- }
+ node = tree->root;
+ }
+ }
- if(node != NULL)
- set_black(node);
+ if(node != NULL)
+ set_black(node);
}
rbtree_node_t*
-rbtree_remove(rbtree_t *tree,
- rbtree_node_t *node,
- rbtree_node_destructor_t destructor)
+rbtree_remove(rbtree_t *tree,
+ rbtree_node_t *node,
+ rbtree_node_destructor_t destructor)
{
- rbtree_color_t color;
- rbtree_node_t *child, *parent, *original = node;
- rbtree_node_t *next;
+ rbtree_color_t color;
+ rbtree_node_t *child, *parent, *original = node;
+ rbtree_node_t *next;
- next = rbtree_node_next(node);
+ next = rbtree_node_next(node);
- if(node->child[LEFT] != NULL && node->child[RIGHT] != NULL)
- {
- rbtree_node_t *old = node;
+ if(node->child[LEFT] != NULL && node->child[RIGHT] != NULL)
+ {
+ rbtree_node_t *old = node;
- node = node->child[RIGHT];
- while(node->child[LEFT] != NULL)
- node = node->child[LEFT];
+ node = node->child[RIGHT];
+ while(node->child[LEFT] != NULL)
+ node = node->child[LEFT];
- parent = get_parent(old);
- if(parent != NULL)
- {
- if(parent->child[LEFT] == old)
- parent->child[LEFT] = node;
- else
- parent->child[RIGHT] = node;
- }
- else
- tree->root = node;
+ parent = get_parent(old);
+ if(parent != NULL)
+ {
+ if(parent->child[LEFT] == old)
+ parent->child[LEFT] = node;
+ else
+ parent->child[RIGHT] = node;
+ }
+ else
+ tree->root = node;
- child = node->child[RIGHT];
- parent = get_parent(node);
- color = get_color(node);
+ child = node->child[RIGHT];
+ parent = get_parent(node);
+ color = get_color(node);
- if(parent == old)
- parent = node;
- else
- {
- if(child != NULL)
- set_parent(child, parent);
- parent->child[LEFT] = child;
+ if(parent == old)
+ parent = node;
+ else
+ {
+ if(child != NULL)
+ set_parent(child, parent);
+ parent->child[LEFT] = child;
- node->child[RIGHT] = old->child[RIGHT];
- set_parent(old->child[RIGHT], node);
- }
+ node->child[RIGHT] = old->child[RIGHT];
+ set_parent(old->child[RIGHT], node);
+ }
- node->parent_color = old->parent_color;
- node->child[LEFT] = old->child[LEFT];
- set_parent(old->child[LEFT], node);
- }
- else
- {
- if(node->child[LEFT] == NULL)
- child = node->child[RIGHT];
- else
- child = node->child[LEFT];
+ node->parent_color = old->parent_color;
+ node->child[LEFT] = old->child[LEFT];
+ set_parent(old->child[LEFT], node);
+ }
+ else
+ {
+ if(node->child[LEFT] == NULL)
+ child = node->child[RIGHT];
+ else
+ child = node->child[LEFT];
- parent = get_parent(node);
- color = get_color(node);
+ parent = get_parent(node);
+ color = get_color(node);
- if(child != NULL)
- set_parent(child, parent);
- if(parent != NULL)
- {
- if(parent->child[LEFT] == node)
- parent->child[LEFT] = child;
- else
- parent->child[RIGHT] = child;
- }
- else
- tree->root = child;
- }
+ if(child != NULL)
+ set_parent(child, parent);
+ if(parent != NULL)
+ {
+ if(parent->child[LEFT] == node)
+ parent->child[LEFT] = child;
+ else
+ parent->child[RIGHT] = child;
+ }
+ else
+ tree->root = child;
+ }
- if(color == BLACK)
- recolor(tree, parent, child);
+ if(color == BLACK)
+ recolor(tree, parent, child);
- if(destructor != NULL)
- (*destructor)(original);
+ if(destructor != NULL)
+ (*destructor)(original);
- tree->size -= 1;
+ tree->size -= 1;
- return next;
+ return next;
}
diff --git a/libctru/source/util/rbtree_rotate.c b/libctru/source/util/rbtree_rotate.c
index c47d290..5e92550 100644
--- a/libctru/source/util/rbtree_rotate.c
+++ b/libctru/source/util/rbtree_rotate.c
@@ -2,27 +2,27 @@
#include "rbtree_internal.h"
void
-rbtree_rotate(rbtree_t *tree,
- rbtree_node_t *node,
- int left)
+rbtree_rotate(rbtree_t *tree,
+ rbtree_node_t *node,
+ int left)
{
- rbtree_node_t *tmp = node->child[left];
- rbtree_node_t *parent = get_parent(node);
+ rbtree_node_t *tmp = node->child[left];
+ rbtree_node_t *parent = get_parent(node);
- node->child[left] = tmp->child[!left];
- if(tmp->child[!left] != NULL)
- set_parent(tmp->child[!left], node);
+ node->child[left] = tmp->child[!left];
+ if(tmp->child[!left] != NULL)
+ set_parent(tmp->child[!left], node);
- tmp->child[!left] = node;
- set_parent(tmp, parent);
- if(parent != NULL)
- {
- if(node == parent->child[!left])
- parent->child[!left] = tmp;
- else
- parent->child[left] = tmp;
- }
- else
- tree->root = tmp;
- set_parent(node, tmp);
+ tmp->child[!left] = node;
+ set_parent(tmp, parent);
+ if(parent != NULL)
+ {
+ if(node == parent->child[!left])
+ parent->child[!left] = tmp;
+ else
+ parent->child[left] = tmp;
+ }
+ else
+ tree->root = tmp;
+ set_parent(node, tmp);
}