X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=99836953bfafd8853ba3d217476b5cd42139b9f2;hb=c1e5704657315b436c0409e8172c1fcb76adccad;hp=402b7caa3f56a015e3ff687402d94f36b9eadb7a;hpb=f8b69d1dfc307562a353f6aa923b7c2b915aaddb;p=elogind.git diff --git a/src/shared/util.c b/src/shared/util.c index 402b7caa3..99836953b 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -57,6 +57,8 @@ #include #include #include +#include +#include #include "macro.h" #include "util.h" @@ -75,6 +77,10 @@ char **saved_argv = NULL; static volatile unsigned cached_columns = 0; static volatile unsigned cached_lines = 0; +bool is_efiboot(void) { + return access("/sys/firmware/efi", F_OK) >= 0; +} + size_t page_size(void) { static __thread size_t pgsz = 0; long r; @@ -6115,3 +6121,45 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, } return NULL; } + +bool is_locale_utf8(void) { + const char *set; + static int cached_answer = -1; + + if (cached_answer >= 0) + goto out; + + if (!setlocale(LC_ALL, "")) { + cached_answer = true; + goto out; + } + + set = nl_langinfo(CODESET); + if (!set) { + cached_answer = true; + goto out; + } + + cached_answer = streq(set, "UTF-8"); +out: + return (bool)cached_answer; +} + +const char *draw_special_char(DrawSpecialChar ch) { + static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = { + /* UTF-8 */ { + [DRAW_BOX_VERT] = "\342\224\202", /* │ */ + [DRAW_BOX_VERT_AND_RIGHT] = "\342\224\234", /* ├ */ + [DRAW_BOX_UP_AND_RIGHT] = "\342\224\224", /* └ */ + [DRAW_TRIANGULAR_BULLET] = "\342\200\243", /* ‣ */ + }, + /* ASCII fallback */ { + [DRAW_BOX_VERT] = "|", + [DRAW_BOX_VERT_AND_RIGHT] = "+", + [DRAW_BOX_UP_AND_RIGHT] = "\\", + [DRAW_TRIANGULAR_BULLET] = ">", + } + }; + + return draw_table[!is_locale_utf8()][ch]; +}