all: drop str_if_set() in favor of the "?:" operator

str_if_set() was added to replace the non-standard gcc extension "?:".
However, "?:" is supported by clang as well and we already use it at
several places.

Also, str_if_set() did not follow our naming scheme and renaming to
nm_str_if_set() would be ugly. So just drop it.
This commit is contained in:
Thomas Haller 2016-03-08 17:41:31 +01:00
parent 24d96e6f65
commit b36d721525
15 changed files with 16 additions and 32 deletions

View file

@ -158,7 +158,7 @@ _update_s390_subchannels (NMDeviceEthernet *self)
dev = (GUdevDevice *) nm_platform_link_get_udev_device (NM_PLATFORM_GET, ifindex);
if (!dev) {
_LOGW (LOGD_DEVICE | LOGD_HW, "failed to find device %d '%s' with udev",
ifindex, str_if_set (nm_device_get_iface (NM_DEVICE (self)), "(null)"));
ifindex, nm_device_get_iface (NM_DEVICE (self)) ?: "(null)");
goto out;
}
g_object_ref (dev);

View file

@ -36,7 +36,7 @@ _nm_device_log_self_to_device (t *self) \
#define _NMLOG(level, domain, ...) \
nm_log_obj ((level), (domain), (self), "device", \
"(%s): " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
(self) ? str_if_set (nm_device_get_iface (_nm_device_log_self_to_device (self)), "(null)") : "(none)" \
(self) ? (nm_device_get_iface (_nm_device_log_self_to_device (self)) ?: "(null)") : "(none)" \
_NM_UTILS_MACRO_REST(__VA_ARGS__))
#endif /* __NETWORKMANAGER_DEVICE_LOGGING_H__ */

View file

@ -741,7 +741,7 @@ nm_ap_dump (NMAccessPoint *self,
nm_log_dbg (LOGD_WIFI_SCAN, "%s[%s%c] %-32s[%s%u %3u%% %c W:%04X R:%04X] [%3u] %s%s",
prefix,
str_if_set (priv->address, "(none)"),
priv->address ?: "(none)",
mode_to_char (self),
priv->ssid ? nm_utils_escape_ssid (priv->ssid->data, priv->ssid->len) : "(none)",
chan > 99 ? "" : (chan > 9 ? " " : " "),

View file

@ -178,7 +178,7 @@ void
nm_main_utils_ensure_root ()
{
if (getuid () != 0) {
fprintf (stderr, _("You must be root to run %s!\n"), str_if_set (g_get_prgname (), ""));
fprintf (stderr, _("You must be root to run %s!\n"), g_get_prgname () ?: "");
exit (1);
}
}

View file

@ -145,22 +145,6 @@ int nm_spawn_process (const char *args, GError **error);
int nm_utils_modprobe (GError **error, gboolean suppress_error_loggin, const char *arg1, ...) G_GNUC_NULL_TERMINATED;
/**
* str_if_set:
* @str: input string that will be returned if @str is not %NULL
* @fallback: if @str is %NULL, return @fallback instead
*
* This utility function is useful when printing a string to avoid passing
* %NULL. E.g. printf ("%s", str_if_set (get_string(), "(none)"));
*
* Returns: either @str or @fallback, depending on whether @str is %NULL.
*/
static inline const char *
str_if_set (const char *str, const char *fallback)
{
return str ? str : fallback;
}
guint64 nm_utils_get_start_time_for_pid (pid_t pid, char *out_state, pid_t *out_ppid);
void nm_utils_kill_process_sync (pid_t pid, guint64 start_time, int sig, guint64 log_domain,

View file

@ -1315,7 +1315,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
g_message (" nis: %s", nm_utils_inet4_ntop (tmp, NULL));
}
g_message (" nisdmn: %s", str_if_set (nm_ip4_config_get_nis_domain (config), "(none)"));
g_message (" nisdmn: %s", nm_ip4_config_get_nis_domain (config) ?: "(none)");
/* WINS */
for (i = 0; i < nm_ip4_config_get_num_wins (config); i++) {

View file

@ -725,11 +725,11 @@ nm_log_handler (const gchar *log_domain,
boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1);
sd_journal_send ("PRIORITY=%d", syslog_priority,
"MESSAGE=%s", str_if_set (message, ""),
"MESSAGE=%s", message ?: "",
"SYSLOG_IDENTIFIER=%s", G_LOG_DOMAIN,
"SYSLOG_PID=%ld", (long) getpid (),
"SYSLOG_FACILITY=GLIB",
"GLIB_DOMAIN=%s", str_if_set (log_domain, ""),
"GLIB_DOMAIN=%s", log_domain ?: "",
"GLIB_LEVEL=%d", (int) (level & G_LOG_LEVEL_MASK),
"TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000),
"TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000),
@ -738,7 +738,7 @@ nm_log_handler (const gchar *log_domain,
break;
#endif
default:
syslog (syslog_priority, "%s", str_if_set (message, ""));
syslog (syslog_priority, "%s", message ?: "");
break;
}
}

View file

@ -2827,7 +2827,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
_LOGD (LOGD_CORE, "Activation of '%s' depends on active connection %p %s",
nm_settings_connection_get_id (connection),
master_ac,
str_if_set (nm_exported_object_get_path (NM_EXPORTED_OBJECT (master_ac)), ""));
nm_exported_object_get_path (NM_EXPORTED_OBJECT (master_ac)) ?: "");
}
/* Check slaves for master connection and possibly activate them */

View file

@ -4018,7 +4018,7 @@ link_get_type_name (NMPlatform *platform, int ifindex)
return nm_link_type_to_string (obj->link.type);
}
/* Link type not detected. Fallback to rtnl_link_get_type()/IFLA_INFO_KIND. */
return str_if_set (obj->link.kind, "unknown");
return obj->link.kind ?: "unknown";
}
static gboolean

View file

@ -3081,7 +3081,7 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
str_flags->str,
link->mtu, master,
link->arptype,
str_if_set (str_link_type, "???"),
str_link_type ?: "???",
link->kind ? (g_strcmp0 (str_link_type, link->kind) ? "/" : "*") : "?",
link->kind && g_strcmp0 (str_link_type, link->kind) ? link->kind : "",
link->initialized ? " init" : " not-init",

View file

@ -1664,7 +1664,7 @@ test_create_many_links (gconstpointer user_data)
guint n_devices = GPOINTER_TO_UINT (user_data);
if (n_devices > 100 && nmtst_test_quick ()) {
g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", str_if_set (g_get_prgname (), "test-link-linux"));
g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", g_get_prgname () ?: "test-link-linux");
g_test_skip ("Skip long running test");
return;
}

View file

@ -431,7 +431,7 @@ main (int argc, char **argv)
nmtst_init_with_logging (&argc, &argv, NULL, "DEFAULT");
if (nmtst_test_quick ()) {
g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", str_if_set (g_get_prgname (), "test-rdisc-fake"));
g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", g_get_prgname () ?: "test-rdisc-fake");
return g_test_run ();
}

View file

@ -26,7 +26,7 @@
#include "shvar.h"
#include "common.h"
#define NM_IFCFG_CONNECTION_LOG_PATH(path) str_if_set (path,"in-memory")
#define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"

View file

@ -27,7 +27,7 @@
#define KEYFILE_PLUGIN_NAME "keyfile"
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define NM_KEYFILE_CONNECTION_LOG_PATH(path) str_if_set (path,"in-memory")
#define NM_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NM_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
#define NM_KEYFILE_CONNECTION_LOG_ARG(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
#define NM_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"

View file

@ -196,7 +196,7 @@ __LOG_create_prefix (char *buf, NMVpnConnection *self)
"]",
_NMLOG_PREFIX_NAME,
self,
con ? "," : "--", con ? str_if_set (nm_connection_get_uuid (con), "??") : "",
con ? "," : "--", con ? (nm_connection_get_uuid (con) ?: "??") : "",
con ? "," : "", NM_PRINT_FMT_QUOTED (id, "\"", id, "\"", con ? "??" : ""),
priv->ip_ifindex,
priv->ip_iface ? ":" : "", NM_PRINT_FMT_QUOTED (priv->ip_iface, "(", priv->ip_iface, ")", "")