From e8fc08387bc54be815b176afa8c4e2dcffa59c7b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 16 Oct 2021 17:19:23 -0400 Subject: Import refactored xdg.c from pounce --- database.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'database.h') diff --git a/database.h b/database.h index 15704f0..4de1625 100644 --- a/database.h +++ b/database.h @@ -41,11 +41,10 @@ #define SQL(...) #__VA_ARGS__ #define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0])) -const char *configPath(const char **dirs, const char *path); -const char *dataPath(const char **dirs, const char *path); +char *configPath(char *buf, size_t cap, const char *path, int i); +char *dataPath(char *buf, size_t cap, const char *path, int i); FILE *configOpen(const char *path, const char *mode); FILE *dataOpen(const char *path, const char *mode); -void dataMkdir(const char *path); int getopt_config( int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longindex @@ -114,13 +113,14 @@ static inline void dbFind(const char *path, int flags) { errx(EX_NOINPUT, "%s: database not found", path); } + char buf[PATH_MAX]; if (flags & SQLITE_OPEN_CREATE) { - dataMkdir(""); + int error = mkdir(dataPath(buf, sizeof(buf), "", 0), S_IRWXU); + if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", buf); } - const char *dirs = NULL; - while (NULL != (path = dataPath(&dirs, DatabasePath))) { - dbOpen(path, flags); + for (int i = 0; dataPath(buf, sizeof(buf), DatabasePath, i); ++i) { + dbOpen(buf, flags); if (db) return; } errx(EX_NOINPUT, "database not found; initialize it with litterbox -i"); -- cgit 1.4.1
path: root/bin/dtch.c (unfollow)
Commit message (Collapse)Author
2019-02-18Clean up htmlHeaderJune McEnroe
2019-02-18Remove hi line numberingJune McEnroe
Tags are much better for referring to specific parts of a file and line numbering is better done by a post-processing tool such as cat -n or producing a two-column HTML <table>.
2019-02-18Add Tag class to hiJune McEnroe
2019-02-17Generate HTML with hi -n -f html -o anchorJune McEnroe
Running hi twice to insert stuff between the head and the content is a bit of a hack but oh well.
2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe
2019-02-17Simplify temp trap in upJune McEnroe
2019-02-17Add line numbers to hiJune McEnroe
Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow.
2019-02-17Always split spans after newlinesJune McEnroe
Simplifies ANSI and IRC output code, and prepares for line numbered output.
2019-02-15Color format specifiers light cyan in vimJune McEnroe
2019-02-15Highlight Interp as yellowJune McEnroe
2019-02-15Highlight strings in sh command substitutionsJune McEnroe
2019-02-15Add nmap gpJune McEnroe
2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe
2019-02-13Add forgotten "sixth" book of H2G2June McEnroe