+char *ellipsize(const char *s, unsigned length, unsigned percent) {
+ size_t l, x;
+ char *r;
+
+ assert(s);
+ assert(percent <= 100);
+ assert(length >= 3);
+
+ l = strlen(s);
+
+ if (l <= 3 || l <= length)
+ return strdup(s);
+
+ if (!(r = new0(char, length+1)))
+ return r;
+
+ x = (length * percent) / 100;
+
+ if (x > length - 3)
+ x = length - 3;
+
+ memcpy(r, s, x);
+ r[x] = '.';
+ r[x+1] = '.';
+ r[x+2] = '.';
+ memcpy(r + x + 3,
+ s + l - (length - x - 3),
+ length - x - 3);
+
+ return r;
+}
+
+void nss_disable_nscd(void) {
+
+ void (*func)(void);
+
+ /* This is an internal glibc function call. We are not
+ * supposed to call this, because we are not nscd. However
+ * sometimes we feel really dangerous and do it
+ * nonetheless. Muahahah! But at least we protect this with a
+ * dlsym() just in case glibc takes this away from us. */
+
+ if ((func = dlsym(RTLD_DEFAULT, "__nss_disable_nscd"))) {
+ log_debug("Disabling nscd.");
+ func();
+ } else
+ log_debug("Cannot disable nscd.");
+}
+
+