Under the assumption that strcmp() is cheaper than memory allocation,
let's avoid the allocation, if the new value is identical to the old.
/* Replaces a string pointer with an strdup()ed new string,
* possibly freeing the old one. */
/* Replaces a string pointer with an strdup()ed new string,
* possibly freeing the old one. */
+ if (streq_ptr(*p, s))
+ return 0;
+
if (s) {
t = strdup(s);
if (!t)
if (s) {
t = strdup(s);
if (!t)
}
int sethostname_idempotent(const char *s) {
}
int sethostname_idempotent(const char *s) {