Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_files.c File Reference

Cross-platform directory scanning (Linux/Solaris/Windows), optionnal recursion. More...

#include "nilorea/n_files.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
+ Include dependency graph for n_files.c:

Go to the source code of this file.

Functions

int n_comp_file_info (const void *a, const void *b)
 Comparison function for sorting N_FILE_INFO by time (oldest first).
 
void n_free_file_info (void *ptr)
 Cross-platform directory scanning (Linux / Solaris / Windows via MinGW) WITHOUT chdir().
 
char * n_path_join (const char *dir, const char *name)
 Build "dir + '/' + name" (or without extra slash if dir already ends with '/' or '\').
 
int n_scan_dir (const char *dir, LIST *result, const int recurse)
 Scan a directory and append only regular files into a sorted list (oldest first).
 
void n_set_time_from_stat (N_FILE_INFO *file, const struct stat *st)
 Fill filetime and filetime_nsec from a struct stat (mtime).
 

Detailed Description

Cross-platform directory scanning (Linux/Solaris/Windows), optionnal recursion.

Author
Castagnier Mickael
Version
1.0
Date
02/11/23

Definition in file n_files.c.

Function Documentation

◆ n_comp_file_info()

int n_comp_file_info ( const void *  a,
const void *  b 
)

Comparison function for sorting N_FILE_INFO by time (oldest first).

Orders by: 1) filetime (seconds) ascending 2) filetime_nsec (nanoseconds) ascending

Return values:

  • < 0 if a is older than b
  • = 0 if equal timestamps
  • > 0 if a is newer than b
Parameters
aPointer to first N_FILE_INFO
bPointer to second N_FILE_INFO
Returns
Ordering result.

Definition at line 121 of file n_files.c.

References N_FILE_INFO::filetime, and N_FILE_INFO::filetime_nsec.

Referenced by n_scan_dir().

+ Here is the caller graph for this function:

◆ n_path_join()

char * n_path_join ( const char *  dir,
const char *  name 
)

Build "dir + '/' + name" (or without extra slash if dir already ends with '/' or '\').

Uses '/' as a separator for portability. Windows (MinGW) accepts forward slashes.

Parameters
dirBase directory path (non-NULL)
nameEntry name (non-NULL)
Returns
Newly allocated full path (free() by caller), or NULL on error.

Definition at line 78 of file n_files.c.

Referenced by n_scan_dir().

+ Here is the caller graph for this function:

◆ n_set_time_from_stat()

void n_set_time_from_stat ( N_FILE_INFO file,
const struct stat *  st 
)

Fill filetime and filetime_nsec from a struct stat (mtime).

On Linux and Solaris, uses st_mtim (seconds + nanoseconds). On other POSIX environments, falls back to st_mtime (seconds only).

Parameters
fileN_FILE_INFO to fill (non-NULL)
ststruct stat source (non-NULL)

Definition at line 146 of file n_files.c.

References N_FILE_INFO::filetime, and N_FILE_INFO::filetime_nsec.

Referenced by n_scan_dir().

+ Here is the caller graph for this function: