mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 22:42:31 +02:00
Cleanup add brace (#6545)
* Add braces after if conditions
* More add braces after if conditions
* Add braces after while() conditions
* Fix compilation because of macro being modified
* Add braces to for loop
* Add braces after if/goto
* Move comments up
* Remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements after merge
* Fix inconsistent patterns are xxx == NULL vs !xxx
* More "{}" for "if() break;" and "if() continue;"
* More "{}" after if() short statement
* More "{}" after "if () return;" statement
* More fix inconsistent patterns are xxx == NULL vs !xxx
* Revert some modificaion on SDL_RLEaccel.c
* SDL_RLEaccel: no short statement
* Cleanup 'if' where the bracket is in a new line
* Cleanup 'while' where the bracket is in a new line
* Cleanup 'for' where the bracket is in a new line
* Cleanup 'else' where the bracket is in a new line
(cherry picked from commit 6a2200823c to reduce conflicts merging between SDL2 and SDL3)
This commit is contained in:
committed by
Sam Lantinga
parent
0739d237ad
commit
fb0ce375f0
@@ -47,7 +47,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
if (path) {
|
||||
size_t pathlen = SDL_strlen(path)+2;
|
||||
char *fullpath = (char *)SDL_malloc(pathlen);
|
||||
if (!fullpath) {
|
||||
if (fullpath == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -47,17 +47,17 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -71,8 +71,9 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
goto error;
|
||||
}
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ SDL_GetBasePath(void)
|
||||
|
||||
const size_t len = SDL_strlen(str);
|
||||
char *retval = (char *) SDL_malloc(len + 2);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -77,11 +77,11 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
const char *append = "/config/settings/";
|
||||
size_t len = SDL_strlen(home);
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
}
|
||||
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
char *retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
if (*org) {
|
||||
|
||||
@@ -41,8 +41,9 @@ SDL_GetBasePath(void)
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
len = SDL_strlen(cwd) + 1;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (retval)
|
||||
if (retval) {
|
||||
SDL_memcpy(retval, cwd, len);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -56,15 +57,17 @@ static void recursive_mkdir(const char *dir) {
|
||||
|
||||
snprintf(tmp, sizeof(tmp),"%s",dir);
|
||||
len = strlen(tmp);
|
||||
if (tmp[len - 1] == '/')
|
||||
if (tmp[len - 1] == '/') {
|
||||
tmp[len - 1] = 0;
|
||||
}
|
||||
|
||||
for (p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') {
|
||||
*p = 0;
|
||||
// Just creating subfolders from current path
|
||||
if (strstr(tmp, base) != NULL)
|
||||
if (strstr(tmp, base) != NULL) {
|
||||
mkdir(tmp, S_IRWXU);
|
||||
}
|
||||
|
||||
*p = '/';
|
||||
}
|
||||
@@ -80,11 +83,11 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if(!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +52,11 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if(!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -39,22 +39,23 @@ SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
|
||||
{
|
||||
const char *const in_buf = buffer; /* = NULL if we allocate the buffer. */
|
||||
|
||||
if (!buffer) {
|
||||
if (buffer == NULL) {
|
||||
/* This matches the logic in __unixify, with an additional byte for the
|
||||
* extra path separator.
|
||||
*/
|
||||
buf_len = SDL_strlen(ro_path) + 14 + 1;
|
||||
buffer = SDL_malloc(buf_len);
|
||||
|
||||
if (!buffer) {
|
||||
if (buffer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!__unixify_std(ro_path, buffer, buf_len, filetype)) {
|
||||
if (!in_buf)
|
||||
if (in_buf == NULL) {
|
||||
SDL_free(buffer);
|
||||
}
|
||||
|
||||
SDL_SetError("Could not convert '%s' to a Unix-style path", ro_path);
|
||||
return NULL;
|
||||
@@ -93,7 +94,7 @@ canonicalisePath(const char *path, const char *pathVar)
|
||||
|
||||
regs.r[5] = 1 - regs.r[5];
|
||||
buf = SDL_malloc(regs.r[5]);
|
||||
if (!buf) {
|
||||
if (buf == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -123,8 +124,9 @@ createDirectoryRecursive(char *path)
|
||||
*ptr = '\0';
|
||||
error = _kernel_swi(OS_File, ®s, ®s);
|
||||
*ptr = '.';
|
||||
if (error != NULL)
|
||||
if (error != NULL) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _kernel_swi(OS_File, ®s, ®s);
|
||||
@@ -143,14 +145,15 @@ SDL_GetBasePath(void)
|
||||
}
|
||||
|
||||
canon = canonicalisePath((const char *)regs.r[0], "Run$Path");
|
||||
if (!canon) {
|
||||
if (canon == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* chop off filename. */
|
||||
ptr = SDL_strrchr(canon, '.');
|
||||
if (ptr != NULL)
|
||||
if (ptr != NULL) {
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED);
|
||||
SDL_free(canon);
|
||||
@@ -164,22 +167,22 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
size_t len;
|
||||
_kernel_oserror *error;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
canon = canonicalisePath("<Choices$Write>", "Run$Path");
|
||||
if (!canon) {
|
||||
if (canon == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
dir = (char *) SDL_malloc(len);
|
||||
if (!dir) {
|
||||
if (dir == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(canon);
|
||||
return NULL;
|
||||
|
||||
@@ -52,8 +52,7 @@ readSymLink(const char *path)
|
||||
ssize_t len = 64;
|
||||
ssize_t rc = -1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
char *ptr = (char *) SDL_realloc(retval, (size_t) len);
|
||||
if (ptr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
@@ -88,13 +87,13 @@ static char *search_path_for_binary(const char *bin)
|
||||
char *start = envr;
|
||||
char *ptr;
|
||||
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
SDL_SetError("No $PATH set");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
envr = SDL_strdup(envr);
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -143,7 +142,7 @@ SDL_GetBasePath(void)
|
||||
const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||
if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
|
||||
retval = SDL_strdup(fullpath);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -157,13 +156,13 @@ SDL_GetBasePath(void)
|
||||
if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
|
||||
char *exe, *pwddst;
|
||||
char *realpathbuf = (char *) SDL_malloc(PATH_MAX + 1);
|
||||
if (!realpathbuf) {
|
||||
if (realpathbuf == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdline = SDL_malloc(len);
|
||||
if (!cmdline) {
|
||||
if (cmdline == NULL) {
|
||||
SDL_free(realpathbuf);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
@@ -201,7 +200,7 @@ SDL_GetBasePath(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_free(realpathbuf);
|
||||
}
|
||||
|
||||
@@ -210,7 +209,7 @@ SDL_GetBasePath(void)
|
||||
#endif
|
||||
|
||||
/* is a Linux-style /proc filesystem available? */
|
||||
if (!retval && (access("/proc", F_OK) == 0)) {
|
||||
if (retval == NULL && (access("/proc", F_OK) == 0)) {
|
||||
/* !!! FIXME: after 2.0.6 ships, let's delete this code and just
|
||||
use the /proc/%llu version. There's no reason to have
|
||||
two copies of this plus all the #ifdefs. --ryan. */
|
||||
@@ -265,8 +264,9 @@ SDL_GetBasePath(void)
|
||||
if (retval != NULL) {
|
||||
/* try to shrink buffer... */
|
||||
char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
|
||||
if (ptr != NULL)
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
if (ptr != NULL) {
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
@@ -288,18 +288,18 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
/* You end up with "$HOME/.local/share/Game Name 2" */
|
||||
envr = SDL_getenv("HOME");
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
/* we could take heroic measures with /etc/passwd, but oh well. */
|
||||
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
|
||||
return NULL;
|
||||
@@ -310,12 +310,13 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
}
|
||||
|
||||
len = SDL_strlen(envr);
|
||||
if (envr[len - 1] == '/')
|
||||
if (envr[len - 1] == '/') {
|
||||
append += 1;
|
||||
}
|
||||
|
||||
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -329,8 +330,9 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
goto error;
|
||||
}
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,11 +55,11 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
|
||||
len += SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ SDL_GetBasePath(void)
|
||||
|
||||
while (SDL_TRUE) {
|
||||
void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
|
||||
if (!ptr) {
|
||||
if (ptr == NULL) {
|
||||
SDL_free(path);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
@@ -101,11 +101,11 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
size_t new_wpath_len = 0;
|
||||
BOOL api_result = FALSE;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
|
||||
}
|
||||
|
||||
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
if (!ucs2Path) {
|
||||
if (ucs2Path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -128,14 +128,14 @@ SDL_GetBasePath(void)
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
if (srcPath == NULL) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + 2;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
if (destPath == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -161,16 +161,16 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
size_t new_wpath_len = 0;
|
||||
BOOL api_result = FALSE;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
|
||||
if ( ! srcPath) {
|
||||
if (srcPath == NULL) {
|
||||
SDL_SetError("Unable to find a source path");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user