fe

terminal file explorer and picker

git clone https://9o.is/git/fe.git

commit 02575e229d6de2bd3d6ac6d10a0397edd9f790e6
parent ce6744ef97d9e20db66397671d3ebf64ae6a7162
Author: Jul <jul@9o.is>
Date:   Sun, 18 Jan 2026 10:39:45 -0500

use static functions where appropriate

Diffstat:
Mentries.c | 24++++++++++++------------
Mtty.c | 32++++++++++++++++----------------
Mtty.h | 2--
3 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/entries.c b/entries.c @@ -22,14 +22,14 @@ static int sort_icase; static int sort_mtime; static int show_hidden; -void *xrealloc(void *p, size_t size) { +static void *xrealloc(void *p, size_t size) { p = realloc(p, size); if (p == NULL) exit(1); return p; } -char *xdirname(const char *path) { +static char *xdirname(const char *path) { static char out[PATH_MAX]; char tmp[PATH_MAX], *p; @@ -41,7 +41,7 @@ char *xdirname(const char *path) { return out; } -int dircmp(mode_t a, mode_t b) { +static int dircmp(mode_t a, mode_t b) { if (S_ISDIR(a) && S_ISDIR(b)) return 0; if (!S_ISDIR(a) && !S_ISDIR(b)) @@ -52,7 +52,7 @@ int dircmp(mode_t a, mode_t b) { return 1; } -int entrycmp(const void *va, const void *vb) { +static int entrycmp(const void *va, const void *vb) { const struct entry *a = va, *b = vb; if (sort_dir && dircmp(a->mode, b->mode) != 0) @@ -64,7 +64,7 @@ int entrycmp(const void *va, const void *vb) { return strcmp(a->name, b->name); } -int canopendir(char *path) { +static int canopendir(char *path) { DIR *dirp; dirp = opendir(path); @@ -76,7 +76,7 @@ int canopendir(char *path) { return 1; } -char *mkpath(char *dir, char *name, char *out, size_t n) { +static char *mkpath(char *dir, char *name, char *out, size_t n) { if (name[0] == '/') { strlcpy(out, name, n); } else { @@ -92,7 +92,7 @@ char *mkpath(char *dir, char *name, char *out, size_t n) { return out; } -int dentfill(char *path, struct entry **dents) { +static int dentfill(char *path, struct entry **dents) { char newpath[PATH_MAX]; DIR *dirp; struct dirent *dp; @@ -147,7 +147,7 @@ int dentfill(char *path, struct entry **dents) { return n; } -int dentfind(struct entry *dents, int n, char *cwd, const char *path) { +static int dentfind(struct entry *dents, int n, char *cwd, const char *path) { char tmp[PATH_MAX]; int i; @@ -161,7 +161,7 @@ int dentfind(struct entry *dents, int n, char *cwd, const char *path) { return 0; } -int filetype(char *path) { +static int filetype(char *path) { int fd = open(path, O_RDONLY | O_NONBLOCK); if (fd == -1) return 0; @@ -174,7 +174,7 @@ int filetype(char *path) { return sb.st_mode & S_IFMT; } -int set_directory(entries_t *entries, char *path) { +static int set_directory(entries_t *entries, char *path) { if (canopendir(path) == 0) return -1; @@ -195,7 +195,7 @@ int set_directory(entries_t *entries, char *path) { return 0; } -void set_path(entries_t *entries, char *path) { +static void set_path(entries_t *entries, char *path) { if (filetype(path) == S_IFDIR) { set_directory(entries, path); } else { @@ -211,7 +211,7 @@ void set_path(entries_t *entries, char *path) { } } -void truncate_at_newline(const char *buffer) { +static void truncate_at_newline(const char *buffer) { char *newline_pos = strchr(buffer, '\n'); if (newline_pos != NULL) { *newline_pos = '\0'; diff --git a/tty.c b/tty.c @@ -9,20 +9,31 @@ #include <errno.h> #include "tty.h" -void tty_reset(tty_t *tty) { +static void tty_reset(tty_t *tty) { tcsetattr(tty->fdin, TCSANOW, &tty->original_termios); } +static void handle_sigwinch(int sig){ + (void)sig; +} + +static void tty_getwinsz(tty_t *tty) { + struct winsize ws; + if (ioctl(fileno(tty->fout), TIOCGWINSZ, &ws) == -1) { + tty->maxwidth = 80; + tty->maxheight = 25; + } else { + tty->maxwidth = ws.ws_col; + tty->maxheight = ws.ws_row; + } +} + void tty_close(tty_t *tty) { tty_reset(tty); fclose(tty->fout); close(tty->fdin); } -static void handle_sigwinch(int sig){ - (void)sig; -} - void tty_init(tty_t *tty, const char *tty_filename) { tty->fdin = open(tty_filename, O_RDONLY); if (tty->fdin < 0) { @@ -68,17 +79,6 @@ void tty_init(tty_t *tty, const char *tty_filename) { signal(SIGWINCH, handle_sigwinch); } -void tty_getwinsz(tty_t *tty) { - struct winsize ws; - if (ioctl(fileno(tty->fout), TIOCGWINSZ, &ws) == -1) { - tty->maxwidth = 80; - tty->maxheight = 25; - } else { - tty->maxwidth = ws.ws_col; - tty->maxheight = ws.ws_row; - } -} - char tty_getchar(tty_t *tty) { char ch; int size = read(tty->fdin, &ch, 1); diff --git a/tty.h b/tty.h @@ -14,10 +14,8 @@ typedef struct { size_t maxheight; } tty_t; -void tty_reset(tty_t *tty); void tty_close(tty_t *tty); void tty_init(tty_t *tty, const char *tty_filename); -void tty_getwinsz(tty_t *tty); char tty_getchar(tty_t *tty); int tty_input_ready(tty_t *tty, long int timeout, int return_on_signal);