|
|
|
@ -0,0 +1,672 @@
|
|
|
|
|
/**
|
|
|
|
|
* ***** BEGIN LICENSE BLOCK ***** |
|
|
|
|
* |
|
|
|
|
* Copyright 2017-2021 Yzena Tech |
|
|
|
|
* |
|
|
|
|
* Licensed under the Yzena Network License, Version 0.1 (the "Yzena Network |
|
|
|
|
* License" or "YNL"). You may not use this file except in compliance with the |
|
|
|
|
* Yzena Network License. |
|
|
|
|
* |
|
|
|
|
* You may obtain a copy of the Yzena Network License at |
|
|
|
|
* |
|
|
|
|
* https://yzena.com/yzena-network-license/
|
|
|
|
|
* |
|
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
|
* distributed under the Yzena Network License is distributed under the |
|
|
|
|
* following disclaimer: |
|
|
|
|
* |
|
|
|
|
* As far as the law allows, this software comes as is, without any |
|
|
|
|
* warranty or condition, and no contributor will be liable to anyone for |
|
|
|
|
* any damages related to this software or this license, under any kind of |
|
|
|
|
* legal claim. |
|
|
|
|
* |
|
|
|
|
* ****** END LICENSE BLOCK ****** |
|
|
|
|
* |
|
|
|
|
* ***************************************************************** |
|
|
|
|
* |
|
|
|
|
* ******* BEGIN FILE DESCRIPTION ******* |
|
|
|
|
* |
|
|
|
|
* Main public header file for Yfs. |
|
|
|
|
* |
|
|
|
|
* ******** END FILE DESCRIPTION ******** |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifndef YC_FILE_H |
|
|
|
|
#define YC_FILE_H |
|
|
|
|
|
|
|
|
|
/* For C++ compatibility */ |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#include <yc/yc.h> |
|
|
|
|
|
|
|
|
|
#include <stdbool.h> |
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file yc/fs.h |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def YFS_PATH_SEP |
|
|
|
|
* A define that is the correct path separator for the platform as a char. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def YFS_PATH_SEP_STR |
|
|
|
|
* A define that is the correct path separator for the platform as a string. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def YFS_PATH_EXTRA |
|
|
|
|
* The extra amount of space needed for paths for the platform. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__) |
|
|
|
|
|
|
|
|
|
#define YFS_PATH_MAX (MAX_PATH) |
|
|
|
|
|
|
|
|
|
#ifdef _MSC_VER |
|
|
|
|
|
|
|
|
|
// Extra chars for the "\\*" mask.
|
|
|
|
|
#define YFS_PATH_EXTRA (2) |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#define YFS_PATH_SEP (YPATHSTR('\\')) |
|
|
|
|
#define YFS_PATH_SEP_STR (YPATHSTR("\\")) |
|
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
|
|
#ifdef __linux__ |
|
|
|
|
|
|
|
|
|
#include <limits.h> |
|
|
|
|
#define YFS_PATH_MAX (PATH_MAX) |
|
|
|
|
|
|
|
|
|
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) |
|
|
|
|
|
|
|
|
|
#include <sys/param.h> |
|
|
|
|
|
|
|
|
|
#if defined(BSD) |
|
|
|
|
|
|
|
|
|
#include <limits.h> |
|
|
|
|
#define YFS_PATH_MAX (PATH_MAX) |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#define YFS_PATH_SEP (YPATHSTR('/')) |
|
|
|
|
#define YFS_PATH_SEP_STR (YPATHSTR("/")) |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifndef _MSC_VER |
|
|
|
|
|
|
|
|
|
#include <sys/stat.h> |
|
|
|
|
|
|
|
|
|
#include <dirent.h> |
|
|
|
|
#include <libgen.h> |
|
|
|
|
#include <stddef.h> |
|
|
|
|
|
|
|
|
|
#define YFS_PATH_EXTRA (0) |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup dir dir |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The public type for directories. This |
|
|
|
|
* is a pointer to hide the implementation. |
|
|
|
|
*/ |
|
|
|
|
typedef struct ydir* YDir; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup dirent dirent |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A struct to contain information |
|
|
|
|
* about a directory entry. |
|
|
|
|
*/ |
|
|
|
|
typedef struct YStat |
|
|
|
|
{ |
|
|
|
|
/// The size of the entry, in bytes, on disk.
|
|
|
|
|
/// For files, this is the file size.
|
|
|
|
|
size_t size; |
|
|
|
|
|
|
|
|
|
/// Whether the entry is a directory or not.
|
|
|
|
|
bool dir; |
|
|
|
|
|
|
|
|
|
/// Whether the entry is a file or not.
|
|
|
|
|
bool file; |
|
|
|
|
|
|
|
|
|
/// Whether the current user can read the entry or not.
|
|
|
|
|
bool read; |
|
|
|
|
|
|
|
|
|
/// Whether the current user can write to the entry or not.
|
|
|
|
|
bool write; |
|
|
|
|
|
|
|
|
|
/// Whether the current user can execute
|
|
|
|
|
/// the file or search the directory.
|
|
|
|
|
bool execute; |
|
|
|
|
|
|
|
|
|
} YStat; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup yfs yfs |
|
|
|
|
* Functions and data structures common to all of Yfs. |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup path path |
|
|
|
|
* Functions and data types for paths. |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def YFS_PATH_MAX |
|
|
|
|
* The max number of ychar's that a path can contain. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifndef YFS_PATH_MAX |
|
|
|
|
#define YFS_PATH_MAX (4096) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def YFS_FILENAME_MAX |
|
|
|
|
* The max number of ychar's that a file (entry) name can contain. |
|
|
|
|
*/ |
|
|
|
|
#define YFS_FILENAME_MAX (256) |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A common definition for paths. |
|
|
|
|
* Paths should not be modified. |
|
|
|
|
*/ |
|
|
|
|
typedef ychar* YPath; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the item at @a path. |
|
|
|
|
* @param path The path to the item to remove. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_path_remove(const YPath path) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves information about the item at @a path and |
|
|
|
|
* returns it in the @a YStat struct pointed to by @a st. |
|
|
|
|
* @param path The path to the item to collect data about. |
|
|
|
|
* @param st A pointer to the structure to fill. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, an error |
|
|
|
|
* code otherwise. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_path_stat(const YPath path, YStat* st) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens the parent directory of the item at @a path. |
|
|
|
|
* The directory must be closed with @a yfs_dir_close(). |
|
|
|
|
* @param path The path to the item whose directory |
|
|
|
|
* parent will be opened. |
|
|
|
|
* @return The newly-created YDir, or NULL and @a |
|
|
|
|
* ystatus will be set the the error. |
|
|
|
|
*/ |
|
|
|
|
YDir |
|
|
|
|
yfs_path_parent(YPath path) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the directory (parent) name of @a path. The |
|
|
|
|
* path must be freed with @a yfs_path_free(). |
|
|
|
|
* @param path The path to get the dirname for. |
|
|
|
|
* @return The dirname of @a path, or NULL |
|
|
|
|
* on error with @a ystatus set. |
|
|
|
|
*/ |
|
|
|
|
ychar* |
|
|
|
|
yfs_path_dirname(YPath path) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the base (file) name of @a path. The |
|
|
|
|
* path must be freed with @a yfs_path_free(). |
|
|
|
|
* @param path The path to get the basename for. |
|
|
|
|
* @return The basename of @a path, or NULL |
|
|
|
|
* on error with @a ystatus set. |
|
|
|
|
*/ |
|
|
|
|
ychar* |
|
|
|
|
yfs_path_basename(YPath path) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the path of the home directory. The |
|
|
|
|
* path must be freed with @a yfs_path_free(). |
|
|
|
|
* @return The home directory path, or NULL |
|
|
|
|
* on error with @a ystatus set. |
|
|
|
|
*/ |
|
|
|
|
ychar* |
|
|
|
|
yfs_path_home(void) ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the path of the temp directory. The |
|
|
|
|
* path must be freed with @a yfs_path_free(). |
|
|
|
|
* @return The temp directory path, or NULL |
|
|
|
|
* on error with @a ystatus set. |
|
|
|
|
*/ |
|
|
|
|
ychar* |
|
|
|
|
yfs_path_temp(void) ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the index within @a path that the file extension starts, |
|
|
|
|
* not including the leading period. |
|
|
|
|
* If there is no extension, this returns strlen(@a path). |
|
|
|
|
* @param path The path to query for the extension. |
|
|
|
|
* @return The index of the path that the extension starts. |
|
|
|
|
*/ |
|
|
|
|
uint32_t |
|
|
|
|
yfs_path_extIdx(const ychar path[]) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Concatenates @a path and @a name into one |
|
|
|
|
* path and returns the result. The path must |
|
|
|
|
* be freed with @a yfs_path_free(). |
|
|
|
|
* @param path The beginning part of the path. |
|
|
|
|
* @param name The file name. |
|
|
|
|
* @return The concatenated path. |
|
|
|
|
*/ |
|
|
|
|
ychar* |
|
|
|
|
yfs_path_concat(YPath path, YPath name) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Frees @a path. |
|
|
|
|
* @param path The path to free. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
yfs_path_free(ychar path[]) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup dirent dirent |
|
|
|
|
* Functions and data structures to manipulate directory entries. |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The public type for directory entries. |
|
|
|
|
* Entries are always within the context |
|
|
|
|
* of an open directory. |
|
|
|
|
*/ |
|
|
|
|
typedef uint32_t YDirent; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the entry's name. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return A pointer to the name. This |
|
|
|
|
* pointer is invalidated if the |
|
|
|
|
* parent is changed in any way. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
YPath |
|
|
|
|
yfs_dirent_name(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the entry's extension. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return A pointer to the extension. This |
|
|
|
|
* pointer is invalidated if the |
|
|
|
|
* parent is changed in any way. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
YPath |
|
|
|
|
yfs_dirent_ext(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the size of the entry (file size or |
|
|
|
|
* directory data size in bytes). |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return The entry's size, in bytes. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
size_t |
|
|
|
|
yfs_dirent_size(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the entry is a directory. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return true if directory, false otherwise. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dirent_isDir(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the entry is a file. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return true if file, false otherwise. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dirent_isFile(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the entry can be read by the |
|
|
|
|
* current user. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return true if the entry can be read, |
|
|
|
|
* false otherwise. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dirent_canRead(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the entry can be written by the |
|
|
|
|
* current user. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return true if the entry can be written, |
|
|
|
|
* false otherwise. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dirent_canWrite(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the entry can be executed (or |
|
|
|
|
* searched in the case of directories) by the |
|
|
|
|
* current user. |
|
|
|
|
* @param parent The parent directory. |
|
|
|
|
* @param dirent The index of the entry in the |
|
|
|
|
* parent directory. |
|
|
|
|
* @return true if the entry can be executed |
|
|
|
|
* or searched, false otherwise. |
|
|
|
|
* @pre @a parent must be opened. |
|
|
|
|
* @pre @a parent must have an entry |
|
|
|
|
* associated with @a dirent. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dirent_canExecute(const YDir parent, YDirent dirent) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup dir dir |
|
|
|
|
* Functions and data structures to manipulate directories. |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the directory at @a path. |
|
|
|
|
* @param path The path to create the directory at. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_dir_create(YPath path) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the directory at @a path, making sure to |
|
|
|
|
* create any missing parent directories. |
|
|
|
|
* @param path The path to create the directory at. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_dir_createWithParents(YPath path) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens and returns the directory at @a path. |
|
|
|
|
* The opened directory must be closed by using |
|
|
|
|
* @a yfs_dir_close(). |
|
|
|
|
* @param path The path to open the directory at. |
|
|
|
|
* @return The opened directory, or NULL on |
|
|
|
|
* error with @a ystatus set. |
|
|
|
|
*/ |
|
|
|
|
YDir |
|
|
|
|
yfs_dir_open(YPath path) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reopens @a dir with @a path. |
|
|
|
|
* @param d The directory to reopen. |
|
|
|
|
* @param path The path to open the directory at. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, an |
|
|
|
|
* error code otherwise. |
|
|
|
|
* @pre @a d must have been opened. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_dir_reopen(YDir d, YPath path) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sorts the open directory @a d. |
|
|
|
|
* @param d The directory to sort. |
|
|
|
|
* @param dirsFirst Whether to put directories |
|
|
|
|
* first or not. |
|
|
|
|
* @pre @a d must have been opened. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
yfs_dir_sort(YDir d, bool dirsFirst) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unsorts @a d. This does not change the order of |
|
|
|
|
* any entries, but if the directory is reopened with |
|
|
|
|
* another path, or used to open its parent or a |
|
|
|
|
* subdirectory, the new one will not be sorted. |
|
|
|
|
* @param d The directory to not sort. |
|
|
|
|
* @pre @a d must have been opened. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
yfs_dir_unsort(YDir d); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens the subdirectory of @a d at entry @a i. |
|
|
|
|
* The directory must not be closed first. |
|
|
|
|
* @param d The directory whose subdirectory |
|
|
|
|
* will be opened. |
|
|
|
|
* @param i The index of the entry that will |
|
|
|
|
* be opened. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
* @pre @a d must have been opened. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_dir_subdir(YDir d, YDirent i) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens the parent of @a d into @a d. |
|
|
|
|
* The directory must not be closed first. |
|
|
|
|
* @param d The directory whose parent |
|
|
|
|
* will be opened. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
* @pre @a d must have been opened. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_dir_parent(YDir d) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens the home directory into @a d. The directory |
|
|
|
|
* must not be closed first. |
|
|
|
|
* @param d The directory into which the home directory |
|
|
|
|
* will be opened. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
* @pre @a d must have been opened. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_dir_home(YDir d); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the path of @a dir. |
|
|
|
|
* The pointer will be invalidated if it is |
|
|
|
|
* reopened or closed, or if its parent or |
|
|
|
|
* a subdirectory is opened. |
|
|
|
|
* @param dir The directory to query. |
|
|
|
|
* @return The path of the directory. |
|
|
|
|
* @pre @a dir must have been opened. |
|
|
|
|
*/ |
|
|
|
|
YPath |
|
|
|
|
yfs_dir_path(YDir dir) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of entries in @a dir. |
|
|
|
|
* @param dir The directory to query. |
|
|
|
|
* @return The number of entries in @a dir. |
|
|
|
|
* @pre @a dir must have been opened. |
|
|
|
|
*/ |
|
|
|
|
uint32_t |
|
|
|
|
yfs_dir_numEntries(YDir dir) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if @a dir is sorted, false otherwise. |
|
|
|
|
* @param dir The directory to query. |
|
|
|
|
* @return true if sorted, false otherwise. |
|
|
|
|
* @pre @a dir must have been opened. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dir_sorted(YDir dir) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if @a dir is sorted with directories |
|
|
|
|
* first, false otherwise. |
|
|
|
|
* @param dir The directory to query. |
|
|
|
|
* @return true if sorted with directories first, |
|
|
|
|
* false otherwise. |
|
|
|
|
* @pre @a dir must have been opened. |
|
|
|
|
*/ |
|
|
|
|
bool |
|
|
|
|
yfs_dir_dirsFirst(YDir dir) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Closes the directory @a dir. |
|
|
|
|
* @param dir The directory to close. |
|
|
|
|
* @pre @a dir must have been opened. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
yfs_dir_close(YDir dir) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup file file |
|
|
|
|
* Functions and data structures to manipulate files. |
|
|
|
|
* @{ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the file at @a path. |
|
|
|
|
* @param path The path to create the file at. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_file_create(YPath path) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the file at @a path, making sure to |
|
|
|
|
* create any missing parent directories. |
|
|
|
|
* @param path The path to create the file at. |
|
|
|
|
* @return YSTATUS_SUCCESS on success, |
|
|
|
|
* an error code otherwise. |
|
|
|
|
*/ |
|
|
|
|
YStatus |
|
|
|
|
yfs_file_createWithParents(YPath path) yallnonnull; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a temp file name, creates the file, and returns |
|
|
|
|
* the path to the file. |
|
|
|
|
* @param dir The directory to create the file in. |
|
|
|
|
* @param prefix The prefix to prepend to the file name. |
|
|
|
|
* @return The path of the temp file, or NULL on |
|
|
|
|
* error with @a ystatus set. |
|
|
|
|
*/ |
|
|
|
|
ychar* |
|
|
|
|
yfs_file_temp(YPath dir, YPath prefix) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The public definition of Yfs file contents. |
|
|
|
|
* This allows the user to index it directly. |
|
|
|
|
*/ |
|
|
|
|
typedef char* YFile; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads the entirety of the file at @a path and returns a |
|
|
|
|
* @a YFile (byte array) with the contents. The param |
|
|
|
|
* @a binary indicates whether the file is a binary file |
|
|
|
|
* or not. If not, Yfs will add a terminating null char. |
|
|
|
|
* |
|
|
|
|
* The file must be freed with @a yfs_file_free(). |
|
|
|
|
* @param path The path to the file. |
|
|
|
|
* @param binary true if the file is a binary file, |
|
|
|
|
* false otherwise. |
|
|
|
|
* @return The new @a YFile, or NULL on error and |
|
|
|
|
* @a ystatus is set to the error code. |
|
|
|
|
*/ |
|
|
|
|
YFile |
|
|
|
|
yfs_file_read(YPath path, bool binary) yallnonnull ynoretalias; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Frees the data read into a YFile. |
|
|
|
|
* @param file The file data to free. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
yfs_file_free(YFile file) yallnonnull yinline; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#endif // YC_FILE_H
|