C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
lf.h
Go to the documentation of this file.
1/** @file lf.h
2 * @brief Headder for lf
3 * @author Bill Waller
4 * Copyright (c) 2026
5 * MIT License
6 * billxwaller@gmail.com
7 * @date 2026-02-09
8 */
9#pragma once
10#ifdef __cplusplus
11extern "C" {
12#endif
13#define LF_VERSION_MAJOR 0
14#define LF_VERSION_MINOR 3
15#define LF_VERSION_PATCH 3
16#define LF_VERSION "v0.3.3"
17#include <argp.h>
18#include <pthread.h>
19#include <regex.h>
20#include <stdatomic.h>
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdint.h>
24#include <stdlib.h>
25#include <sys/types.h>
26#include <time.h>
27#include <unistd.h>
28#include <wait.h>
29// #define DEBUGT 1
30// #define DEBUGF 1
31// #define DEBUGX 1
32// #define DEBUGY 1
33// #define DEBUGZ 1
34#if __STDC_VERSION__ < 202311L
35#define nullptr NULL
36#endif
37#define MAX_ARGS 64 /**< maximum number of arguments for external commands */
38#define MAXLEN 256 /**< maximum length for various strings and buffers */
39// #define MAX_PATH_LEN _POSIX_PATH_MAX
40#define MAX_THREADS 64
41#define MAX_DEPTH 64
42#define CACHE_LINE_SIZE 64
43#define STAGE_NODES 8
44#define STAGE_PATH_BYTES (STAGE_NODES * 1024)
45#define MAX_PATH_LEN PATH_MAX
46#define MAX_LOG_RECORD_LEN MAX_PATH_LEN
47#define DIR_BUF_SIZE 65536
48#define QUEUE_NODES (1024 * 1024)
49#define PATH_BYTES (32 * 1024 * 1024)
50#define MAX_LOG_REC_LEN 1024
51#define MAX_LOG_SIZE (1024 * 1024)
52#define OUTPUT_BUFFER_BYTES (16 * MAX_PATH_LEN)
53#define QUEUE_MASK (QUEUE_NODES - 1)
54// #define DEBUG_CHILD_STAGING
55#if defined(__has_c_attribute)
56#if __has_c_attribute(gnu::format)
57#define ATTR_FORMAT(archetype, fmt_idx, first_arg)
58 [[gnu::format(archetype, fmt_idx, first_arg)]]
59#endif
60#endif
61// Fallback for older compilers (C11, C99, etc.) using legacy GCC syntax
62#ifndef ATTR_FORMAT
63#if defined(__GNUC__) || defined(__clang__)
64#define ATTR_FORMAT(archetype, fmt_idx, first_arg)
65 __attribute__((format(archetype, fmt_idx, first_arg)))
66#else
67#define ATTR_FORMAT(archetype, fmt_idx,
68 first_arg) /* Unsupported compiler, strip attribute */
69#endif
70#endif
71// Don't set __USE_GNU_GETTEXT as the translations are not yet complete
72#ifdef __USE_GNU_GETTEXT
73#include <libintl.h>
74#define _(String) gettext(String)
75#define gettext_noop(String) String
76#define N_(String) gettext_noop(String)
77#else
78#define _(String) (String)
79#define N_(String) String
80#define textdomain(Domain)
81#define bindtextdomain(Package, Directory)
82#endif
83// ---------------------------------------------------------------
84// Logging
85// ---------------------------------------------------------------
86#define ANSI_RESET "\033[0m"
87#define AS_STRINGS(NAME) #NAME,
88#define AS_ENUM(NAME) NAME,
89#define LOG_LEVEL_LIST(X)
90 X(NONE)
91 X(CONFIG)
92 X(INFO)
93 X(ERROR)
94 X(DEBUG)
95 X(CYCLE)
96 X(ENQUEUE)
97 X(DEQUEUE)
98 X(ALL)
99 X(COUNT_ERRORS)
100 X(ONLY_ERRORS)
101 X(SPIN_COUNT)
102 X(STAGING)
103typedef enum : uint16_t { LOG_LEVEL_LIST(AS_ENUM) LOG_LEVEL_COUNT } ll_e;
104typedef struct {
105 char key;
106 const char *name;
107 uint16_t bits;
108 char SGR[64];
109} log_level;
110typedef uint16_t LogLevel;
111#define TIMESTAMP_STYLE(X)
112 X(ISO8601_ZULU)
113 X(ISO8601_LOCAL)
114 X(CODER)
115typedef enum {
116 TIMESTAMP_STYLE(AS_ENUM) TIMESTAMP_STYLE_COUNT
117} __attribute((packed)) tss_e;
118#define ANSI_COLOR_LIST(X)
119 X(BLACK)
120 X(RED)
121 X(GREEN)
122 X(YELLOW)
123 X(BLUE)
124 X(CYAN)
125 X(MAGENTA)
126 X(WHITE)
127 X(BBLACK)
128 X(BRED)
129 X(BGREEN)
130 X(BYELLOW)
131 X(BBLUE)
132 X(BCYAN)
133 X(BMAGENTA)
134 X(BWHITE)
135 X(ORANGE)
136 X(BORANGE)
137 X(RESET)
138typedef enum {
139 ANSI_COLOR_LIST(AS_ENUM) ANSI_COLOR_COUNT
140} __attribute((packed)) sgr_t;
141#define MAX_TIMESTAMP_LEN 64
142typedef struct {
147 size_t thread_id;
150} LogCtx;
151// HELPER MACROS
152#define max(a, b)
153 ({
154 __typeof__(a) _a = (a);
155 __typeof__(a) _b = (b);
156 _a > _b ? _a : _b;
157 })
158#define min(x, y)
159 ({
160 typeof(x) _x = (x);
161 typeof(x) _y = (y);
162 (void)(&_x == &_y);
163 _x < _y ? _x : _y;
164 })
165#define MAX(a, b)
166 ({
167 typeof(a) _a = (a);
168 typeof(y) _b = (b);
169 _a > _b ? _a : _b;
170 })
171#define MIN(x, y)
172 ({
173 typeof(x) _x = (x);
174 typeof(y) _y = (y);
175 (void)(&_x == &_y);
176 _x < _y ? _x : _y;
177 })
178#define ABS(x)
179 ({
180 __typeof__(x) _a = (x);
181 _a < 0 ? -_a : _a;
182 })
183#define S_TOLOWER(c)
184 ({
185 int __c = (c);
186 (__c >= 'A' && __c <= 'Z') ? (__c + ('a' - 'A')) : __c;
187 })
188#define S_TOUPPER(c)
189 ({
190 int __c = (c);
191 (__c >= 'a' && __c <= 'z') ? (__c - ('a' - 'A')) : __c;
192 })
193#define to_uppercase(c)
194 if (c >= 'a' && c <= 'z')
195 c -= ' '
196#define to_lowercase(c)
197 if (c >= 'A' && c <= 'Z')
198 c += ' '
199// ---------------------------------------------------------------
200// DIRECTORY DATA
201// ---------------------------------------------------------------
203 unsigned long long d_ino; /* 64-bit inode number */
204 long long d_off; /* 64-bit offset to next structure */
205 unsigned short d_reclen; /* Size of this dirent */
206 unsigned char d_type; /* File type */
207 char d_name[]; /* Filename (null-terminated) */
208};
209typedef enum {
210 /** byte 0 - bits 0-7 Selection Flags*/
211 LF_HIDE = 0b00000001, /**< 1 Don't list hidden files */
212 LF_ICASE = 0b00000010, /**< 2 Ignore case in search */
213 LF_EXC_REGEX = 0b00000100, /**< 4 Exclude files matching regex */
214 LF_REGEX = 0b00001000, /**< 8 Include files matching regex */
215 LF_EXEC = 0b00010000, /**< 16 Execute command each file */
216 LF_USER = 0b00100000, /**< 32 Select User Name */
217 /** << 16 */
218 /** byte 1 - bits 8-15 */
219 LF_IXUSR = 0b00000001, /**< 1 Select Files with Execute Permission */
220 LF_IWUSR = 0b00000010, /**< 2 Select Files with Write Permission */
221 LF_IRUSR = 0b00000100, /**< 4 Select Files with Read Permission */
222 LF_ISGID = 0b00010000, /**< 16 Select Setgid Files */
223 LF_ISUID = 0b00100000, /**< 32 Select Setuid Files */
224} LFFlags;
225/** byte 2 - bits 16-23 File types*/
226typedef enum {
227 LF_FIFO = 0b00000001, /**< 1 named pipe */
228 LF_CHR = 0b00000010, /**< 2 character device */
229 LF_DIR = 0b00000100, /**< 4 directory */
230 LF_BLK = 0b00001000, /**< 8 block */
231 LF_REG = 0b00010000, /**< 16 regular file */
232 LF_LNK = 0b00100000, /**< 32 link */
233 LF_SOCK = 0b01000000, /**< 64 socket */
234 LF_UNKNOWN = 0b10000000 /**< 128 unknown */
235} LFTypes;
236typedef enum {
237 F_F0, // 0
238 F_FIFO, // 1
239 F_CHR, // 2
240 F_F1, // 3
241 F_DIR, // 4
242 F_F2, // 5
243 F_BLK, // 6
244 F_F3, // 7
245 F_REG, // 8
246 F_F4, // 9
247 F_LNK, // 10
248 F_F5, // 11
249 F_SOCK, // 12
250 F_F6, // 13
252} F_Type;
253/*
254 dirent d_type to lf_type reference
255 ------------------------ --------------------
256 d_type binary dec lf_type binary dec ordinal
257 --------- -------- --- ----------- -------- --- -------
258 DT_FIFO: 00000001 1 LF_FIFO: 00000001 1 1
259 DT_CHR: 00000010 2 LF_CHR: 00000010 2 2
260 DT_DIR: 00000100 4 LF_DIR: 00000100 4 3
261 DT_BLK: 00000110 6 LF_BLK: 00001000 8 4
262 DT_REG: 00001000 8 LF_REG: 00010000 16 5
263 DT_LNK: 00001010 10 LF_LNK: 00100000 32 6
264 DT_SOCK: 00001100 12 LF_SOCK: 01000000 64 7
265 DT_UNKNOWN: 00001110 14 LF_UNKNOWN: 10000000 128 8
266*/
267#define F_NO_STDERR 1
268/*
269 Include Exclude
270 ---------- ----------
271 LF_FIFO 1 0 00000001 7 11111110 named pipe
272 LF_CHR 2 1 00000010 6 11111101 character device
273 LF_DIR 4 2 00000100 5 11111011 directory
274 LF_BLK 8 3 00001000 4 11110111 block device
275 LF_REG 16 4 00010000 3 11101111 regular file
276 LF_LNK 32 5 00100000 2 11011111 link
277 LF_SOCK 64 6 01000000 1 10111111 socket
278 LF_UNKNOWN 128 7 10000000 0 01111111 unknown
279*/
280#define DEFAULTSHELL "/bin/bash"
281#define S_WCOK 0x1000 /**< write or create permitted */
282#define S_QUIET 0x2000 /**< quiet mode flag for file validation */
283/** @brief This macro registers the end_pgm function to be called when the
284 program exits.
285 @details It checks the return value of atexit() to ensure that the
286 registration was successful, and if not, it prints an error message and
287 exits with a failure status. Programs using libcm should call __atexit in
288 their main function to ensure that the end_pgm function is registered to be
289 called on program exit. This will help ensure that the terminal is properly
290 restored to its original state, even if the program encounters an error or
291 is terminated unexpectedly. */
292#define __atexit
293 {
294 int rc;
295 rc = atexit(end_pgm);
296 if (rc != 0) {
297 fprintf(stderr, "\nCannot set exit function\n");
298 exit(EXIT_FAILURE);
299 }
300 }
301#define to_uppercase(c)
302 if (c >= 'a' && c <= 'z')
303 c -= ' '
304// ---------------------------------------------------------------
305// QUEUE STRUCTURES
306// ---------------------------------------------------------------
307#define NO_PARENT UINT32_MAX
308typedef struct {
309 uint_fast32_t parent_idx; // 4
310 uint_fast32_t path_offset; // 4
311 uint_fast32_t path_len; // 4
312 uint_fast32_t child_dirs_remaining; // 4
313 uint_fast32_t depth; // 4
314 dev_t dev; // 8
315 ino_t ino; // 8
316} QueueNode; // 36 bytes total
317// ---------------------------------------------------------------
318// OUTPUT BUFFER
319// ---------------------------------------------------------------
320typedef struct {
322 size_t len;
323} OutputBuffer;
324// ---------------------------------------------------------------
325// THREAD LOCAL
326// ---------------------------------------------------------------
327typedef struct {
329 QueueNode *stage_node;
334 OutputBuffer *output_buffer;
335 uint_fast32_t parent_idx; // 4
336 uint_fast32_t path_offset; // 4
337 uint_fast32_t path_len; // 4
338 uint_fast32_t child_dirs_remaining; // 4
339 uint_fast32_t depth; // 4
340 dev_t dev; // 8
341 ino_t ino; // 8
342 uint_fast32_t cum_path_offset;
343 uint_fast32_t queue_idx;
344 uint_fast32_t stage_idx;
345 uint_fast32_t thread_id;
346 uint_fast32_t parent_path_len;
347 uint_fast32_t d_name_len;
348 char *d_name;
350 struct stat *cached_sb;
352 unsigned char effective_type;
353 char *dir_buf;
354 LogCtx log_ctx;
355} ThreadLocal;
356// ---------------------------------------------------------------
357// MEMORY USAGE STATISTICS
358// ---------------------------------------------------------------
359typedef struct {
360 uintptr_t stack_max;
361 uintptr_t stack_base;
362 uintptr_t current_sp;
366} MemMetrics;
367// ---------------------------------------------------------------
368// MISCELANEOUS
369// ---------------------------------------------------------------
370typedef enum {
375} TerminationStatus;
376// ---------------------------------------------------------------
377// GLOBAL LF CONTEXT
378// ---------------------------------------------------------------
379typedef struct {
380 void *arena;
381 alignas(CACHE_LINE_SIZE) QueueNode *queue;
383 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t path_offset;
384 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t shut_down;
385 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t enqueue_pos;
386 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t dequeue_pos;
387 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t active_tasks;
388 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t queue_idx;
389 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t thread_id;
390 alignas(CACHE_LINE_SIZE) atomic_uint_fast32_t sequence[QUEUE_NODES];
394 pthread_mutex_t output_mutex;
395 atomic_size_t error_count;
396 atomic_size_t log_error_count;
397 pthread_t *threads;
398 long start;
399 unsigned int nthreads;
400 atomic_size_t file_count;
401 uintmax_t user_id;
406 long flags;
411 time_t after;
412 time_t before;
413 uint32_t max_depth;
416 char *re;
417 char *ere;
419 char *sbuffer;
420 regex_t compiled_re;
422 unsigned char include_perms;
423 unsigned char include_types;
424 unsigned char suppress_types;
426 bool unlink;
427 bool xdev;
430 bool sort;
441 bool count;
443} GlobalContext;
444// LOG LEVELS
445// 1-CONFIG, 2- INFO, 3-ERROR, 4-DEBUG, 5-CYCLE, 6-QUEUE, 7-ONLY_ERRORS,
446// 8-COUNT_ERRORS, 9-ALL, S-SPIN_COUNT, T-STAGE
447#define print_file_type(mask, lf_type, dt_type, name)
448 {
449 fprintf(stderr, "%c %08b (%3d) %08b (%2d) %s\n",
450 (mask & lf_type) ? '*' : ' ', lf_type, lf_type, dt_type, dt_type,
451 name);
452 }
453
454// ---------------------------------------------------------------
455// FUNCTION PROTOTYPES
456// ---------------------------------------------------------------
457unsigned long a_to_ul(const char *);
458int a_toi(char *, bool *);
459bool is_symlink_to_dir(const char *);
460bool expand_tilde(char *, uint);
461bool is_directory(const char *);
462bool is_valid_regex(const char *);
463char *get_local_timestamp();
464char *get_user_str(char *, size_t);
465char *get_ip_addresses(char *, uint);
466bool is_newer(char *, char *);
467int str_to_args(char **, char *, uint);
468size_t ssnprintf(char *, size_t, const char *, ...);
469size_t strnz__cpy(char *, const char *, size_t);
470size_t strnz__cat(char *, const char *, size_t);
471size_t strnz__pcat(char *d, size_t pos, const char *s, size_t max_len);
472char *strerror__r(int errnum, char *buf, size_t buflen);
474void iso8601_timestamp(GlobalContext *__G, LogCtx *log_ctx);
475void coders_timestamp(LogCtx *log_ctx);
476void initialize_timer(GlobalContext *__G, LogCtx *log_ctx);
477void initialize_thread_timer(GlobalContext *__G, LogCtx *log_ctx);
478void debug_out(GlobalContext *__G, int, char **);
479bool init_lf(GlobalContext *__G, int, char **);
480int sort_lf_output(GlobalContext *__G, int, char **);
481void *worker(void *arg);
482void *finder(GlobalContext *__G, ThreadLocal *tl);
483int print_file(GlobalContext *__G, ThreadLocal *tl);
484void flush_output_buffer(GlobalContext *, OutputBuffer *);
485bool append_output_buffer(GlobalContext *__G, OutputBuffer *output, const char *path, size_t path_len, bool append_slash);
486void finalize_dir_node(GlobalContext *__G, size_t node_offset);
487bool global_arena_create(GlobalContext *__G);
488void global_arena_destroy(GlobalContext *__G);
489void push_root_node(GlobalContext *__G, dev_t dev, ino_t ino);
490bool mpmc_enqueue(GlobalContext *__G, QueueNode *node, const char *path, size_t len);
491bool mpmc_enqueue_staged(GlobalContext *, ThreadLocal *__tl);
492bool mpmc_bulk_enqueue(GlobalContext *__G, ThreadLocal *__tl);
493bool mpmc_dequeue(GlobalContext *__G, uint_fast32_t *dequeue_pos);
494char *path_data_init(GlobalContext *__G, LogCtx *log_ctx);
495void path_data_destroy(GlobalContext *__G);
496size_t flush_ch(GlobalContext *__G, ThreadLocal *tl);
497void iso8601_timestamp(GlobalContext *__G, LogCtx *log_ctx);
498bool parse_local_timestamp(const char *s, time_t *out);
499char *format_local_timestamp(time_t t, char *buf, size_t n);
500bool expand_tilde(char *str, uint path_maxlen);
501char *rep_substring(const char *org_s, const char *tgt_s, const char *rep_s);
502size_t vssnprintf(char *buf, size_t buf_size, const char *format, va_list args);
503size_t ssnprintf(char *buf, size_t buf_size, const char *format, ...);
504bool is_symlink_to_dir(const char *path);
505unsigned long a_to_ul(const char *str);
506int a_toi(char *s, bool *a_toi_error);
507size_t strnz__cpy(char *d, const char *s, size_t max_len);
508size_t strnz__cat(char *d, const char *s, size_t max_len);
509bool is_directory(const char *path);
510bool is_valid_regex(const char *pattern);
511void build_path(ThreadLocal *__tl, char *file_name);
512// ---------------------------------------------------------------
513// LOGGING
514// ---------------------------------------------------------------
515void log_open(GlobalContext *__G, LogCtx *log_ctx, size_t thread_id);
516ATTR_FORMAT(printf, 7, 8)
517void log_write(const ll_e level, GlobalContext *__G, LogCtx *log_ctx, const char *file,
518 const char *func, const int line, const char *fmt, ...);
519#define lf_log(level, fmt, ...)
520 {
521 log_write(level, __G, log_ctx, __FILE__, __func__, __LINE__,
522 fmt, ##__VA_ARGS__);
523 }
524
525#ifdef __cplusplus
526}
527#endif
@ F_REG
Definition cm.h:221
@ F_BLK
Definition cm.h:219
@ F_FIFO
Definition cm.h:214
@ F_F0
Definition cm.h:213
@ F_F3
Definition cm.h:220
@ F_SOCK
Definition cm.h:225
@ F_CHR
Definition cm.h:215
@ F_F5
Definition cm.h:224
@ F_F1
Definition cm.h:216
@ F_DIR
Definition cm.h:217
@ F_UNKNOWN
Definition cm.h:227
@ F_F2
Definition cm.h:218
@ F_F4
Definition cm.h:222
@ F_LNK
Definition cm.h:223
@ F_F6
Definition cm.h:226
int stdout_fd
Definition ui_common.c:78
@ LF_EXC_REGEX
Definition cm.h:187
@ LF_HIDE
Definition cm.h:185
@ LF_ISUID
Definition cm.h:197
@ LF_IRUSR
Definition cm.h:195
@ LF_ICASE
Definition cm.h:186
@ LF_ISGID
Definition cm.h:196
@ LF_EXEC
Definition cm.h:189
@ LF_REGEX
Definition cm.h:188
@ LF_USER
Definition cm.h:190
@ LF_IXUSR
Definition cm.h:193
@ LF_IWUSR
Definition cm.h:194
@ LF_FIFO
Definition cm.h:202
@ LF_DIR
Definition cm.h:204
@ LF_UNKNOWN
Definition cm.h:209
@ LF_SOCK
Definition cm.h:208
@ LF_BLK
Definition cm.h:205
@ LF_LNK
Definition cm.h:207
@ LF_REG
Definition cm.h:206
@ LF_CHR
Definition cm.h:203
int stdin_fd
Definition ui_common.c:78
size_t strnz__pcat(char *d, size_t pos, const char *s, size_t max_len)
Definition futil.c:577
int stderr_fd
Definition lf.c:62
char * rep_substring(const char *, const char *, const char *) __attribute__((nonnull(1
Replace all occurrences of "tgt_s" in "org_s" with "rep_s".
Definition futil.c:1471
@ TS_SUCCESS
Definition lf.h:371
@ TS_MATCH_PLUS_ERROR
Definition lf.h:374
@ TS_MATCH
Definition lf.h:373
@ TS_ERROR
Definition lf.h:372
#define MAX_LOG_REC_LEN
Definition lf.h:50
#define MAX_TIMESTAMP_LEN
Definition lf.h:141
#define DIR_BUF_SIZE
Definition lf.h:47
#define ATTR_FORMAT(archetype, fmt_idx, first_arg)
Definition lf.h:67
#define MAX_ARGS
Definition lf.h:37
char * path_data_init(GlobalContext *__G, LogCtx *log_ctx)
#define STAGE_PATH_BYTES
Definition lf.h:44
#define QUEUE_NODES
Definition lf.h:48
bool mpmc_enqueue_staged(GlobalContext *, ThreadLocal *__tl)
#define lf_log(level, fmt,...)
Definition lf.h:519
#define QUEUE_MASK
Definition lf.h:53
#define PATH_BYTES
Definition lf.h:49
#define OUTPUT_BUFFER_BYTES
Definition lf.h:52
uint16_t LogLevel
Definition lf.h:110
#define TIMESTAMP_STYLE(X)
Definition lf.h:111
void path_data_destroy(GlobalContext *__G)
#define NO_PARENT
Definition lf.h:307
size_t flush_ch(GlobalContext *__G, ThreadLocal *tl)
#define print_file_type(mask, lf_type, dt_type, name)
Definition lf.h:447
#define STAGE_NODES
Definition lf.h:43
void get_proc_memory()
#define LOG_LEVEL_LIST(X)
Definition lf.h:89
#define MAX_LOG_SIZE
Definition lf.h:51
#define MAX_PATH_LEN
Definition lf.h:45
void finalize_dir_node(GlobalContext *__G, size_t node_offset)
#define LF_VERSION
Definition lf.h:16
#define MAX_LOG_RECORD_LEN
Definition lf.h:46
#define MAXLEN
Definition lf.h:38
#define ANSI_RESET
Definition lf.h:86
#define CACHE_LINE_SIZE
Definition lf.h:42
#define ANSI_COLOR_LIST(X)
Definition lf.h:118
char * exec
Definition lf.c:104
const char * sgr_c[]
Definition lf.c:81
void * worker(void *arg)
Worker thread function for processing directory nodes.
Definition lf.c:1227
void coders_timestamp(LogCtx *log_ctx)
Generate a timestamp string for logging, including both current time and interval since last log entr...
Definition lf.c:1847
char * lfargs[3]
Definition lf.c:103
int pipe_in
Definition lf.c:62
log_level ll_t[]
Definition lf.c:63
TerminationStatus termination_status
Definition lf.c:60
char em1[MAXLEN]
Definition lf.c:43
bool global_arena_create(GlobalContext *__G)
Create a queue arena for managing directory traversal tasks.
Definition lf.c:878
char * perms_p
Definition lf.c:106
void initialize_timer(GlobalContext *__G, LogCtx *log_ctx)
Initialize the timer for logging, capturing the start time and setting up interval tracking.
Definition lf.c:1821
const char * sgr_s[]
Definition lf.c:80
const char * tss_s[]
Definition lf.c:79
int tty_fd
Definition lf.c:62
char * debug_p
Definition lf.c:107
char em2[MAXLEN]
Definition lf.c:44
#define WRITE_STR(p, str)
Definition lf.c:1712
unsigned char const lf_type_mask[15]
Definition lf.c:110
void debug_out(GlobalContext *__G, int argc, char **argv)
Display everything and the kitchen sink on stderr.
Definition lf.c:582
bool append_output_buffer(GlobalContext *__G, OutputBuffer *output_buffer, const char *path, size_t path_len, bool append_slash)
Append a path to the output_buffer, flushing if necessary.
Definition lf.c:971
void initialize_thread_timer(GlobalContext *__G, LogCtx *log_ctx)
Initialize the timer for a thread, capturing the start time and setting up interval tracking.
Definition lf.c:1799
void * finder(GlobalContext *__G, ThreadLocal *__tl)
Traverse a directory and process its entries.
Definition lf.c:1335
char * file_types_p
Definition lf.c:105
void build_path(ThreadLocal *__tl, char *file_name)
Build the full path for a file or directory entry.
Definition lf.c:1583
void iso8601_timestamp(GlobalContext *__G, LogCtx *log_ctx)
Generate an ISO 8601 timestamp string.
Definition lf.c:1695
const char * log_s[]
Definition lf.c:61
bool mpmc_enqueue(GlobalContext *__G, QueueNode *node, const char *path, size_t len)
Definition lf.c:997
MemMetrics mm
Definition lf.c:41
int sort_lf_output(GlobalContext *__G, int argc, char **argv)
Sort the output of the lf command using the system's sort utility.
Definition lf.c:529
bool mpmc_dequeue(GlobalContext *__G, uint_fast32_t *dequeue_pos)
Dequeue a node from the MPMC queue.
Definition lf.c:1144
void log_write(const ll_e level, GlobalContext *__G, LogCtx *log_ctx, const char *file, const char *func, const int line, const char *fmt,...)
Write a log message to the log file and/or display.
Definition lf.c:1984
char em4[MAXLEN]
Definition lf.c:46
char em3[MAXLEN]
Definition lf.c:45
int lfargc
Definition lf.c:102
void push_root_node(GlobalContext *__G, dev_t dev, ino_t ino)
Push the root directory node into the queue arena.
Definition lf.c:908
bool init_lf(GlobalContext *__G, int argc, char **argv)
Initialize the file search process.
Definition lf.c:731
void global_arena_destroy(GlobalContext *__G)
Destroy the queue arena and free associated resources.
Definition lf.c:929
bool mpmc_bulk_enqueue(GlobalContext *__G, ThreadLocal *__tl)
Bulk enqueue multiple nodes into the MPMC queue.
Definition lf.c:1048
char em0[MAXLEN]
Definition lf.c:42
void flush_output_buffer(GlobalContext *__G, OutputBuffer *output_buffer)
Flush the output_buffer to stdout in a thread-safe manner.
Definition lf.c:947
struct tm tm_info
Definition lf.c:48
void log_open(GlobalContext *__G, LogCtx *log_ctx, size_t thread_id)
Open the log file for writing.
Definition lf.c:1918
const char doc[]
Definition lf.c:53
bool is_dirsys(const char *)
int print_file(GlobalContext *__G, ThreadLocal *__tl)
Print the path of a file or directory entry based on filtering criteria.
Definition lf.c:1602
int pipe_out
Definition lf.c:62
char * log_p
Definition lf.c:108
bool is_hidden(const char *)
const char * argp_program_version
Definition init.c:110
const char * argp_program_bug_address
Definition init.c:111
#define _(String)
Definition amort.c:23
int main(int argc, char **argv)
Capture the current terminal settings for later restoration.
Definition amort.c:41
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition lf.c:2299
bool parse_local_timestamp(const char *, time_t *)
Parses an ISO 8601 timestamp string in local time and converts it to time_t.
Definition futil.c:249
char * get_local_timestamp()
Returns the current local time as an ISO 8601 formatted string.
Definition futil.c:283
bool is_directory(const char *)
Check if a given path is a directory.
Definition lf.c:2358
size_t ssnprintf(char *, size_t, const char *,...)
Custom safe string formatting utility (Variadic version).
Definition futil.c:398
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:418
bool is_valid_regex(const char *)
Check if a given path is a regular file.
Definition lf.c:2374
bool expand_tilde(char *, uint)
Expand a tilde (~) in a file path to the user's home directory.
Definition lf.c:2089
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition lf.c:2330
char * get_ip_addresses(char *, uint)
Retrieves the IP addresses of the local machine and formats them into a string.
Definition futil.c:323
bool is_symlink_to_dir(const char *)
Check if a given path is a symbolic link that points to a directory.
Definition lf.c:2220
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
Definition futil.c:806
char * strerror__r(int errnum, char *buf, size_t buflen)
A thread-safe alternative to strerror() that writes the error message corresponding to errnum into th...
Definition futil.c:770
size_t vssnprintf(char *buf, size_t buf_size, const char *format, va_list args)
Custom safe string formatting utility (va_list version).
Definition futil.c:377
char * format_local_timestamp(time_t, char *, size_t)
Formats a time_t as an ISO 8601 string in local time.
Definition futil.c:272
bool is_newer(char *, char *)
Checks if the file specified by "fut" is newer than the file specified by "control".
Definition futil.c:147
char * get_user_str(char *, size_t)
Retrieves the current user's name and UID, and formats it into a string.
Definition futil.c:296
unsigned long a_to_ul(const char *)
Convert a string to an unsigned long with optional size suffixes.
Definition lf.c:2241
const char * name
Definition lf.h:106
char key
Definition lf.h:105
uint16_t bits
Definition lf.h:107
char SGR[64]
Definition lf.h:108
long p_int_sec
Definition lf.h:146
long p_int_nsec
Definition lf.h:145
char record[MAX_LOG_REC_LEN]
Definition lf.h:149
long start_sec
Definition lf.h:144
size_t thread_id
Definition lf.h:147
char time_buf[MAX_TIMESTAMP_LEN]
Definition lf.h:148
long start_nsec
Definition lf.h:143
unsigned short d_reclen
Definition lf.h:205
unsigned char d_type
Definition lf.h:206
char d_name[]
Definition lf.h:207
long long d_off
Definition lf.h:204
unsigned long long d_ino
Definition lf.h:203
dev_t dev
Definition lf.h:314
uint_fast32_t depth
Definition lf.h:313
ino_t ino
Definition lf.h:315
uint_fast32_t parent_idx
Definition lf.h:309
uint_fast32_t path_len
Definition lf.h:311
uint_fast32_t child_dirs_remaining
Definition lf.h:312
uint_fast32_t path_offset
Definition lf.h:310
size_t len
Definition lf.h:322
char data[OUTPUT_BUFFER_BYTES]
Definition lf.h:321
char * d_name
Definition lf.h:348
size_t stage_queue_size
Definition lf.h:332
char * dir_buf
Definition lf.h:353
uint_fast32_t d_name_len
Definition lf.h:347
size_t stage_arena_size
Definition lf.h:331
uint_fast32_t depth
Definition lf.h:339
uint_fast32_t child_dirs_remaining
Definition lf.h:338
LogCtx log_ctx
Definition lf.h:354
uint_fast32_t thread_id
Definition lf.h:345
uint_fast32_t path_len
Definition lf.h:337
char * path_data
Definition lf.h:330
uint_fast32_t stage_idx
Definition lf.h:344
dev_t dev
Definition lf.h:340
uint_fast32_t parent_idx
Definition lf.h:335
size_t stage_path_size
Definition lf.h:333
QueueNode * stage_node
Definition lf.h:329
OutputBuffer * output_buffer
Definition lf.h:334
ino_t ino
Definition lf.h:341
uint_fast32_t queue_idx
Definition lf.h:343
unsigned char effective_type
Definition lf.h:352
void * stage_arena
Definition lf.h:328
uint_fast32_t parent_path_len
Definition lf.h:346
uint_fast32_t cum_path_offset
Definition lf.h:342
char path[MAX_PATH_LEN]
Definition lf.h:349
uint_fast32_t path_offset
Definition lf.h:336
bool stat_cached
Definition lf.h:351
struct stat * cached_sb
Definition lf.h:350
uintptr_t stack_max
Definition lf.h:360
uintptr_t current_sp
Definition lf.h:362
long heap_used
Definition lf.h:364
long stack_used
Definition lf.h:365
void * heap_base
Definition lf.h:363
uintptr_t stack_base
Definition lf.h:361
unsigned char include_types
Definition lf.h:423
time_t after
Definition lf.h:411
unsigned int nthreads
Definition lf.h:399
atomic_size_t log_error_count
Definition lf.h:396
size_t arena_bytes
Definition lf.h:391
bool depth_first
Definition lf.h:428
atomic_uint_fast32_t dequeue_pos
Definition lf.h:386
atomic_size_t file_count
Definition lf.h:400
long p_int_sec
Definition lf.h:410
long p_int_nsec
Definition lf.h:409
int err_fd
Definition lf.h:403
atomic_uint_fast32_t queue_idx
Definition lf.h:388
size_t path_bytes
Definition lf.h:393
char * base_path
Definition lf.h:415
time_t before
Definition lf.h:412
bool count_silently
Definition lf.h:442
atomic_uint_fast32_t shut_down
Definition lf.h:384
long start_nsec
Definition lf.h:407
bool unlink
Definition lf.h:426
atomic_uint_fast32_t active_tasks
Definition lf.h:387
char * sbuffer
Definition lf.h:419
bool count
Definition lf.h:441
pthread_mutex_t output_mutex
Definition lf.h:394
atomic_uint_fast32_t sequence[QUEUE_NODES]
Definition lf.h:390
atomic_uint_fast32_t thread_id
Definition lf.h:389
char log_record[MAX_LOG_RECORD_LEN]
Definition lf.h:425
bool f_logging
Definition lf.h:436
bool include_hidden
Definition lf.h:432
unsigned char suppress_types
Definition lf.h:424
char * ere
Definition lf.h:417
bool follow_links
Definition lf.h:434
char * re
Definition lf.h:416
size_t queue_bytes
Definition lf.h:392
unsigned char include_perms
Definition lf.h:422
ll_e disp_level_mask
Definition lf.h:437
char * path_data
Definition lf.h:382
char * user_name
Definition lf.h:418
long start_sec
Definition lf.h:408
bool sort_reverse
Definition lf.h:431
atomic_uint_fast32_t enqueue_pos
Definition lf.h:385
void * arena
Definition lf.h:380
bool only_errors
Definition lf.h:439
long start
Definition lf.h:398
off_t file_size_min
Definition lf.h:402
uint32_t max_depth
Definition lf.h:413
bool ignore_case
Definition lf.h:429
bool hidden_only
Definition lf.h:433
int log_fd
Definition lf.h:404
atomic_size_t error_count
Definition lf.h:395
regex_t compiled_ere
Definition lf.h:421
int reg_flags
Definition lf.h:414
QueueNode * queue
Definition lf.h:381
char log_file_spec[MAX_PATH_LEN]
Definition lf.h:405
pthread_t * threads
Definition lf.h:397
atomic_uint_fast32_t path_offset
Definition lf.h:383
uintmax_t user_id
Definition lf.h:401
ll_e file_level_mask
Definition lf.h:438
bool xdev
Definition lf.h:427
long flags
Definition lf.h:406
bool sort
Definition lf.h:430
tss_e timestamp_style
Definition lf.h:435
bool count_errors
Definition lf.h:440
regex_t compiled_re
Definition lf.h:420