#define FILENAME "/etc/hostname"
#elif defined(TARGET_ARCH)
#define FILENAME "/etc/rc.conf"
+#elif defined(TARGET_GENTOO)
+#define FILENAME "/etc/conf.d/hostname"
#endif
static int read_hostname(char **hn) {
-#if defined(TARGET_FEDORA) || defined(TARGET_ARCH)
+#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO)
int r;
FILE *f;
s = strstrip(line);
- if (!startswith(s, "HOSTNAME="))
+ if (!startswith_no_case(s, "HOSTNAME="))
continue;
if (!(k = strdup(s+9))) {
goto finish;
}
+ if (!(k = delete_chars(k, "\"\'"))) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
*hn = k;
break;
}
#include <sys/inotify.h>
#include <sys/poll.h>
#include <libgen.h>
+#include <ctype.h>
#include "macro.h"
#include "util.h"
return memcmp(s, prefix, pl) == 0;
}
+bool startswith_no_case(const char *s, const char *prefix) {
+ size_t sl, pl;
+ unsigned i;
+
+ assert(s);
+ assert(prefix);
+
+ sl = strlen(s);
+ pl = strlen(prefix);
+
+ if (pl == 0)
+ return true;
+
+ if (sl < pl)
+ return false;
+
+ for(i = 0; i < pl; ++i) {
+ if (tolower(s[i]) != tolower(prefix[i]))
+ return false;
+ }
+
+ return true;
+}
+
bool first_word(const char *s, const char *word) {
size_t sl, wl;
bool endswith(const char *s, const char *postfix);
bool startswith(const char *s, const char *prefix);
+bool startswith_no_case(const char *s, const char *prefix);
bool first_word(const char *s, const char *word);