mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-04 09:50:17 +01:00
core: reuse common static string buffer in nm_utils_dnsmasq_status_to_string()
Instead of declaring our local string buffer @buffer, reuse nm_utils_to_string_buffer_init(). https://github.com/NetworkManager/NetworkManager/pull/8
This commit is contained in:
parent
fe7d12a010
commit
d66b5e79c7
2 changed files with 11 additions and 19 deletions
|
|
@ -3242,12 +3242,11 @@ nm_utils_lifetime_get (guint32 timestamp,
|
|||
}
|
||||
|
||||
const char *
|
||||
nm_utils_dnsmasq_status_to_string (int status, char *dest, guint size)
|
||||
nm_utils_dnsmasq_status_to_string (int status, char *dest, gsize size)
|
||||
{
|
||||
static char buffer[128];
|
||||
char *msg, *ret;
|
||||
gs_free char *msg_free = NULL;
|
||||
int len;
|
||||
const char *msg;
|
||||
|
||||
nm_utils_to_string_buffer_init (&dest, &size);
|
||||
|
||||
if (status == 0)
|
||||
msg = "Success";
|
||||
|
|
@ -3261,20 +3260,13 @@ nm_utils_dnsmasq_status_to_string (int status, char *dest, guint size)
|
|||
msg = "Memory allocation failure";
|
||||
else if (status == 5)
|
||||
msg = "Other problem";
|
||||
else if (status >= 11)
|
||||
msg = msg_free = g_strdup_printf ("Lease script failed with error %d", status - 10);
|
||||
else if (status >= 11) {
|
||||
g_snprintf (dest, size, "Lease script failed with error %d", status - 10);
|
||||
return dest;
|
||||
}
|
||||
else
|
||||
msg = "Unknown problem";
|
||||
|
||||
if (dest) {
|
||||
ret = dest;
|
||||
len = size;
|
||||
} else {
|
||||
ret = buffer;
|
||||
len = sizeof (buffer);
|
||||
}
|
||||
|
||||
g_snprintf (ret, len, "%s (%d)", msg, status);
|
||||
|
||||
return ret;
|
||||
g_snprintf (dest, size, "%s (%d)", msg, status);
|
||||
return dest;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -404,6 +404,6 @@ gboolean nm_utils_lifetime_get (guint32 timestamp,
|
|||
|
||||
gboolean nm_utils_ip4_address_is_link_local (in_addr_t addr);
|
||||
|
||||
const char *nm_utils_dnsmasq_status_to_string (int status, char *dest, guint size);
|
||||
const char *nm_utils_dnsmasq_status_to_string (int status, char *dest, gsize size);
|
||||
|
||||
#endif /* __NM_CORE_UTILS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue