path.c
This file
Path
path.c
102 lines · 3.0 KiB · C
Last changed by
path/xdg/main: include errno(3) description in more LOG_WARN() messagesCraig Barnesbefore adoptionab9a3dc
History of this fileTake it
The walk stopped after 200 commits: lines older than c18512f point at it.
docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 1–4why, one step back1#include "path.h"2#include "application.h"3#include "tllist.h"4path/xdg/main: include errno(3) description in more LOG_WARN() messagesCraig Barnesbefore adoptionab9a3dc
line 5why, one step back5#include <errno.h>docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 6–18why, one step back6#include <string.h>7#include <fcntl.h>8#include <sys/types.h>9#include <sys/stat.h>10#include <dirent.h>11#include <stdlib.h>12#include <stdio.h>1314#define LOG_MODULE "path"15#define LOG_ENABLE_DBG 016#include "log.h"17#include "xdg.h"18#include "char32.h"Add xmalloc.h and xsnprintf.h and use to improve/simplify error handlingCraig Barnesbefore adoption539d514
line 19why, one step back19#include "xmalloc.h"docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 20–28why, one step back2021void22path_find_programs(struct application_list *applications)23{24 const char *_path = getenv("PATH");2526 if (_path == NULL)27 return ;28Add xmalloc.h and xsnprintf.h and use to improve/simplify error handlingCraig Barnesbefore adoption539d514
line 29why, one step back29 char *copy = xstrdup(_path);docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
line 30why, one step back30 char *ctx = NULL;dmenu: start rendering input before STDIN has been closedDaniel Eklöfbefore adoptionb69ba92
lines 31–32why, one step back31 tll(struct application *) entries = tll_init();32docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 33–38why, one step back33 for (const char *tok = strtok_r(copy, ":", &ctx);34 tok != NULL;35 tok = strtok_r(NULL, ":", &ctx))36 {37 DIR *d = opendir(tok);38 if (d == NULL) {path/xdg/main: include errno(3) description in more LOG_WARN() messagesCraig Barnesbefore adoptionab9a3dc
line 39why, one step back39 LOG_WARN("failed to open %s from PATH: %s", tok, strerror(errno));docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 40–43why, one step back40 continue;41 }42 int fd = dirfd(d);43 if (fd == -1) {path/xdg/main: include errno(3) description in more LOG_WARN() messagesCraig Barnesbefore adoptionab9a3dc
line 44why, one step back44 LOG_WARN("failed to open %s's fd from PATH: %s", tok, strerror(errno));docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 45–53why, one step back45 closedir(d);46 continue;47 }48 for (const struct dirent *e = readdir(d); e != NULL; e = readdir(d)) {49 if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0)50 continue;5152 struct stat st;53 if (fstatat(fd, e->d_name, &st, 0) == -1) {path/xdg/main: include errno(3) description in more LOG_WARN() messagesCraig Barnesbefore adoptionab9a3dc
line 54why, one step back54 LOG_WARN("%s: failed to stat: %s", e->d_name, strerror(errno));docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 55–62why, one step back55 continue;56 }57 if (S_ISREG(st.st_mode) && st.st_mode & S_IXUSR) {58 char32_t *wtitle = ambstoc32(e->d_name);59 if (wtitle == NULL)60 continue;61 bool already_exist = false;62 tll_foreach(entries, it) {dmenu: start rendering input before STDIN has been closedDaniel Eklöfbefore adoptionb69ba92
line 63why, one step back63 if (c32cmp(wtitle, it->item->title) == 0) {docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 64–71why, one step back64 already_exist = true;65 break;66 }67 };68 if (already_exist) {69 free(wtitle);70 continue;71 }path: initialize lower-case title, and the title-length fieldsDaniel Eklöfbefore adoptiona709f29
line 72why, one step back72Add xmalloc.h and xsnprintf.h and use to improve/simplify error handlingCraig Barnesbefore adoption539d514
line 73why, one step back73 char32_t *lowercase = xc32dup(wtitle);path: initialize lower-case title, and the title-length fieldsDaniel Eklöfbefore adoptiona709f29
lines 74–76why, one step back74 for (size_t i = 0; i < c32len(lowercase); i++)75 lowercase[i] = toc32lower(lowercase[i]);76Add xmalloc.h and xsnprintf.h and use to improve/simplify error handlingCraig Barnesbefore adoption539d514
line 77why, one step back77 struct application *app = xmalloc(sizeof(*app));dmenu: start rendering input before STDIN has been closedDaniel Eklöfbefore adoptionb69ba92
line 78why, one step back78 *app = (struct application){path: initialize lower-case title, and the title-length fieldsDaniel Eklöfbefore adoptiona709f29
line 79why, one step back79 .index = 0, /* Not used in application mode */docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
line 80why, one step back80 .title = wtitle,path: initialize lower-case title, and the title-length fieldsDaniel Eklöfbefore adoptiona709f29
lines 81–82why, one step back81 .title_lowercase = lowercase,82 .title_len = c32len(lowercase),Add xmalloc.h and xsnprintf.h and use to improve/simplify error handlingCraig Barnesbefore adoption539d514
line 83why, one step back83 .exec = xstrjoin3(tok, "/", e->d_name),docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 84–93why, one step back84 .visible = true,85 };8687 tll_push_back(entries, app);88 }89 }90 closedir(d);91 }92 free(copy);93Add xmalloc.h and xsnprintf.h and use to improve/simplify error handlingCraig Barnesbefore adoption539d514
line 94why, one step back94 applications->v = xreallocarray(docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 95–98why, one step back95 applications->v, applications->count + tll_length(entries), sizeof(applications->v[0]));9697 tll_foreach(entries, it) {98 applications->v[applications->count++] = it->item;xdg: don't count NoDisplay=true apps towards the match counter's totalChristian Fillionbefore adoptiondb12816
line 99why, one step back99 applications->visible_count++;docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f
lines 100–102why, one step back100 tll_remove(entries, it);101 }102}