1 #ifndef FILESYS_H 2 #define FILESYS_H 3 4 #include <stdbool.h> 5 #include <stdint.h> 6 #include <stdio.h> 7 8 #define UTOX_FILE_NAME_LENGTH 1024 9 10 /** 11 * Options to define behavior when opening files. 12 */ 13 typedef enum UTOX_FILE_OPTS { 14 UTOX_FILE_OPTS_READ = 1 << 0, 15 UTOX_FILE_OPTS_WRITE = 1 << 1, 16 UTOX_FILE_OPTS_APPEND = 1 << 2, 17 UTOX_FILE_OPTS_MKDIR = 1 << 3, 18 UTOX_FILE_OPTS_DELETE = 1 << 7, 19 } UTOX_FILE_OPTS; 20 21 /** 22 * OS independent way of opening a file from the utox storage folder. 23 * 24 * This function takes care of the environment, checking for portable mode. 25 * 26 * @param name file name, relative to utox storage folder. 27 * @param size size of the file. This variable is written to by the function. Can be NULL if you don't care about the size. 28 * @param opts options to apply when opening the file, see UTOX_FILE_OPTS for available options. 29 * @return open file pointer, or NULL on failure. 30 */ 31 FILE *utox_get_file(const char *name, size_t *size, UTOX_FILE_OPTS opts); 32 33 /** 34 * @brief OS independent way of opening a file from filesystem. 35 * 36 * @param name full path of file to open. 37 * @param opts Options to apply when opening the file, see UTOX_FILE_OPTS for available options. 38 * 39 * @return open file pointer, or NULL on failure. 40 */ 41 FILE *utox_get_file_simple(const char *name, UTOX_FILE_OPTS opts); 42 43 /** 44 * TODO DOCUMENTATION 45 */ 46 bool utox_remove_file(const uint8_t *full_name, size_t length); 47 48 bool utox_move_file(const uint8_t *current_name, const uint8_t *new_name); 49 50 /** 51 * Takes a null-terminated utf8 filepath and creates it with permissions 0700 52 * (in posix environments) if it doesn't already exist. In Windows environments 53 * there are no security settings applied to the created folder. 54 * 55 * Returns a bool indicating if the path exists or not. 56 */ 57 bool native_create_dir(const uint8_t *filepath); 58 59 /** 60 * @brief Get full path of the file in the Tox profile folder. 61 * 62 * @param name name of the file. 63 * @return null-terminated string, or NULL on failure. 64 */ 65 char *utox_get_filepath(const char *name); 66 67 #endif 68