pid_filename = NULL;
tr_variantDictFindStr(settings, key_pidfile, &pid_filename, NULL);
- if (pid_filename != NULL && *pid_filename != '\0')
+ if (!tr_str_is_empty(pid_filename))
{
tr_error* error = NULL;
tr_sys_file_t fp = tr_sys_file_open(pid_filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, 0666,
force_generic = false;
}
- if (tr_variantDictFindStr(settings, TR_KEY_watch_dir, &dir, NULL) && dir != NULL && *dir != '\0')
+ if (tr_variantDictFindStr(settings, TR_KEY_watch_dir, &dir, NULL) && !tr_str_is_empty(dir))
{
tr_logAddInfo("Watching \"%s\" for new .torrent files", dir);
mixed_date |= date != infos[i]->dateCreated;
}
- gboolean const empty_creator = *creator == '\0';
+ gboolean const empty_creator = tr_str_is_empty(creator);
gboolean const empty_date = date == 0;
if (mixed_date || mixed_creator)
str = is_uniform ? baseline : mixed;
}
- if (str == NULL || *str == '\0')
+ if (tr_str_is_empty(str))
{
str = _("No errors");
}
g_string_append_printf(gstr, "<b>%s</b>\n%s\n \n", markup, addr);
g_free(markup);
- for (char const* pch = flagstr; pch != NULL && *pch != '\0'; ++pch)
+ for (char const* pch = flagstr; !tr_str_is_empty(pch); ++pch)
{
char const* s = NULL;
{
char* const str = tracker_strings[i];
- if (*str == '\0')
+ if (tr_str_is_empty(str))
{
++tier;
}
char* url = g_strdup(gtk_entry_get_text(GTK_ENTRY(e)));
g_strstrip(url);
- if (url != NULL && *url != '\0')
+ if (!tr_str_is_empty(url))
{
if (tr_urlIsValidTracker(url))
{
g_free(filename);
filename = tmp;
}
- while (filename != NULL && *filename != '\0' && !g_file_test(filename, G_FILE_TEST_EXISTS));
+ while (!tr_str_is_empty(filename) && !g_file_test(filename, G_FILE_TEST_EXISTS));
}
- if ((handled = filename != NULL && *filename != '\0'))
+ if ((handled = !tr_str_is_empty(filename)))
{
gtr_open_file(filename);
}
{
gboolean ret = FALSE;
- if (key == NULL || *key == '\0')
+ if (tr_str_is_empty(key))
{
ret = TRUE;
}
{
char* const str = tracker_strings[i];
- if (*str == '\0')
+ if (tr_str_is_empty(str))
{
++tier;
}
char buf[256];
getShortTransferString(tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof(buf));
- if (*buf != '\0')
+ if (!tr_str_is_empty(buf))
{
g_string_append_printf(gstr, " - %s", buf);
}
str = get_event_string(req);
- if (str != NULL && *str != '\0')
+ if (!tr_str_is_empty(str))
{
evbuffer_add_printf(buf, "&event=%s", str);
}
str = req->tracker_id_str;
- if (str != NULL && *str != '\0')
+ if (!tr_str_is_empty(str))
{
evbuffer_add_printf(buf, "&trackerid=%s", str);
}
{
struct tr_scrape_info* info = NULL;
- if (url != NULL && *url != '\0')
+ if (!tr_str_is_empty(url))
{
bool found;
struct tr_scrape_info const key = { .url = (char*)url };
tr_snprintf(buf, buflen, "Baidu Netdisk");
}
- if (*buf != '\0')
+ if (!tr_str_is_empty(buf))
{
return buf;
}
strint(id + 5, 2), getMnemonicEnd(id[7]));
}
- if (*buf != '\0')
+ if (!tr_str_is_empty(buf))
{
return buf;
}
mainline_style(buf, buflen, "Queen Bee", id);
}
- if (*buf != '\0')
+ if (!tr_str_is_empty(buf))
{
return buf;
}
}
/* Shad0w-style */
- if (*buf == '\0')
+ if (tr_str_is_empty(buf))
{
int a;
int b;
}
/* No match */
- if (*buf == '\0')
+ if (tr_str_is_empty(buf))
{
char out[32];
char* walk = out;
char* tr_sys_path_basename(char const* path, tr_error** error)
{
- if (path == NULL || path[0] == '\0')
+ if (tr_str_is_empty(path))
{
return tr_strdup(".");
}
char* tr_sys_path_dirname(char const* path, tr_error** error)
{
- if (path == NULL || path[0] == '\0')
+ if (tr_str_is_empty(path))
{
return tr_strdup(".");
}
#endif
- if (*buf != '\0')
+ if (!tr_str_is_empty(buf))
{
if (tr_logGetQueueEnabled())
{
if (uri != NULL && strncmp(uri, "magnet:?", 8) == 0)
{
- for (char const* walk = uri + 8; walk != NULL && *walk != '\0';)
+ for (char const* walk = uri + 8; !tr_str_is_empty(walk);)
{
char const* key = walk;
char const* delim = strchr(key, '=');
while ((token = tr_strsep(&walk, TR_PATH_DELIMITER_STR)) != NULL)
{
- if (*token != '\0')
+ if (!tr_str_is_empty(token))
{
tr_variantListAddStr(uninitialized_path, token);
}
if (builder->result == TR_MAKEMETA_OK && !builder->abortFlag)
{
- if (builder->comment != NULL && *builder->comment != '\0')
+ if (!tr_str_is_empty(builder->comment))
{
tr_variantDictAddStr(&top, TR_KEY_comment, builder->comment);
}
builder->comment = tr_strdup(comment);
builder->isPrivate = isPrivate;
- if (outputFile != NULL && *outputFile != '\0')
+ if (!tr_str_is_empty(outputFile))
{
builder->outputFile = tr_strdup(outputFile);
}
}
}
- if (str == NULL || *str == '\0')
+ if (tr_str_is_empty(str))
{
return "name";
}
static void maybeSetCongestionAlgorithm(tr_socket_t socket, char const* algorithm)
{
- if (algorithm != NULL && *algorithm != '\0')
+ if (!tr_str_is_empty(algorithm))
{
tr_netSetCongestionControl(socket, algorithm);
}
{
static char* s = NULL;
- if (appname == NULL || *appname == '\0')
+ if (tr_str_is_empty(appname))
{
appname = "Transmission";
}
/* figure out where to look for user-dirs.dirs */
config_home = tr_env_get_string("XDG_CONFIG_HOME", NULL);
- if (config_home != NULL && *config_home != '\0')
+ if (!tr_str_is_empty(config_home))
{
config_file = tr_buildPath(config_home, "user-dirs.dirs", NULL);
}
/* XDG_DATA_HOME should be the first in the list of candidates */
tmp = tr_env_get_string("XDG_DATA_HOME", NULL);
- if (tmp != NULL && *tmp != '\0')
+ if (!tr_str_is_empty(tmp))
{
tr_list_append(&candidates, tmp);
}
tr_free(xdg);
tmp = buf;
- while (tmp != NULL && *tmp != '\0')
+ while (!tr_str_is_empty(tmp))
{
char const* end = strchr(tmp, ':');
tmp = (char*)end + 1;
}
- else if (tmp != NULL && *tmp != '\0')
+ else if (!tr_str_is_empty(tmp))
{
tr_list_append(&candidates, tr_strdup(tmp));
break;
}
if ((fieldsToLoad & (TR_FR_PROGRESS | TR_FR_DOWNLOAD_DIR)) != 0 &&
- tr_variantDictFindStr(&top, TR_KEY_destination, &str, &len) && str != NULL && *str != '\0')
+ tr_variantDictFindStr(&top, TR_KEY_destination, &str, &len) && !tr_str_is_empty(str))
{
bool const is_current_dir = tor->currentDir == tor->downloadDir;
tr_free(tor->downloadDir);
}
if ((fieldsToLoad & (TR_FR_PROGRESS | TR_FR_INCOMPLETE_DIR)) != 0 &&
- tr_variantDictFindStr(&top, TR_KEY_incomplete_dir, &str, &len) && str != NULL && *str != '\0')
+ tr_variantDictFindStr(&top, TR_KEY_incomplete_dir, &str, &len) && !tr_str_is_empty(str))
{
bool const is_current_dir = tor->currentDir == tor->incompleteDir;
tr_free(tor->incompleteDir);
{
char const* path;
- if (tr_ctorGetDownloadDir(ctor, mode, &path) && path != NULL && *path != '\0')
+ if (tr_ctorGetDownloadDir(ctor, mode, &path) && !tr_str_is_empty(path))
{
ret |= TR_FR_DOWNLOAD_DIR;
tr_free(tor->downloadDir);
{
char const* webClientDir = tr_getWebClientDir(server->session);
- if (webClientDir == NULL || *webClientDir == '\0')
+ if (tr_str_is_empty(webClientDir))
{
send_simple_response(req, HTTP_NOTFOUND,
"<p>Couldn't find Transmission's web interface files!</p>"
else
{
char* filename = tr_strdup_printf("%s%s%s", webClientDir, TR_PATH_DELIMITER_STR,
- *subpath != '\0' ? subpath : "index.html");
+ tr_str_is_empty(subpath) ? "index.html" : subpath);
serve_file(req, server, filename);
tr_free(filename);
}
}
/* build the new whitelist entries */
- for (char const* walk = whitelistStr; walk != NULL && *walk != '\0';)
+ for (char const* walk = whitelistStr; !tr_str_is_empty(walk);)
{
char const* delimiters = " ,;";
size_t const len = strcspn(walk, delimiters);
{
char* label = tr_strndup(str, str_len);
tr_strstrip(label);
- if (*label == '\0')
+ if (tr_str_is_empty(label))
{
errmsg = "labels cannot be empty";
}
tr_sys_file_close(fd, NULL);
- if (*result != '\0')
+ if (!tr_str_is_empty(result))
{
tr_logAddError("%s", result);
}
tr_variantFree(&oldDict);
/* if caller didn't specify a config dir, use the default */
- if (configDir == NULL || *configDir == '\0')
+ if (tr_str_is_empty(configDir))
{
configDir = tr_getDefaultConfigDir(appName);
}
(*arguments)[arguments_len++] = ' ';
}
- if (argument[0] != '\0' && strpbrk(argument, " \t\n\v\"") == NULL)
+ if (!tr_str_is_empty(argument) && strpbrk(argument, " \t\n\v\"") == NULL)
{
*arguments = tr_renew(char, *arguments, arguments_len + argument_len + 2);
strcpy(*arguments + arguments_len, argument);
}
}
- if (name == NULL || *name == '\0')
+ if (tr_str_is_empty(name))
{
char* base = tr_sys_path_basename(filename, NULL);
args->downloadDir = NULL;
args->isSet_downloadDir = false;
- if (directory != NULL && *directory != '\0')
+ if (!tr_str_is_empty(directory))
{
args->isSet_downloadDir = true;
args->downloadDir = tr_strdup(directory);
name = inf->name;
- if (name != NULL && *name != '\0')
+ if (!tr_str_is_empty(name))
{
evbuffer_add_printf(s, "%s", "&dn=");
tr_http_escape(s, name, TR_BAD_SIZE, true);
static void torrentCallScript(tr_torrent const* tor, char const* script)
{
- if (script == NULL || *script == '\0')
+ if (tr_str_is_empty(script))
{
return;
}
static bool renameArgsAreValid(char const* oldpath, char const* newname)
{
- return oldpath != NULL && *oldpath != '\0' && newname != NULL && *newname != '\0' && strcmp(newname, ".") != 0 &&
- strcmp(newname, "..") != 0 && strchr(newname, TR_PATH_DELIMITER) == NULL;
+ return !tr_str_is_empty(oldpath) && !tr_str_is_empty(newname) && strcmp(newname, ".") != 0 && strcmp(newname, "..") != 0 &&
+ strchr(newname, TR_PATH_DELIMITER) == NULL;
}
static tr_file_index_t* renameFindAffectedFiles(tr_torrent* tor, char const* oldpath, size_t* setme_n)
#include <stdlib.h> /* exit() */
#include <string.h>
+#include "transmission.h"
#include "tr-getopt.h"
#include "tr-macros.h"
+#include "utils.h"
int tr_optind = 1;
int const d_width = 80 - d_indent;
char const* d = opt->description;
- printf(" %s%-*s %s%-*s %-*s ", (shortName != NULL && *shortName != '\0') ? "-" : " ", shortWidth, shortName,
- (longName != NULL && *longName != '\0') ? "--" : " ", longWidth, longName, argWidth, arg);
+ printf(" %s%-*s %s%-*s %-*s ", tr_str_is_empty(shortName) ? " " : "-", shortWidth, shortName,
+ tr_str_is_empty(longName) ? " " : "--", longWidth, longName, argWidth, arg);
len = get_next_line_len(d, d_width);
printf("%*.*s\n", len, len, d);
out = buf;
- for (; str != NULL && *str != '\0'; ++str)
+ for (; !tr_str_is_empty(str); ++str)
{
*out++ = *str;
{
int64_t free_space;
- if (dir == NULL || *dir == '\0')
+ if (tr_str_is_empty(dir))
{
errno = EINVAL;
free_space = -1;
walk = str;
- while (walk != NULL && *walk != '\0' && success)
+ while (!tr_str_is_empty(walk) && success)
{
struct number_range range;
char const* pch = strchr(walk, ',');
char const* value = getenv(key);
- if (value != NULL && *value != '\0')
+ if (!tr_str_is_empty(value))
{
return atoi(value);
}
*/
int tr_strcmp0(char const* str1, char const* str2);
+static inline bool tr_str_is_empty(char const* value)
+{
+ return value == NULL || *value == '\0';
+}
+
/**
* @brief like memcmp() but gracefully handles NULL pointers
*/
{
char* out = in;
- for (; in != NULL && *in != '\0'; ++in)
+ for (; !tr_str_is_empty(in); ++in)
{
if (!isspace(*in))
{
static void addIdArg(tr_variant* args, char const* id, char const* fallback)
{
- if (id == NULL || *id == '\0')
+ if (tr_str_is_empty(id))
{
id = fallback;
- if (id == NULL || *id == '\0')
+ if (tr_str_is_empty(id))
{
fprintf(stderr, "No torrent specified! Please use the -t option first.\n");
id = "-1"; /* no torrent will have this ID, so will act as a no-op */
while ((token = tr_strsep(&argcpy, ",")) != NULL)
{
tr_strstrip(token);
- if (*token != '\0')
+ if (!tr_str_is_empty(token))
{
tr_variantListAddStr(labels, token);
}
{
tr_variant* files = tr_variantDictAddList(args, key, 100);
- if (*arg == '\0')
+ if (tr_str_is_empty(arg))
{
fprintf(stderr, "No files specified!\n");
arg = "-1"; /* no file will have this index, so should be a no-op */
printf(" Corrupt DL: %s\n", buf);
}
- if (tr_variantDictFindStr(t, TR_KEY_errorString, &str, NULL) && str != NULL && *str != '\0' &&
+ if (tr_variantDictFindStr(t, TR_KEY_errorString, &str, NULL) && !tr_str_is_empty(str) &&
tr_variantDictFindInt(t, TR_KEY_error, &i) && i != 0)
{
switch (i)
printf(" Public torrent: %s\n", (boolVal ? "No" : "Yes"));
}
- if (tr_variantDictFindStr(t, TR_KEY_comment, &str, NULL) && str != NULL && *str != '\0')
+ if (tr_variantDictFindStr(t, TR_KEY_comment, &str, NULL) && !tr_str_is_empty(str))
{
printf(" Comment: %s\n", str);
}
- if (tr_variantDictFindStr(t, TR_KEY_creator, &str, NULL) && str != NULL && *str != '\0')
+ if (tr_variantDictFindStr(t, TR_KEY_creator, &str, NULL) && !tr_str_is_empty(str))
{
printf(" Creator: %s\n", str);
}
tr_variant* targs = NULL;
tr_variant* sargs = NULL;
- if (*id != '\0')
+ if (!tr_str_is_empty(id))
{
targs = ensure_tset(&tset);
}
printf(" Created by: %s\n", inf->creator ? inf->creator : "Unknown");
printf(" Created on: %s\n", unix_timestamp_to_str(inf->dateCreated));
- if (inf->comment != NULL && *inf->comment != '\0')
+ if (!tr_str_is_empty(inf->comment))
{
printf(" Comment: %s\n", inf->comment);
}