nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

fileio.h (3360B)


      1 #ifndef FILES_H
      2 #define FILES_H
      3 
      4 #include <stdlib.h>
      5 
      6 /*
      7  * Returns an allocated copy of the path truncated to len if len is
      8  * shorter. Free returned string subsequently. Also truncates to less
      9  * than len if path contains null characters.
     10  */
     11 char *__flatcc_fb_copy_path_n(const char *path, size_t len);
     12 #define fb_copy_path_n __flatcc_fb_copy_path_n
     13 
     14 /* Returns an allocated copy of path. Free returned string subsequently. */
     15 char *__flatcc_fb_copy_path(const char *path);
     16 #define fb_copy_path __flatcc_fb_copy_path
     17 
     18 /*
     19  * Joins two paths. The prefix can optionally be null.
     20  * Free returned string subsequently. If `path_sep` is true, prefix is
     21  * separated from suffix with a path separator if not already present.
     22  */
     23 char *__flatcc_fb_create_join_path_n(const char *prefix, size_t prefix_len,
     24         const char *suffix, size_t suffix_len, const char *ext, int path_sep);
     25 #define fb_create_join_path_n __flatcc_fb_create_join_path_n
     26 
     27 char *__flatcc_fb_create_join_path(const char *prefix, const char * suffix, const char *ext, int path_sep);
     28 #define fb_create_join_path __flatcc_fb_create_join_path
     29 
     30 /* Adds extension to path in a new copy. */
     31 char *__flatcc_fb_create_path_ext_n(const char *path, size_t path_len, const char *ext);
     32 #define fb_create_path_ext_n __flatcc_fb_create_path_ext_n
     33 
     34 char *__flatcc_fb_create_path_ext(const char *path, const char *ext);
     35 #define fb_create_path_ext __flatcc_fb_create_path_ext
     36 
     37 /*
     38  * Creates a path with spaces escaped in a sort of gcc/Gnu Make
     39  * compatible way, primarily for use with dependency files.
     40  *
     41  * http://clang.llvm.org/doxygen/DependencyFile_8cpp_source.html
     42  *
     43  * We should escape a backslash only if followed by space.
     44  * We should escape a space in all cases.
     45  * We ought to handle to #, but don't because gcc fails to do so.
     46  *
     47  * This is dictated by how clang and gcc generates makefile
     48  * dependency rules for gnu make.
     49  *
     50  * This is not intended for strings used for system calls, but rather
     51  * for writing to files where a quoted format is not supported.
     52  *
     53  */
     54 char *__flatcc_fb_create_make_path_n(const char *path, size_t path_len);
     55 #define fb_create_make_path_n __flatcc_fb_create_make_path_n
     56 
     57 char *__flatcc_fb_create_make_path(const char *path);
     58 #define fb_create_make_path __flatcc_fb_create_make_path
     59 
     60 /*
     61  * Creates a new filename stripped from path prefix and optional ext
     62  * suffix. Free returned string subsequently.
     63  */
     64 char *__flatcc_fb_create_basename(const char *path, size_t len, const char *ext);
     65 #define fb_create_basename __flatcc_fb_create_basename
     66 
     67 /* Free returned buffer subsequently. Stores file size in `size_out` arg.
     68  * if `max_size` is 0 the file as read regardless of size, otherwise
     69  * if the file size exceeds `max_size` then `size_out` is set to the
     70  * actual size and null is returend. */
     71 char *__flatcc_fb_read_file(const char *filename, size_t max_size, size_t *size_out);
     72 #define fb_read_file __flatcc_fb_read_file
     73 
     74 
     75 /*
     76  * Returns offset into source path representing the longest suffix
     77  * string with no path separator.
     78  */
     79 size_t __flatcc_fb_find_basename(const char *path, size_t len);
     80 #define fb_find_basename __flatcc_fb_find_basename
     81 
     82 /* Returns input length or length reduced by ext len if ext is a proper suffix. */
     83 size_t __flatcc_fb_chomp(const char *path, size_t len, const char *ext);
     84 #define fb_chomp __flatcc_fb_chomp
     85 
     86 #endif /* FILES_H */