_3DS -> __3DS__

This commit is contained in:
Michael Theall 2022-03-31 11:53:47 -05:00
parent 9c1735e33f
commit 7364ea7dd5
15 changed files with 50 additions and 50 deletions

View File

@ -68,7 +68,7 @@ CFLAGS := -g -Wall $(OPTIMIZE) -mword-relocations \
-fomit-frame-pointer -ffunction-sections -fdata-sections \ -fomit-frame-pointer -ffunction-sections -fdata-sections \
$(ARCH) $(DEFINES) $(CLASSIC) $(ARCH) $(DEFINES) $(CLASSIC)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS \ CFLAGS += $(INCLUDE) -DARM11 -D__3DS__ \
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \ -DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \ -DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \
-DNO_IPV6 -DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\"" \ -DNO_IPV6 -DFTPDCONFIG="\"/config/ftpd/ftpd.cfg\"" \

View File

@ -46,7 +46,7 @@ DATA := data
INCLUDES := include INCLUDES := include
ifeq ($(strip $(CLASSIC)),) ifeq ($(strip $(CLASSIC)),)
APP_TITLE := ftpd pro $(VERSION) APP_TITLE := ftpd Issue \#139
TARGET := switch/ftpd TARGET := switch/ftpd
BUILD := switch/build BUILD := switch/build
SOURCES += source/imgui SOURCES += source/imgui

View File

@ -60,7 +60,7 @@ public:
/// \brief Get port /// \brief Get port
std::uint16_t port () const; std::uint16_t port () const;
#ifdef _3DS #ifdef __3DS__
/// \brief Whether to get mtime /// \brief Whether to get mtime
/// \note only effective on 3DS /// \note only effective on 3DS
bool getMTime () const; bool getMTime () const;
@ -93,7 +93,7 @@ public:
/// \param port_ Listen port /// \param port_ Listen port
bool setPort (std::uint16_t port_); bool setPort (std::uint16_t port_);
#ifdef _3DS #ifdef __3DS__
/// \brief Set whether to get mtime /// \brief Set whether to get mtime
/// \param getMTime_ Whether to get mtime /// \param getMTime_ Whether to get mtime
void setGetMTime (bool getMTime_); void setGetMTime (bool getMTime_);
@ -130,7 +130,7 @@ private:
/// \brief Listen port /// \brief Listen port
std::uint16_t m_port; std::uint16_t m_port;
#ifdef _3DS #ifdef __3DS__
/// \brief Whether to get mtime /// \brief Whether to get mtime
bool m_getMTime = true; bool m_getMTime = true;
#endif #endif

View File

@ -128,7 +128,7 @@ private:
/// \brief Port setting /// \brief Port setting
std::uint16_t m_portSetting; std::uint16_t m_portSetting;
#ifdef _3DS #ifdef __3DS__
/// \brief getMTime setting /// \brief getMTime setting
bool m_getMTimeSetting; bool m_getMTimeSetting;
#endif #endif

View File

@ -83,7 +83,7 @@ private:
/// \brief Amount of file position history to keep /// \brief Amount of file position history to keep
constexpr static auto POSITION_HISTORY = 60; constexpr static auto POSITION_HISTORY = 60;
#elif defined(_3DS) #elif defined(__3DS__)
/// \brief Socket buffer size /// \brief Socket buffer size
constexpr static auto SOCK_BUFFERSIZE = 32768; constexpr static auto SOCK_BUFFERSIZE = 32768;

View File

@ -26,7 +26,7 @@ extern char const *const g_dearImGuiVersion;
extern char const *const g_dearImGuiCopyright; extern char const *const g_dearImGuiCopyright;
extern char const *const g_mitLicense; extern char const *const g_mitLicense;
#ifdef _3DS #ifdef __3DS__
extern char const *const g_libctruVersion; extern char const *const g_libctruVersion;
extern char const *const g_citro3dVersion; extern char const *const g_citro3dVersion;
extern char const *const g_citro3dCopyright; extern char const *const g_citro3dCopyright;
@ -47,7 +47,7 @@ extern char const *const g_bsdLicense;
extern char const *const g_zlibLicense; extern char const *const g_zlibLicense;
#endif #endif
#if !defined(NDS) && !defined(_3DS) && !defined(__SWITCH__) #if !defined(NDS) && !defined(__3DS__) && !defined(__SWITCH__)
extern char const *const g_glfwVersion; extern char const *const g_glfwVersion;
extern char const *const g_glfwCopyright; extern char const *const g_glfwCopyright;
#endif #endif

View File

@ -24,7 +24,7 @@
#if defined(NDS) #if defined(NDS)
#include <nds.h> #include <nds.h>
#elif defined(_3DS) #elif defined(__3DS__)
#include <3ds.h> #include <3ds.h>
#elif defined(__SWITCH__) #elif defined(__SWITCH__)
#include <switch.h> #include <switch.h>
@ -80,7 +80,7 @@ void render ();
/// \brief Deinitialize platform /// \brief Deinitialize platform
void exit (); void exit ();
#ifdef _3DS #ifdef __3DS__
/// \brief Steady clock /// \brief Steady clock
struct steady_clock struct steady_clock
{ {

View File

@ -65,7 +65,7 @@ public:
/// \param addr_ Address /// \param addr_ Address
SockAddr (struct sockaddr_in const &addr_); SockAddr (struct sockaddr_in const &addr_);
#ifndef _3DS #ifndef __3DS__
/// \param Parameterized constructor /// \param Parameterized constructor
/// \param addr_ Address /// \param addr_ Address
SockAddr (struct sockaddr_in6 const &addr_); SockAddr (struct sockaddr_in6 const &addr_);
@ -78,7 +78,7 @@ public:
/// \param sockaddr_in cast operator /// \param sockaddr_in cast operator
operator struct sockaddr_in const & () const; operator struct sockaddr_in const & () const;
#ifndef _3DS #ifndef __3DS__
/// \param sockaddr_in6 cast operator /// \param sockaddr_in6 cast operator
operator struct sockaddr_in6 const & () const; operator struct sockaddr_in6 const & () const;
#endif #endif

View File

@ -25,7 +25,7 @@
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#if defined(NDS) || defined(_3DS) || defined(__SWITCH__) #if defined(NDS) || defined(__3DS__) || defined(__SWITCH__)
#define getline __getline #define getline __getline
#endif #endif

View File

@ -153,7 +153,7 @@ UniqueFtpConfig FtpConfig::load (char const *const path_)
config->m_pass = val; config->m_pass = val;
else if (key == "port") else if (key == "port")
parseInt (port, val); parseInt (port, val);
#ifdef _3DS #ifdef __3DS__
else if (key == "mtime") else if (key == "mtime")
{ {
if (val == "0") if (val == "0")
@ -208,7 +208,7 @@ bool FtpConfig::save (char const *const path_)
std::fprintf (fp, "pass=%s\n", m_pass.c_str ()); std::fprintf (fp, "pass=%s\n", m_pass.c_str ());
std::fprintf (fp, "port=%u\n", m_port); std::fprintf (fp, "port=%u\n", m_port);
#ifdef _3DS #ifdef __3DS__
std::fprintf (fp, "mtime=%u\n", m_getMTime); std::fprintf (fp, "mtime=%u\n", m_getMTime);
#endif #endif
@ -238,7 +238,7 @@ std::uint16_t FtpConfig::port () const
return m_port; return m_port;
} }
#ifdef _3DS #ifdef __3DS__
bool FtpConfig::getMTime () const bool FtpConfig::getMTime () const
{ {
return m_getMTime; return m_getMTime;
@ -290,7 +290,7 @@ bool FtpConfig::setPort (std::uint16_t const port_)
errno = EPERM; errno = EPERM;
return false; return false;
} }
#elif defined(NDS) || defined(_3DS) #elif defined(NDS) || defined(__3DS__)
// 3DS is allowed < 1024, but not 0 // 3DS is allowed < 1024, but not 0
// NDS is allowed < 1024, but 0 crashes the app // NDS is allowed < 1024, but 0 crashes the app
if (port_ == 0) if (port_ == 0)
@ -304,7 +304,7 @@ bool FtpConfig::setPort (std::uint16_t const port_)
return true; return true;
} }
#ifdef _3DS #ifdef __3DS__
void FtpConfig::setGetMTime (bool const getMTime_) void FtpConfig::setGetMTime (bool const getMTime_)
{ {
m_getMTime = getMTime_; m_getMTime = getMTime_;

View File

@ -157,7 +157,7 @@ void FtpServer::draw ()
auto const height = io.DisplaySize.y; auto const height = io.DisplaySize.y;
ImGui::SetNextWindowPos (ImVec2 (0, 0), ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos (ImVec2 (0, 0), ImGuiCond_FirstUseEver);
#ifdef _3DS #ifdef __3DS__
// top screen // top screen
ImGui::SetNextWindowSize (ImVec2 (width, height * 0.5f)); ImGui::SetNextWindowSize (ImVec2 (width, height * 0.5f));
#else #else
@ -177,26 +177,26 @@ void FtpServer::draw ()
ImGui::Begin (title, ImGui::Begin (title,
nullptr, nullptr,
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
#ifndef _3DS #ifndef __3DS__
| ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_MenuBar
#endif #endif
); );
} }
#ifndef _3DS #ifndef __3DS__
showMenu (); showMenu ();
#endif #endif
#ifndef _3DS #ifndef __3DS__
ImGui::BeginChild ( ImGui::BeginChild (
"Logs", ImVec2 (0, 0.5f * height), false, ImGuiWindowFlags_HorizontalScrollbar); "Logs", ImVec2 (0, 0.5f * height), false, ImGuiWindowFlags_HorizontalScrollbar);
#endif #endif
drawLog (); drawLog ();
#ifndef _3DS #ifndef __3DS__
ImGui::EndChild (); ImGui::EndChild ();
#endif #endif
#ifdef _3DS #ifdef __3DS__
ImGui::End (); ImGui::End ();
// bottom screen // bottom screen
@ -242,7 +242,7 @@ std::string FtpServer::getFreeSpace ()
void FtpServer::updateFreeSpace () void FtpServer::updateFreeSpace ()
{ {
struct statvfs st; struct statvfs st;
#if defined(NDS) || defined(_3DS) || defined(__SWITCH__) #if defined(NDS) || defined(__3DS__) || defined(__SWITCH__)
if (::statvfs ("sdmc:/", &st) != 0) if (::statvfs ("sdmc:/", &st) != 0)
#else #else
if (::statvfs ("/", &st) != 0) if (::statvfs ("/", &st) != 0)
@ -329,7 +329,7 @@ void FtpServer::showMenu ()
if (ImGui::BeginMenuBar ()) if (ImGui::BeginMenuBar ())
{ {
#if defined(_3DS) || defined(__SWITCH__) #if defined(__3DS__) || defined(__SWITCH__)
if (ImGui::BeginMenu (u8"Menu \xee\x80\x83")) // Y Button if (ImGui::BeginMenu (u8"Menu \xee\x80\x83")) // Y Button
#else #else
if (ImGui::BeginMenu ("Menu")) if (ImGui::BeginMenu ("Menu"))
@ -362,7 +362,7 @@ void FtpServer::showMenu ()
m_portSetting = m_config->port (); m_portSetting = m_config->port ();
#ifdef _3DS #ifdef __3DS__
m_getMTimeSetting = m_config->getMTime (); m_getMTimeSetting = m_config->getMTime ();
#endif #endif
@ -393,7 +393,7 @@ void FtpServer::showMenu ()
void FtpServer::showSettings () void FtpServer::showSettings ()
{ {
#ifdef _3DS #ifdef __3DS__
auto const &io = ImGui::GetIO (); auto const &io = ImGui::GetIO ();
auto const width = io.DisplaySize.x; auto const width = io.DisplaySize.x;
auto const height = io.DisplaySize.y; auto const height = io.DisplaySize.y;
@ -425,7 +425,7 @@ void FtpServer::showSettings ()
"%u", "%u",
ImGuiInputTextFlags_AutoSelectAll); ImGuiInputTextFlags_AutoSelectAll);
#ifdef _3DS #ifdef __3DS__
ImGui::Checkbox ("Get mtime", &m_getMTimeSetting); ImGui::Checkbox ("Get mtime", &m_getMTimeSetting);
#endif #endif
@ -491,7 +491,7 @@ void FtpServer::showSettings ()
m_config->setPass (m_passSetting); m_config->setPass (m_passSetting);
m_config->setPort (m_portSetting); m_config->setPort (m_portSetting);
#ifdef _3DS #ifdef __3DS__
m_config->setGetMTime (m_getMTimeSetting); m_config->setGetMTime (m_getMTimeSetting);
#endif #endif
@ -522,7 +522,7 @@ void FtpServer::showSettings ()
m_userSetting = defaults->user (); m_userSetting = defaults->user ();
m_passSetting = defaults->pass (); m_passSetting = defaults->pass ();
m_portSetting = defaults->port (); m_portSetting = defaults->port ();
#ifdef _3DS #ifdef __3DS__
m_getMTimeSetting = defaults->getMTime (); m_getMTimeSetting = defaults->getMTime ();
#endif #endif
@ -549,7 +549,7 @@ void FtpServer::showAbout ()
auto const width = io.DisplaySize.x; auto const width = io.DisplaySize.x;
auto const height = io.DisplaySize.y; auto const height = io.DisplaySize.y;
#ifdef _3DS #ifdef __3DS__
ImGui::SetNextWindowSize (ImVec2 (width * 0.8f, height * 0.5f)); ImGui::SetNextWindowSize (ImVec2 (width * 0.8f, height * 0.5f));
ImGui::SetNextWindowPos (ImVec2 (width * 0.1f, height * 0.5f)); ImGui::SetNextWindowPos (ImVec2 (width * 0.1f, height * 0.5f));
#else #else
@ -582,7 +582,7 @@ void FtpServer::showAbout ()
} }
#if defined(NDS) #if defined(NDS)
#elif defined(_3DS) #elif defined(__3DS__)
if (ImGui::TreeNode (g_libctruVersion)) if (ImGui::TreeNode (g_libctruVersion))
{ {
ImGui::TextWrapped (g_zlibLicense); ImGui::TextWrapped (g_zlibLicense);

View File

@ -40,7 +40,7 @@
#include <mutex> #include <mutex>
using namespace std::chrono_literals; using namespace std::chrono_literals;
#if defined(NDS) || defined(_3DS) || defined(__SWITCH__) #if defined(NDS) || defined(__3DS__) || defined(__SWITCH__)
#define lstat stat #define lstat stat
#endif #endif
@ -341,7 +341,7 @@ void FtpSession::draw ()
std::fputs (m_workItem.empty () ? m_cwd.c_str () : m_workItem.c_str (), stdout); std::fputs (m_workItem.empty () ? m_cwd.c_str () : m_workItem.c_str (), stdout);
#else #else
#ifdef _3DS #ifdef __3DS__
ImGui::BeginChild (m_windowName.c_str (), ImVec2 (0.0f, 45.0f), true); ImGui::BeginChild (m_windowName.c_str (), ImVec2 (0.0f, 45.0f), true);
#else #else
ImGui::BeginChild (m_windowName.c_str (), ImVec2 (0.0f, 80.0f), true); ImGui::BeginChild (m_windowName.c_str (), ImVec2 (0.0f, 80.0f), true);
@ -718,7 +718,7 @@ bool FtpSession::dataAccept ()
return false; return false;
} }
#ifndef _3DS #ifndef __3DS__
m_dataSocket->setRecvBufferSize (SOCK_BUFFERSIZE); m_dataSocket->setRecvBufferSize (SOCK_BUFFERSIZE);
m_dataSocket->setSendBufferSize (SOCK_BUFFERSIZE); m_dataSocket->setSendBufferSize (SOCK_BUFFERSIZE);
#endif #endif
@ -793,7 +793,7 @@ int FtpSession::fillDirent (struct stat const &st_, std::string_view const path_
type_ = "file"; type_ = "file";
else if (S_ISDIR (st_.st_mode)) else if (S_ISDIR (st_.st_mode))
type_ = "dir"; type_ = "dir";
#if !defined(_3DS) && !defined(__SWITCH__) #if !defined(__3DS__) && !defined(__SWITCH__)
else if (S_ISLNK (st_.st_mode)) else if (S_ISLNK (st_.st_mode))
type_ = "os.unix=symlink"; type_ = "os.unix=symlink";
else if (S_ISCHR (st_.st_mode)) else if (S_ISCHR (st_.st_mode))
@ -970,7 +970,7 @@ int FtpSession::fillDirent (struct stat const &st_, std::string_view const path_
buffer[pos++] = ' '; buffer[pos++] = ' ';
} }
#ifdef _3DS #ifdef __3DS__
auto const owner = "3DS"; auto const owner = "3DS";
auto const group = "3DS"; auto const group = "3DS";
#elif defined(__SWITCH__) #elif defined(__SWITCH__)
@ -989,7 +989,7 @@ int FtpSession::fillDirent (struct stat const &st_, std::string_view const path_
// clang-format off // clang-format off
S_ISREG (st_.st_mode) ? '-' : S_ISREG (st_.st_mode) ? '-' :
S_ISDIR (st_.st_mode) ? 'd' : S_ISDIR (st_.st_mode) ? 'd' :
#if !defined(_3DS) && !defined(__SWITCH__) #if !defined(__3DS__) && !defined(__SWITCH__)
S_ISLNK (st_.st_mode) ? 'l' : S_ISLNK (st_.st_mode) ? 'l' :
S_ISCHR (st_.st_mode) ? 'c' : S_ISCHR (st_.st_mode) ? 'c' :
S_ISBLK (st_.st_mode) ? 'b' : S_ISBLK (st_.st_mode) ? 'b' :
@ -1648,7 +1648,7 @@ bool FtpSession::listTransfer ()
auto const fullPath = buildPath (m_lwd, dent->d_name); auto const fullPath = buildPath (m_lwd, dent->d_name);
struct stat st; struct stat st;
#ifdef _3DS #ifdef __3DS__
// the sdmc directory entry already has the type and size, so no need to do a slow stat // the sdmc directory entry already has the type and size, so no need to do a slow stat
auto const dp = static_cast<DIR *> (m_dir); auto const dp = static_cast<DIR *> (m_dir);
auto const magic = *reinterpret_cast<u32 *> (dp->dirData->dirStruct); auto const magic = *reinterpret_cast<u32 *> (dp->dirData->dirStruct);
@ -2226,7 +2226,7 @@ void FtpSession::PASV (char const *args_)
// create an address to bind // create an address to bind
struct sockaddr_in addr = m_commandSocket->sockName (); struct sockaddr_in addr = m_commandSocket->sockName ();
#if defined(NDS) || defined(_3DS) #if defined(NDS) || defined(__3DS__)
static std::uint16_t ephemeralPort = 5001; static std::uint16_t ephemeralPort = 5001;
if (ephemeralPort > 10000) if (ephemeralPort > 10000)
ephemeralPort = 5001; ephemeralPort = 5001;
@ -2550,7 +2550,7 @@ void FtpSession::SITE (char const *args_)
" Set username: SITE USER <NAME>\r\n" " Set username: SITE USER <NAME>\r\n"
" Set password: SITE PASS <PASS>\r\n" " Set password: SITE PASS <PASS>\r\n"
" Set port: SITE PORT <PORT>\r\n" " Set port: SITE PORT <PORT>\r\n"
#ifdef _3DS #ifdef __3DS__
" Set getMTime: SITE MTIME [0|1]\r\n" " Set getMTime: SITE MTIME [0|1]\r\n"
#endif #endif
" Save config: SITE SAVE\r\n" " Save config: SITE SAVE\r\n"
@ -2608,7 +2608,7 @@ void FtpSession::SITE (char const *args_)
sendResponse ("200 OK\r\n"); sendResponse ("200 OK\r\n");
return; return;
} }
#ifdef _3DS #ifdef __3DS__
else if (::strcasecmp (command.c_str (), "MTIME") == 0) else if (::strcasecmp (command.c_str (), "MTIME") == 0)
{ {
if (arg == "0") if (arg == "0")

View File

@ -26,7 +26,7 @@
#include <zstd.h> #include <zstd.h>
#endif #endif
#if !defined(NDS) && !defined(_3DS) && !defined(__SWITCH__) #if !defined(NDS) && !defined(__3DS__) && !defined(__SWITCH__)
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#endif #endif
@ -52,7 +52,7 @@ char const *const g_mitLicense =
"ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE " "ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE "
"SOFTWARE."; "SOFTWARE.";
#ifdef _3DS #ifdef __3DS__
char const *const g_libctruVersion = "libctru"; char const *const g_libctruVersion = "libctru";
char const *const g_citro3dVersion = "citro3d"; char const *const g_citro3dVersion = "citro3d";
@ -125,7 +125,7 @@ char const *const g_zlibLicense =
"3. This notice may not be removed or altered from any source distribution."; "3. This notice may not be removed or altered from any source distribution.";
#endif #endif
#if !defined(NDS) && !defined(_3DS) && !defined(__SWITCH__) #if !defined(NDS) && !defined(__3DS__) && !defined(__SWITCH__)
#define STR(x) #x #define STR(x) #x
#define XSTR(x) STR (x) #define XSTR(x) STR (x)
#define GLFW_VERSION_STRING \ #define GLFW_VERSION_STRING \

View File

@ -29,7 +29,7 @@
namespace namespace
{ {
#ifdef _3DS #ifdef __3DS__
/// \brief Maximum number of log messages to keep /// \brief Maximum number of log messages to keep
constexpr auto MAX_LOGS = 250; constexpr auto MAX_LOGS = 250;
#else #else

View File

@ -65,7 +65,7 @@ SockAddr::SockAddr (struct sockaddr_in const &addr_)
assert (m_addr.ss_family == AF_INET); assert (m_addr.ss_family == AF_INET);
} }
#ifndef _3DS #ifndef __3DS__
SockAddr::SockAddr (struct sockaddr_in6 const &addr_) SockAddr::SockAddr (struct sockaddr_in6 const &addr_)
: SockAddr (reinterpret_cast<struct sockaddr const &> (addr_)) : SockAddr (reinterpret_cast<struct sockaddr const &> (addr_))
{ {
@ -84,7 +84,7 @@ SockAddr::operator struct sockaddr_in const & () const
return reinterpret_cast<struct sockaddr_in const &> (m_addr); return reinterpret_cast<struct sockaddr_in const &> (m_addr);
} }
#ifndef _3DS #ifndef __3DS__
SockAddr::operator struct sockaddr_in6 const & () const SockAddr::operator struct sockaddr_in6 const & () const
{ {
assert (m_addr.ss_family == AF_INET6); assert (m_addr.ss_family == AF_INET6);