sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 36f39ef21e2bd33fde6268e83917d8e282908aa2
parent cb8b93d71222d50b6afb2275fa56a6b332c34d26
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sat,  5 Jan 2019 23:16:59 +0100

build-page: rework online function

Diffstat:
Mbuild-page.c | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/build-page.c b/build-page.c @@ -135,20 +135,24 @@ oneline(char *buf, size_t bufsiz, char const *path) char *r; FILE *fp; + if (!buf || bufsiz == 0) + return 0; if (!(fp = fopen(path, "r"))) { perror(path); - return -1; + return 0; } - r = fgets(buf, bufsiz, fp); + + fgets(buf, bufsiz, fp); if (ferror(fp)) die_perror("fgets: %s", path); fclose(fp); - if (r) - buf[strcspn(buf, "\n")] = '\0'; + for (r = buf; *r && *r != '\n'; ++r) + ; + *r = '\0'; - return !!r; + return 1; } void @@ -180,10 +184,10 @@ print_header(void) { char title[TITLE_MAX]; - if (oneline(title, sizeof title, ".title") <= 0) - printf(html_header, TITLE_DEFAULT, TITLE_DEFAULT); - else + if (oneline(title, sizeof title, ".title")) printf(html_header, title, title); + else + printf(html_header, TITLE_DEFAULT, TITLE_DEFAULT); } void