From de6746127b335345e0a1c89cdd330e8968182218 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 23 Feb 2018 16:15:54 -0500 Subject: Clean up fbclock You can't use the return value of gzerror to check if an error occurred or not. Its implementation actually checks if the internal error is NULL and returns the empty string if it is! This is stupid and unhelpful, so check gzeof first since its return value actually means something. --- bin/fbclock.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'bin/fbclock.c') diff --git a/bin/fbclock.c b/bin/fbclock.c index 480a4b6d..b1039d80 100644 --- a/bin/fbclock.c +++ b/bin/fbclock.c @@ -44,30 +44,40 @@ static const uint32_t BG = 0x1D2021; static const uint32_t FG = 0xA99A84; int main() { - size_t count; + size_t len; const char *fontPath = getenv("FONT"); - if (!fontPath) fontPath = "/usr/share/kbd/consolefonts/Lat2-Terminus16.psfu.gz"; + if (!fontPath) { + fontPath = "/usr/share/kbd/consolefonts/Lat2-Terminus16.psfu.gz"; + } gzFile font = gzopen(fontPath, "r"); if (!font) err(EX_NOINPUT, "%s", fontPath); struct Psf2Header header; - count = gzfread(&header, sizeof(header), 1, font); - if (!count) errx(EX_IOERR, "%s: %s", fontPath, gzerror(font, NULL)); + len = gzfread(&header, sizeof(header), 1, font); + if (!len && gzeof(font)) errx(EX_DATAERR, "%s: missing header", fontPath); + if (!len) errx(EX_IOERR, "%s", gzerror(font, NULL)); if (header.magic != PSF2_MAGIC) { - errx(EX_DATAERR, "%s: invalid header magic %#x", fontPath, header.magic); + errx( + EX_DATAERR, "%s: invalid header magic %08x", + fontPath, header.magic + ); } if (header.headerSize != sizeof(struct Psf2Header)) { - errx(EX_DATAERR, "%s: weird header size %d", fontPath, header.headerSize); + errx( + EX_DATAERR, "%s: weird header size %d", + fontPath, header.headerSize + ); } uint8_t glyphs[128][header.glyphSize]; - count = gzfread(glyphs, header.glyphSize, 128, font); - if (!count) errx(EX_IOERR, "%s: %s", fontPath, gzerror(font, NULL)); + len = gzfread(glyphs, header.glyphSize, 128, font); + if (!len && gzeof(font)) errx(EX_DATAERR, "%s: missing glyphs", fontPath); + if (!len) errx(EX_IOERR, "%s", gzerror(font, NULL)); - assert(Z_OK == gzclose(font)); + gzclose(font); const char *fbPath = getenv("FRAMEBUFFER"); if (!fbPath) fbPath = "/dev/fb0"; @@ -79,8 +89,8 @@ int main() { int error = ioctl(fb, FBIOGET_VSCREENINFO, &info); if (error) err(EX_IOERR, "%s", fbPath); - size_t len = 4 * info.xres * info.yres; - uint32_t *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); + size_t size = 4 * info.xres * info.yres; + uint32_t *buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); if (buf == MAP_FAILED) err(EX_IOERR, "%s", fbPath); for (;;) { @@ -90,10 +100,10 @@ int main() { if (!local) err(EX_OSERR, "localtime"); char str[64]; - size_t len = strftime(str, sizeof(str), "%H:%M", local); + len = strftime(str, sizeof(str), "%H:%M", local); assert(len); - for (int i = 0; i < (60 - local->tm_sec); ++i) { + for (int i = 0; i < (60 - local->tm_sec); ++i, sleep(1)) { uint32_t left = info.xres - header.glyphWidth * len; uint32_t bottom = header.glyphHeight; @@ -105,7 +115,7 @@ int main() { } for (const char *s = str; *s; ++s) { - uint8_t *glyph = glyphs[(uint8_t)*s]; + const uint8_t *glyph = glyphs[(unsigned)*s]; uint32_t stride = header.glyphSize / header.glyphHeight; for (uint32_t y = 0; y < header.glyphHeight; ++y) { for (uint32_t x = 0; x < header.glyphWidth; ++x) { @@ -116,8 +126,6 @@ int main() { } left += header.glyphWidth; } - - sleep(1); } } } -- cgit 1.4.1 mit/ui-tag.c?id=696a33b66f8638d5c3e0464d66760c6d60ff24a5&follow=1'>tag: move layout into page functionJohn Keeping 2015-08-14summary: move layout into page functionJohn Keeping 2015-08-14stats: move layout into page functionJohn Keeping 2015-08-14refs: move layout to page functionJohn Keeping 2015-08-14log: move layout into page functionJohn Keeping 2015-08-14diff: move layout to page functionJohn Keeping 2015-08-14commit: move layout into page functionJohn Keeping 2015-08-14about: move layout into page functionsJohn Keeping 2015-08-14ui-shared: add cgit_print_layout_{start,end}()John Keeping 2015-08-14html: remove html_status()John Keeping 2015-08-14snapshot: don't reimplement cgit_print_error_page()John Keeping 2015-08-14snapshot: use cgit_print_error_page() for HTTP status codesJohn Keeping 2015-08-14patch: use cgit_print_error_page() for HTTP status codesJohn Keeping 2015-08-14blob: use cgit_print_error_page() to add HTTP headersJohn Keeping 2015-08-14snapshot: use cgit_print_error_page() instead of html_status()John Keeping 2015-08-14plain: use cgit_print_error_page() instead of html_status()John Keeping 2015-08-14clone: use cgit_print_error_page() instead of html_status()John Keeping 2015-08-14cgit: use cgit_print_error_page() where appropriateJohn Keeping 2015-08-14ui-shared: add cgit_print_error_page() functionJohn Keeping 2015-08-14ui-patch: make sure to send http headersChristian Hesse 2015-08-13Makefile: make "git/config.mak.uname" inclusion optionalJohn Keeping 2015-08-13ui-shared: show full date in tooltip if longer ago than max_relativeJohn Keeping 2015-08-13ui-shared: use common function in print_rel_date()John Keeping 2015-08-13ui-shared: extract date formatting to a functionJohn Keeping 2015-08-13filter: don't use dlsym unnecessarilyJohn Keeping 2015-08-13ui-tree: use "sane" isgraph()John Keeping 2015-08-13cgit.h: move stdbool.h from ui-shared.hJohn Keeping 2015-08-13cache.c: fix header orderJohn Keeping 2015-08-13configfile.c: don't include system headers directlyJohn Keeping 2015-08-13Remove redundant includesJohn Keeping 2015-08-13Makefile: include Git's config.mak.unameJohn Keeping 2015-08-13tests: allow shell to be overriddenJohn Keeping 2015-08-13redirect: cleanlinessJason A. Donenfeld 2015-08-13redirect: be more careful for different cgi setupsJason A. Donenfeld 2015-08-12ui-log: fix double countingJohn Keeping 2015-08-12log: allow users to follow a fileJohn Keeping 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld 2015-08-12filters: apply HTML escapingLazaros Koromilas 2015-08-12git: update to v2.5.0Christian Hesse 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt