![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Cross-platform directory scanning (Linux/Solaris/Windows), optionnal recursion. More...
#include "nilorea/n_files.h"#include "nilorea/n_common.h"#include <errno.h>#include <stdio.h>#include <string.h>#include <fcntl.h>#include <sys/stat.h>#include <unistd.h>#include <stdlib.h>#include <stdint.h>#include <dirent.h>Go to the source code of this file.
Macros | |
| #define | N_FILE_COPY_BLOCK 262144 |
| Block size for the streaming copy and compare. | |
Functions | |
| int | n_comp_file_info (const void *a, const void *b) |
| Comparison function for sorting N_FILE_INFO by time (oldest first). | |
| int | n_file_copy_verified (const char *from, const char *to, size_t *copied) |
| Copy a file, check the copy against the original, and only then give it its name. | |
| int | n_file_read_bounded (const char *path, size_t max_size, unsigned char **out, size_t *out_len) |
| read a whole file into a freshly allocated, NUL-terminated buffer, refusing a file larger than max_size bytes. | |
| int | n_file_same_content (const char *a, const char *b) |
| Do two files hold the same bytes. | |
| static int | n_file_streams_equal (FILE *a, FILE *b) |
| Compare two open streams to their ends. | |
| int | n_file_write_atomic (const char *path, const unsigned char *data, size_t len, int mode) |
| durably and atomically write len bytes to path: write a "<path>.tmp" sibling created with mode from the outset (POSIX; 0 or Windows = leave default), flush it to stable storage, then atomically rename it over path (MoveFileEx REPLACE_EXISTING|WRITE_THROUGH on Windows, which replaces an existing target where the CRT rename() would fail). | |
| 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). | |
Cross-platform directory scanning (Linux/Solaris/Windows), optionnal recursion.
Definition in file n_files.c.
| #define N_FILE_COPY_BLOCK 262144 |
Block size for the streaming copy and compare.
Definition at line 327 of file n_files.c.
Referenced by n_file_copy_verified(), and n_file_streams_equal().
| 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:
| a | Pointer to first N_FILE_INFO |
| b | Pointer to second N_FILE_INFO |
Definition at line 137 of file n_files.c.
References N_FILE_INFO::filetime, and N_FILE_INFO::filetime_nsec.
Referenced by n_scan_dir().
|
static |
Compare two open streams to their ends.
| a | first stream, positioned at its start |
| b | second stream, positioned at its start |
Definition at line 335 of file n_files.c.
References Free, Malloc, and N_FILE_COPY_BLOCK.
Referenced by n_file_same_content().
| 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.
| dir | Base directory path (non-NULL) |
| name | Entry name (non-NULL) |
Definition at line 94 of file n_files.c.
References last.
Referenced by n_scan_dir().
| 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).
| file | N_FILE_INFO to fill (non-NULL) |
| st | struct stat source (non-NULL) |
Definition at line 162 of file n_files.c.
References N_FILE_INFO::filetime, and N_FILE_INFO::filetime_nsec.
Referenced by n_scan_dir().