Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
FILES: files utilies

Data Structures

struct  N_FILE_INFO
 common file information More...
 

Functions

void n_free_file_info (void *ptr)
 free a N_FILE_INFO structure
 
int n_scan_dir (const char *dir, LIST *result, const int recurse)
 scan a directory and store file information in the result list
 

Detailed Description


Data Structure Documentation

◆ N_FILE_INFO

struct N_FILE_INFO

common file information

Examples
ex_file.c.

Definition at line 45 of file n_files.h.

+ Collaboration diagram for N_FILE_INFO:
Data Fields
time_t filetime file creation time
time_t filetime_nsec
char * name file name

Function Documentation

◆ n_free_file_info()

void n_free_file_info ( void *  ptr)

free a N_FILE_INFO structure

free a N_FILE_INFO structure

This implementation uses ONLY POSIX-style APIs:

  • opendir / readdir / closedir
  • stat

MinGW provides these APIs on Windows, so no WinAPI (FindFirstFile...) is required.

Sorting:

  • Files are inserted sorted by modification time (mtime), oldest first.
  • Comparator uses seconds then nanoseconds (if available).

Notes:

  • This version stores FULL PATH in N_FILE_INFO->name so recursion is unambiguous. If you prefer basename only, replace strdup(fullpath) with strdup(entry->d_name).

helper to free N_FILE_INFO structs

Parameters
ptra pointer to a N_FILE_INFO structure

Definition at line 60 of file n_files.c.

References __n_assert, and N_FILE_INFO::name.

Referenced by n_scan_dir().

+ Here is the caller graph for this function:

◆ n_scan_dir()

int n_scan_dir ( const char *  dir,
LIST result,
const int  recurse 
)

scan a directory and store file information in the result list

scan a directory and store file information in the result list

This function:

  • Opens dir with opendir()
  • Iterates entries via readdir()
  • Builds full path for each entry (no chdir())
  • Uses stat() to detect file type and modification time
  • If recursion enabled and entry is a directory, scans it recursively
  • If entry is a regular file, pushes an allocated N_FILE_INFO into result, keeping result sorted by n_comp_file_info (oldest -> newest).

Error handling:

  • If opendir() fails: returns FALSE.
  • If stat() fails for an entry: logs and continues.
  • If readdir() fails: logs and returns FALSE.
Parameters
dirDirectory to scan (non-NULL)
resultLIST to fill (non-NULL)
recurseTRUE/FALSE recursion flag
Returns
TRUE on success, FALSE on fatal error.

Definition at line 180 of file n_files.c.

References __n_assert, list_push_sorted(), LOG_ERR, Malloc, n_comp_file_info(), n_free_file_info(), n_log, n_path_join(), n_scan_dir(), n_set_time_from_stat(), and N_FILE_INFO::name.

Referenced by main(), and n_scan_dir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: