Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_files.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
27
28#ifndef __N_FILES_HEADER
29#define __N_FILES_HEADER
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
39
40#include "nilorea/n_str.h"
41#include "nilorea/n_list.h"
42#include "nilorea/n_log.h"
43#include "dirent.h"
44
46typedef struct N_FILE_INFO {
48 char* name;
52
54int n_scan_dir(const char* dir, LIST* result, const int recurse);
56void n_free_file_info(void* ptr);
57
59int n_file_read_bounded(const char* path, size_t max_size, unsigned char** out, size_t* out_len);
60
62int n_file_write_atomic(const char* path, const unsigned char* data, size_t len, int mode);
63
77int n_file_copy_verified(const char* from, const char* to, size_t* copied);
78
83int n_file_same_content(const char* a, const char* b);
84
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif
static int mode
Structure of a generic LIST container.
Definition n_list.h:59
time_t filetime
file creation time
Definition n_files.h:50
time_t filetime_nsec
Definition n_files.h:50
char * name
file name
Definition n_files.h:48
int n_file_same_content(const char *a, const char *b)
Do two files hold the same bytes.
Definition n_files.c:366
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 t...
Definition n_files.c:466
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.
Definition n_files.c:381
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_si...
Definition n_files.c:270
int n_scan_dir(const char *dir, LIST *result, const int recurse)
scan a directory and store file information in the result list
Definition n_files.c:196
void n_free_file_info(void *ptr)
free a N_FILE_INFO structure
Definition n_files.c:76
common file information
Definition n_files.h:46
List structures and definitions.
Generic log system.
N_STR and string function declaration.