mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
fsdev/romfsdev: Reduce TLS usage by sharing the path buffer
This commit is contained in:
parent
a774fb81cc
commit
26a0ee4af3
@ -14,6 +14,7 @@
|
||||
#include "services/fs.h"
|
||||
#include "services/time.h"
|
||||
|
||||
#include "path_buf.h"
|
||||
|
||||
/*! @internal
|
||||
*
|
||||
@ -109,7 +110,6 @@ static fsdev_fsdevice fsdev_fsdevices[32];
|
||||
/*! @endcond */
|
||||
|
||||
static char __cwd[PATH_MAX+1] = "/";
|
||||
static __thread char __fixedpath[PATH_MAX+1];
|
||||
|
||||
__attribute__((weak)) u32 __nx_fsdev_direntry_cache_size = 32;
|
||||
|
||||
@ -202,17 +202,17 @@ fsdev_fixpath(struct _reent *r,
|
||||
} while(code != 0);
|
||||
|
||||
if(path[0] == '/')
|
||||
strncpy(__fixedpath, path, PATH_MAX);
|
||||
strncpy(__nx_dev_path_buf, path, PATH_MAX);
|
||||
else
|
||||
{
|
||||
strncpy(__fixedpath, __cwd, PATH_MAX);
|
||||
__fixedpath[PATH_MAX] = '\0';
|
||||
strncat(__fixedpath, path, PATH_MAX - strlen(__cwd));
|
||||
strncpy(__nx_dev_path_buf, __cwd, PATH_MAX);
|
||||
__nx_dev_path_buf[PATH_MAX] = '\0';
|
||||
strncat(__nx_dev_path_buf, path, PATH_MAX - strlen(__cwd));
|
||||
}
|
||||
|
||||
if(__fixedpath[PATH_MAX] != 0)
|
||||
if(__nx_dev_path_buf[PATH_MAX] != 0)
|
||||
{
|
||||
__fixedpath[PATH_MAX] = 0;
|
||||
__nx_dev_path_buf[PATH_MAX] = 0;
|
||||
r->_errno = ENAMETOOLONG;
|
||||
return NULL;
|
||||
}
|
||||
@ -236,7 +236,7 @@ fsdev_fixpath(struct _reent *r,
|
||||
}
|
||||
}
|
||||
|
||||
return __fixedpath;
|
||||
return __nx_dev_path_buf;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -248,7 +248,7 @@ fsdev_getfspath(struct _reent *r,
|
||||
if(fsdev_fixpath(r, path, device) == NULL)
|
||||
return -1;
|
||||
|
||||
memcpy(outpath, __fixedpath,FS_MAX_PATH-1);
|
||||
memcpy(outpath, __nx_dev_path_buf,FS_MAX_PATH-1);
|
||||
outpath[FS_MAX_PATH-1] = '\0';
|
||||
|
||||
return 0;
|
||||
@ -462,15 +462,15 @@ Result fsdevMountSdmc(void)
|
||||
{
|
||||
if(FindDevice(__system_argv[0]) == dev)
|
||||
{
|
||||
strncpy(__fixedpath,__system_argv[0],PATH_MAX);
|
||||
if(__fixedpath[PATH_MAX] != 0)
|
||||
strncpy(__nx_dev_path_buf,__system_argv[0],PATH_MAX);
|
||||
if(__nx_dev_path_buf[PATH_MAX] != 0)
|
||||
{
|
||||
__fixedpath[PATH_MAX] = 0;
|
||||
__nx_dev_path_buf[PATH_MAX] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *last_slash = NULL;
|
||||
p = __fixedpath;
|
||||
p = __nx_dev_path_buf;
|
||||
do
|
||||
{
|
||||
units = decode_utf8(&code, (const uint8_t*)p);
|
||||
@ -489,7 +489,7 @@ Result fsdevMountSdmc(void)
|
||||
if(last_slash != NULL)
|
||||
{
|
||||
last_slash[0] = 0;
|
||||
chdir(__fixedpath);
|
||||
chdir(__nx_dev_path_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
nx/source/runtime/devices/path_buf.c
Normal file
3
nx/source/runtime/devices/path_buf.c
Normal file
@ -0,0 +1,3 @@
|
||||
#include "path_buf.h"
|
||||
|
||||
char __thread __nx_dev_path_buf[PATH_MAX+1];
|
4
nx/source/runtime/devices/path_buf.h
Normal file
4
nx/source/runtime/devices/path_buf.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <limits.h>
|
||||
|
||||
extern char __thread __nx_dev_path_buf[PATH_MAX+1];
|
@ -15,6 +15,8 @@
|
||||
#include "runtime/env.h"
|
||||
#include "nro.h"
|
||||
|
||||
#include "path_buf.h"
|
||||
|
||||
typedef enum {
|
||||
RomfsSource_FsFile,
|
||||
RomfsSource_FsStorage,
|
||||
@ -40,8 +42,6 @@ typedef struct romfs_mount
|
||||
extern int __system_argc;
|
||||
extern char** __system_argv;
|
||||
|
||||
static char __thread __component[PATH_MAX+1];
|
||||
|
||||
#define romFS_root(m) ((romfs_dir*)(m)->dirTable)
|
||||
#define romFS_dir(m,x) ((romfs_dir*) ((u8*)(m)->dirTable + (x)))
|
||||
#define romFS_file(m,x) ((romfs_file*)((u8*)(m)->fileTable + (x)))
|
||||
@ -233,10 +233,10 @@ Result romfsMount(const char *name)
|
||||
filename += 5;
|
||||
else if (strncmp(filename, "nxlink:/", 8) == 0)
|
||||
{
|
||||
strncpy(__component, "/switch", PATH_MAX);
|
||||
strncat(__component, filename+7, PATH_MAX);
|
||||
__component[PATH_MAX] = 0;
|
||||
filename = __component;
|
||||
strncpy(__nx_dev_path_buf, "/switch", PATH_MAX);
|
||||
strncat(__nx_dev_path_buf, filename+7, PATH_MAX);
|
||||
__nx_dev_path_buf[PATH_MAX] = 0;
|
||||
filename = __nx_dev_path_buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -501,7 +501,7 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa
|
||||
while (**pPath)
|
||||
{
|
||||
char* slashPos = strchr(*pPath, '/');
|
||||
char* component = __component;
|
||||
char* component = __nx_dev_path_buf;
|
||||
|
||||
if (slashPos)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user