X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.c;h=9d99fefe78b8ce5e373e52e91084988d8c938893;hb=825636e5a88338436a1cd910319d020038389187;hp=83e819a0cb769decb718148ab02af4a3bb9b8f61;hpb=24a6e4a401f0be0c4cd67621186792d0b7e401a1;p=elogind.git diff --git a/util.c b/util.c index 83e819a0c..9d99fefe7 100644 --- a/util.c +++ b/util.c @@ -114,6 +114,9 @@ bool endswith(const char *s, const char *postfix) { sl = strlen(s); pl = strlen(postfix); + if (pl == 0) + return true; + if (sl < pl) return false; @@ -129,6 +132,9 @@ bool startswith(const char *s, const char *prefix) { sl = strlen(s); pl = strlen(prefix); + if (pl == 0) + return true; + if (sl < pl) return false; @@ -147,11 +153,14 @@ bool first_word(const char *s, const char *word) { if (sl < wl) return false; + if (wl == 0) + return true; + if (memcmp(s, word, wl) != 0) return false; - return (s[wl] == 0 || - strchr(WHITESPACE, s[wl])); + return s[wl] == 0 || + strchr(WHITESPACE, s[wl]); } int close_nointr(int fd) { @@ -1420,10 +1429,14 @@ int ask(char *ret, const char *replies, const char *text, ...) { int r; bool need_nl = true; + fputs("\x1B[1m", stdout); + va_start(ap, text); vprintf(text, ap); va_end(ap); + fputs("\x1B[0m", stdout); + fflush(stdout); if ((r = read_one_char(stdin, &c, &need_nl)) < 0) {