From 93e4b15767cf958d5a07ba6acce25438f244bf22 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 29 May 2022 13:23:19 +1000 Subject: Cleanup: clang-tidy for GHOST X11/SDL/Wayland/NULL backends Also early exit in some functions. --- intern/ghost/intern/GHOST_SystemPathsUnix.cpp | 51 +++++++++++++-------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'intern/ghost/intern/GHOST_SystemPathsUnix.cpp') diff --git a/intern/ghost/intern/GHOST_SystemPathsUnix.cpp b/intern/ghost/intern/GHOST_SystemPathsUnix.cpp index d2c678855f2..41babc5d312 100644 --- a/intern/ghost/intern/GHOST_SystemPathsUnix.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsUnix.cpp @@ -17,8 +17,8 @@ #include #include +#include /* for fprintf only */ #include /* for exit */ -#include /* for fprintf only */ #include /* for get home without use getenv() */ #include @@ -28,7 +28,7 @@ using std::string; #ifdef PREFIX static const char *static_path = PREFIX "/share"; #else -static const char *static_path = NULL; +static const char *static_path = nullptr; #endif GHOST_SystemPathsUnix::GHOST_SystemPathsUnix() @@ -39,7 +39,7 @@ GHOST_SystemPathsUnix::~GHOST_SystemPathsUnix() { } -const char *GHOST_SystemPathsUnix::getSystemDir(int, const char *versionstr) const +const char *GHOST_SystemPathsUnix::getSystemDir(int /*version*/, const char *versionstr) const { /* no prefix assumes a portable build which only uses bundled scripts */ if (static_path) { @@ -47,7 +47,7 @@ const char *GHOST_SystemPathsUnix::getSystemDir(int, const char *versionstr) con return system_path.c_str(); } - return NULL; + return nullptr; } const char *GHOST_SystemPathsUnix::getUserDir(int version, const char *versionstr) const @@ -67,32 +67,29 @@ const char *GHOST_SystemPathsUnix::getUserDir(int version, const char *versionst user_path = string(home) + "/.blender/" + versionstr; } else { - return NULL; + return nullptr; } } return user_path.c_str(); } - else { - if (user_path.empty() || last_version != version) { - const char *home = getenv("XDG_CONFIG_HOME"); - - last_version = version; + if (user_path.empty() || last_version != version) { + const char *home = getenv("XDG_CONFIG_HOME"); - if (home) { - user_path = string(home) + "/blender/" + versionstr; - } - else { - home = getenv("HOME"); + last_version = version; - if (home == NULL) - home = getpwuid(getuid())->pw_dir; - - user_path = string(home) + "/.config/blender/" + versionstr; + if (home) { + user_path = string(home) + "/blender/" + versionstr; + } + else { + home = getenv("HOME"); + if (home == nullptr) { + home = getpwuid(getuid())->pw_dir; } + user_path = string(home) + "/.config/blender/" + versionstr; } - - return user_path.c_str(); } + + return user_path.c_str(); } const char *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const @@ -135,7 +132,7 @@ const char *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDirTypes GHOST_ASSERT( false, "GHOST_SystemPathsUnix::getUserSpecialDir(): Invalid enum value for type parameter"); - return NULL; + return nullptr; } static string path = ""; @@ -143,8 +140,8 @@ const char *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDirTypes string command = string("xdg-user-dir ") + type_str + " 2> /dev/null"; FILE *fstream = popen(command.c_str(), "r"); - if (fstream == NULL) { - return NULL; + if (fstream == nullptr) { + return nullptr; } std::stringstream path_stream; while (!feof(fstream)) { @@ -157,7 +154,7 @@ const char *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDirTypes } if (pclose(fstream) == -1) { perror("GHOST_SystemPathsUnix::getUserSpecialDir failed at pclose()"); - return NULL; + return nullptr; } if (!add_path.empty()) { @@ -165,12 +162,12 @@ const char *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDirTypes } path = path_stream.str(); - return path[0] ? path.c_str() : NULL; + return path[0] ? path.c_str() : nullptr; } const char *GHOST_SystemPathsUnix::getBinaryDir() const { - return NULL; + return nullptr; } void GHOST_SystemPathsUnix::addToSystemRecentFiles(const char * /*filename*/) const -- cgit v1.2.3