]> granicus.if.org Git - transmission/commitdiff
Introduce `tr_str_is_empty` to relay intent better
authorMike Gelfand <mikedld@mikedld.com>
Sat, 13 Jul 2019 08:52:44 +0000 (11:52 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Sat, 13 Jul 2019 09:00:06 +0000 (12:00 +0300)
30 files changed:
daemon/daemon.c
gtk/details.c
gtk/file-list.c
gtk/filter.c
gtk/makemeta-ui.c
gtk/torrent-cell-renderer.c
libtransmission/announcer-http.c
libtransmission/announcer.c
libtransmission/clients.c
libtransmission/file-win32.c
libtransmission/log.c
libtransmission/magnet.c
libtransmission/makemeta.c
libtransmission/metainfo.c
libtransmission/peer-io.c
libtransmission/platform.c
libtransmission/resume.c
libtransmission/rpc-server.c
libtransmission/rpcimpl.c
libtransmission/session.c
libtransmission/subprocess-win32.c
libtransmission/torrent-ctor.c
libtransmission/torrent-magnet.c
libtransmission/torrent.c
libtransmission/tr-getopt.c
libtransmission/utils.c
libtransmission/utils.h
libtransmission/variant-test.c
utils/remote.c
utils/show.c

index 8790b19b2cee375a24d50d6e05e682b4d9149d01..05a14e5beca544e8aaf4df2b4fb609962d6bba7c 100644 (file)
@@ -649,7 +649,7 @@ static int daemon_start(void* raw_arg, bool foreground)
     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,
@@ -693,7 +693,7 @@ static int daemon_start(void* raw_arg, bool foreground)
             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);
 
index 3a01eaad8bb54dc67504c8d0116baf7b6c013795..2709e6cd4847fc9ba347e641b830b34049f74273 100644 (file)
@@ -721,7 +721,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
             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)
@@ -1079,7 +1079,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
         str = is_uniform ? baseline : mixed;
     }
 
-    if (str == NULL || *str == '\0')
+    if (tr_str_is_empty(str))
     {
         str = _("No errors");
     }
@@ -1760,7 +1760,7 @@ static gboolean onPeerViewQueryTooltip(GtkWidget* widget, gint x, gint y, gboole
         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;
 
@@ -2515,7 +2515,7 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
             {
                 char* const str = tracker_strings[i];
 
-                if (*str == '\0')
+                if (tr_str_is_empty(str))
                 {
                     ++tier;
                 }
@@ -2661,7 +2661,7 @@ static void on_add_tracker_response(GtkDialog* dialog, int response, gpointer gd
         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))
             {
index 6d547404f52a8a38bcbbe867ba4a5d25369622fb..a521f37a68456d14d3813d734764215abc0a6587 100644 (file)
@@ -679,10 +679,10 @@ static gboolean onRowActivated(GtkTreeView* view, GtkTreePath* path, GtkTreeView
                     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);
             }
index f30f5ce6ccbd460862e372fa329c12c006187e75..80271052181eafa6fdda5989d80ef38ee2749920 100644 (file)
@@ -703,7 +703,7 @@ static gboolean testText(tr_torrent const* tor, char const* key)
 {
     gboolean ret = FALSE;
 
-    if (key == NULL || *key == '\0')
+    if (tr_str_is_empty(key))
     {
         ret = TRUE;
     }
index ab15306a9a5e45a9131358c1ae92a0ceaad6b996..5ab58049544478a531f082e7537b8a382c4948ab 100644 (file)
@@ -252,7 +252,7 @@ static void onResponse(GtkDialog* d, int response, gpointer user_data)
             {
                 char* const str = tracker_strings[i];
 
-                if (*str == '\0')
+                if (tr_str_is_empty(str))
                 {
                     ++tier;
                 }
index 3e9f187a00000ba2ba7eb7b4db601f2b9c8a8093..eaf332a42bec80bc59ac787d78aa06a554fb7af0 100644 (file)
@@ -298,7 +298,7 @@ static void getStatusString(GString* gstr, tr_torrent const* tor, tr_stat const*
         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);
         }
index 5eec61afa6dc999113623ded6983489d5c250b01..dbeee1daae3a45e4b87deca1255ba8e00435aca6 100644 (file)
@@ -94,14 +94,14 @@ static char* announce_url_new(tr_session const* session, tr_announce_request con
 
     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);
     }
index 193d716a15b750995640618902ac1a8d7beb8100..33ac3f10fbd89f1f7374ccabcacc42344a7a0c00 100644 (file)
@@ -183,7 +183,7 @@ static struct tr_scrape_info* tr_announcerGetScrapeInfo(struct tr_announcer* ann
 {
     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 };
index 1f63d44e11c86952e58e40322ebb7d7fdc6ff636..81d4cbddb027e747f2bfbc01372b2d5dd66ea8ae 100644 (file)
@@ -639,7 +639,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
             tr_snprintf(buf, buflen, "Baidu Netdisk");
         }
 
-        if (*buf != '\0')
+        if (!tr_str_is_empty(buf))
         {
             return buf;
         }
@@ -664,7 +664,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
                 strint(id + 5, 2), getMnemonicEnd(id[7]));
         }
 
-        if (*buf != '\0')
+        if (!tr_str_is_empty(buf))
         {
             return buf;
         }
@@ -683,7 +683,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
             mainline_style(buf, buflen, "Queen Bee", id);
         }
 
-        if (*buf != '\0')
+        if (!tr_str_is_empty(buf))
         {
             return buf;
         }
@@ -806,7 +806,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
     }
 
     /* Shad0w-style */
-    if (*buf == '\0')
+    if (tr_str_is_empty(buf))
     {
         int a;
         int b;
@@ -856,7 +856,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
     }
 
     /* No match */
-    if (*buf == '\0')
+    if (tr_str_is_empty(buf))
     {
         char out[32];
         char* walk = out;
index 83e3fbaf66c5326adb934dece6c3d87485b530ca..998898259a0268a10743bad4fb1322c15662a334 100644 (file)
@@ -595,7 +595,7 @@ cleanup:
 
 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(".");
     }
@@ -635,7 +635,7 @@ char* tr_sys_path_basename(char const* path, tr_error** error)
 
 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(".");
     }
index 56241e77a9a9192ba69700fc1a5ba16c70026773..51aeacfc1cbad3137e32c1aa1c4c9b33f7b90ea8 100644 (file)
@@ -246,7 +246,7 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
 
 #endif
 
-    if (*buf != '\0')
+    if (!tr_str_is_empty(buf))
     {
         if (tr_logGetQueueEnabled())
         {
index 5196a2c4adb2b6c403784845fdae7536b60e2aef..9cdc0c2165dc7603bdb611ac63e0622cace7c7c6 100644 (file)
@@ -122,7 +122,7 @@ tr_magnet_info* tr_magnetParse(char const* uri)
 
     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, '=');
index 481dc2a3db85c7be72a7aaba27fc5326ef776e8d..0418a50a532e16fb2625b901529fa66ca160f637 100644 (file)
@@ -376,7 +376,7 @@ static void getFileInfo(char const* topFile, tr_metainfo_builder_file const* fil
 
         while ((token = tr_strsep(&walk, TR_PATH_DELIMITER_STR)) != NULL)
         {
-            if (*token != '\0')
+            if (!tr_str_is_empty(token))
             {
                 tr_variantListAddStr(uninitialized_path, token);
             }
@@ -479,7 +479,7 @@ static void tr_realMakeMetaInfo(tr_metainfo_builder* builder)
 
     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);
         }
@@ -596,7 +596,7 @@ void tr_makeMetaInfo(tr_metainfo_builder* builder, char const* outputFile, tr_tr
     builder->comment = tr_strdup(comment);
     builder->isPrivate = isPrivate;
 
-    if (outputFile != NULL && *outputFile != '\0')
+    if (!tr_str_is_empty(outputFile))
     {
         builder->outputFile = tr_strdup(outputFile);
     }
index 18e757a7fdd8f672a15d56b3708f22e1f61a2aaf..e42065ab3eec81238af4c16a2913944eb81e4ede 100644 (file)
@@ -621,7 +621,7 @@ static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf,
             }
         }
 
-        if (str == NULL || *str == '\0')
+        if (tr_str_is_empty(str))
         {
             return "name";
         }
index 25ba0e4f6993dd55914285c3490c56be3dd689e5..41fe3489196cf2abc52824f626e862e424b1806d 100644 (file)
@@ -431,7 +431,7 @@ error:
 
 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);
     }
index 4a8de7c4fab75a4c96ee3d7b01f416dfd75c12f8..f9889ec383bd36390335625f38e5ce250aea6b2f 100644 (file)
@@ -328,7 +328,7 @@ char const* tr_getDefaultConfigDir(char const* appname)
 {
     static char* s = NULL;
 
-    if (appname == NULL || *appname == '\0')
+    if (tr_str_is_empty(appname))
     {
         appname = "Transmission";
     }
@@ -390,7 +390,7 @@ char const* tr_getDefaultDownloadDir(void)
         /* 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);
         }
@@ -576,7 +576,7 @@ char const* tr_getWebClientDir(tr_session const* session UNUSED)
             /* 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);
             }
@@ -596,7 +596,7 @@ char const* tr_getWebClientDir(tr_session const* session UNUSED)
                 tr_free(xdg);
                 tmp = buf;
 
-                while (tmp != NULL && *tmp != '\0')
+                while (!tr_str_is_empty(tmp))
                 {
                     char const* end = strchr(tmp, ':');
 
@@ -609,7 +609,7 @@ char const* tr_getWebClientDir(tr_session const* session UNUSED)
 
                         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;
index c438c7eb029a9202a725f1827d7614bcfbaf18be..1d95cfe216d97fdd50e248011220342e37ede0df 100644 (file)
@@ -847,7 +847,7 @@ static uint64_t loadFromFile(tr_torrent* tor, uint64_t fieldsToLoad, bool* didRe
     }
 
     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);
@@ -862,7 +862,7 @@ static uint64_t loadFromFile(tr_torrent* tor, uint64_t fieldsToLoad, bool* didRe
     }
 
     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);
@@ -1024,7 +1024,7 @@ static uint64_t setFromCtor(tr_torrent* tor, uint64_t fields, tr_ctor const* cto
     {
         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);
index 6660a8480f7d84a99c7e26247ea13d85315998f8..fdd6fbbc1acf0086306ff9b21ecb3d23b9496cb2 100644 (file)
@@ -430,7 +430,7 @@ static void handle_web_client(struct evhttp_request* req, struct tr_rpc_server*
 {
     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>"
@@ -461,7 +461,7 @@ static void handle_web_client(struct evhttp_request* req, struct tr_rpc_server*
         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);
         }
@@ -938,7 +938,7 @@ static void tr_rpcSetList(char const* whitelistStr, tr_list** list)
     }
 
     /* 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);
index b510bb7474d4614dfcbeefd1da90d5c0e9444948..b0dcd23c4a186971f74a823fa829f3c1a7d37d85 100644 (file)
@@ -960,7 +960,7 @@ static char const* setLabels(tr_torrent* tor, tr_variant* list)
         {
             char* label = tr_strndup(str, str_len);
             tr_strstrip(label);
-            if (*label == '\0')
+            if (tr_str_is_empty(label))
             {
                 errmsg = "labels cannot be empty";
             }
@@ -1641,7 +1641,7 @@ static void gotNewBlocklist(tr_session* session, bool did_connect UNUSED, bool d
 
         tr_sys_file_close(fd, NULL);
 
-        if (*result != '\0')
+        if (!tr_str_is_empty(result))
         {
             tr_logAddError("%s", result);
         }
index 7623fcc1b82da23120241a4284c70d8c6fbd8f25..32c69a1521d09575b47385b107c78da7e40026f2 100644 (file)
@@ -487,7 +487,7 @@ bool tr_sessionLoadSettings(tr_variant* dict, char const* configDir, char const*
     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);
     }
index 67653a63cf1722b813ee33c404978d6a66f53cc1..709268bf03eb9fb0578580754a488de245285c55 100644 (file)
@@ -253,7 +253,7 @@ static void append_argument(char** arguments, char const* argument)
         (*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);
index 6e56f487907f9191a957b27d386c1f8c3bca58da..ae8289d90e84aa486d0cd19afca316840981e086 100644 (file)
@@ -159,7 +159,7 @@ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename)
                 }
             }
 
-            if (name == NULL || *name == '\0')
+            if (tr_str_is_empty(name))
             {
                 char* base = tr_sys_path_basename(filename, NULL);
 
@@ -338,7 +338,7 @@ void tr_ctorSetDownloadDir(tr_ctor* ctor, tr_ctorMode mode, char const* director
     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);
index aaad93cacb50856669cbb23e703400d19c0bf785..e720e617255d4dd3852414292dc2f47c0ea9a3b8 100644 (file)
@@ -418,7 +418,7 @@ char* tr_torrentInfoGetMagnetLink(tr_info const* inf)
 
     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);
index 4b629169cc8e3978958dea646893714f6cc2bda2..35962028b602bbb858269f7c45795d414dff4645 100644 (file)
@@ -2233,7 +2233,7 @@ static void get_local_time_str(char* const buffer, size_t const buffer_len)
 
 static void torrentCallScript(tr_torrent const* tor, char const* script)
 {
-    if (script == NULL || *script == '\0')
+    if (tr_str_is_empty(script))
     {
         return;
     }
@@ -3794,8 +3794,8 @@ void tr_torrentSetQueueStartCallback(tr_torrent* torrent, void (* callback)(tr_t
 
 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)
index a41b67a8289fff09f6bb90c82b1ff0714802bd4b..bc2e4805372f41f2879684b1b869cd2a3fbee83b 100644 (file)
 #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;
 
@@ -67,8 +69,8 @@ static void getopts_usage_line(tr_option const* opt, int longWidth, int shortWid
     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);
 
index ab2fc446eecc8d330468c4b7b864ad480b19ae15..35c2fde090bd114cd0a738e9d95a65a56b712268 100644 (file)
@@ -192,7 +192,7 @@ char const* tr_strip_positional_args(char const* str)
 
     out = buf;
 
-    for (; str != NULL && *str != '\0'; ++str)
+    for (; !tr_str_is_empty(str); ++str)
     {
         *out++ = *str;
 
@@ -363,7 +363,7 @@ int64_t tr_getDirFreeSpace(char const* dir)
 {
     int64_t free_space;
 
-    if (dir == NULL || *dir == '\0')
+    if (tr_str_is_empty(dir))
     {
         errno = EINVAL;
         free_space = -1;
@@ -1526,7 +1526,7 @@ int* tr_parseNumberRange(char const* str_in, size_t len, int* setmeCount)
 
     walk = str;
 
-    while (walk != NULL && *walk != '\0' && success)
+    while (!tr_str_is_empty(walk) && success)
     {
         struct number_range range;
         char const* pch = strchr(walk, ',');
@@ -2110,7 +2110,7 @@ int tr_env_get_int(char const* key, int default_value)
 
     char const* value = getenv(key);
 
-    if (value != NULL && *value != '\0')
+    if (!tr_str_is_empty(value))
     {
         return atoi(value);
     }
index 9dacc246b45e621ac55b482ed5b0e6efd5ea6fff..6b650aa8958538e643a5bc0a5b092259a061d761 100644 (file)
@@ -202,6 +202,11 @@ char* tr_strdup(void const* in);
  */
 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
  */
index b734444ec2c9df76536913fabb10f0f0dfc432d9..7b7a6f6ad930c168cb9682e393f62dfb3a471bcf 100644 (file)
@@ -323,7 +323,7 @@ static void stripWhitespace(char* in)
 {
     char* out = in;
 
-    for (; in != NULL && *in != '\0'; ++in)
+    for (; !tr_str_is_empty(in); ++in)
     {
         if (!isspace(*in))
         {
index 1408611d80f4956a9d6e4bf473e15b56b4c0382c..ab6f415e30c5c152bb8a57725edf53429fb25cc3 100644 (file)
@@ -548,11 +548,11 @@ static char* getEncodedMetainfo(char const* filename)
 
 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 */
@@ -666,7 +666,7 @@ static void addLabels(tr_variant* args, char const* arg)
     while ((token = tr_strsep(&argcpy, ",")) != NULL)
     {
         tr_strstrip(token);
-        if (*token != '\0')
+        if (!tr_str_is_empty(token))
         {
             tr_variantListAddStr(labels, token);
         }
@@ -679,7 +679,7 @@ static void addFiles(tr_variant* args, tr_quark const key, char const* arg)
 {
     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 */
@@ -1058,7 +1058,7 @@ static void printDetails(tr_variant* top)
                 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)
@@ -1150,12 +1150,12 @@ static void printDetails(tr_variant* top)
                 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);
             }
@@ -2608,7 +2608,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
             tr_variant* targs = NULL;
             tr_variant* sargs = NULL;
 
-            if (*id != '\0')
+            if (!tr_str_is_empty(id))
             {
                 targs = ensure_tset(&tset);
             }
index d70a7c58bf4cc40b27ad31abc1486a7a16ceb652..067bf35b97c15e7bce291fc198457cd0cbdcba8f 100644 (file)
@@ -142,7 +142,7 @@ static void showInfo(tr_info const* inf)
     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);
     }