|
ginnOS
The reference: libc, the libraries and the kernel
|
librat helpers: messages, paths, file data and SHA-256, safe writes, folders. More...
#include "internal.h"#include <dirent.h>#include <errno.h>#include <fcntl.h>#include <stdarg.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <unistd.h>#include "sha2.h"Functions | |
| int | rat_fail (rat_error_t *err, const char *format,...) |
| void | rat_say (rat_note_t note, void *context, const char *format,...) |
| char * | rat_strdup (const char *s) |
| a copy of a string, or NULL when there is no memory | |
| char * | rat_path (const rat_t *rat, const char *rel) |
| a path on the root: <root>/<rel>. | |
| const char * | rat_check_path (const char *path, char out[RAT_PATH_MAX+1]) |
| check a path of a package and make it the normal form: a "./" at the start and a '/' at the end are removed. | |
| const char * | rat_check_link (const char *path, const char *target) |
| check the target of a symbolic link at path: relative, and inside the package root when it is resolved from the folder of the link. | |
| void | rat_hex (const uint8_t sha[32], char out[65]) |
| the SHA-256 as 64 hexadecimal digits and a '\0' | |
| int | rat_unhex (const char *text, uint8_t sha[32]) |
| read 64 hexadecimal digits. | |
| int | rat_sha256_file (const char *path, uint8_t sha[32], uint64_t *size_out) |
| the SHA-256 and size of a file. | |
| char * | rat_read_file (const char *path, size_t max, size_t *size_out) |
| read a whole file into memory, with a '\0' after it. | |
| int | rat_write_file (const char *path, const void *data, size_t size, uint32_t mode) |
| write a file so that a crash leaves the old file or the new one: to <path>.new, fsync, then rename. | |
| int | rat_mkdirs (const char *path, uint32_t mode) |
| make a folder and the folders above it that are not there. | |
| int | rat_remove_tree (const char *path) |
| remove a file, a link, or a folder with everything in it. | |
| void | rat_entry_clear (rat_entry_t *entry) |
| release the members of an entry | |
| void | rat_entries_free (rat_entry_t *entries, int count) |
| release an array from rat_files. | |
| int | rat_compare_entries (const void *a, const void *b) |
| compare two entries by path, for qsort and bsearch | |
| void | rat_sort_entries (rat_entry_t *entries, int count) |
| sort entries by path | |
| bool | rat_is_settings (const rat_entry_t *entry) |
| true if a path of a package is a settings file: a file under etc/. | |
librat helpers: messages, paths, file data and SHA-256, safe writes, folders.
| int rat_fail | ( | rat_error_t * | err, |
| const char * | format, | ||
| ... ) |
| void rat_say | ( | rat_note_t | note, |
| void * | context, | ||
| const char * | format, | ||
| ... ) |
| char * rat_strdup | ( | const char * | s | ) |
a copy of a string, or NULL when there is no memory
| char * rat_path | ( | const rat_t * | rat, |
| const char * | rel ) |
a path on the root: <root>/<rel>.
| const char * rat_check_path | ( | const char * | path, |
| char | out[RAT_PATH_MAX+1] ) |
check a path of a package and make it the normal form: a "./" at the start and a '/' at the end are removed.
| out | gets the normal form (RAT_PATH_MAX + 1 bytes). |
| const char * rat_check_link | ( | const char * | path, |
| const char * | target ) |
check the target of a symbolic link at path: relative, and inside the package root when it is resolved from the folder of the link.
| void rat_hex | ( | const uint8_t | sha[32], |
| char | out[65] ) |
the SHA-256 as 64 hexadecimal digits and a '\0'
| int rat_unhex | ( | const char * | text, |
| uint8_t | sha[32] ) |
read 64 hexadecimal digits.
the SHA-256 and size of a file.
read a whole file into memory, with a '\0' after it.
| max | the largest size that is read. |
write a file so that a crash leaves the old file or the new one: to <path>.new, fsync, then rename.
| int rat_mkdirs | ( | const char * | path, |
| uint32_t | mode ) |
make a folder and the folders above it that are not there.
| int rat_remove_tree | ( | const char * | path | ) |
remove a file, a link, or a folder with everything in it.
it never follows a symbolic link. a path that is not there is not an error.
| void rat_entry_clear | ( | rat_entry_t * | entry | ) |
release the members of an entry
| void rat_entries_free | ( | rat_entry_t * | entries, |
| int | count ) |
release an array from rat_files.
| int rat_compare_entries | ( | const void * | a, |
| const void * | b ) |
compare two entries by path, for qsort and bsearch
| void rat_sort_entries | ( | rat_entry_t * | entries, |
| int | count ) |
sort entries by path
| bool rat_is_settings | ( | const rat_entry_t * | entry | ) |
true if a path of a package is a settings file: a file under etc/.
a settings file that the person changed stays at an upgrade or a remove.