Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added path delimiter configuration option #653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#define LFS_BLOCK_NULL ((lfs_block_t)-1)
#define LFS_BLOCK_INLINE ((lfs_block_t)-2)

// create a string out of the character
static const char lsf_path_delimiter[2] = {LSF_PATH_DELIMITER, '\0'};
#define LSF_PATH_DELIMITER_STR (&lsf_path_delimiter[0])

/// Caching block device operations ///
static inline void lfs_cache_drop(lfs_t *lfs, lfs_cache_t *rcache) {
// do not zero, cheaper if cache is readonly or only going to be
Expand Down Expand Up @@ -1102,7 +1106,7 @@ static int lfs_dir_getinfo(lfs_t *lfs, lfs_mdir_t *dir,
uint16_t id, struct lfs_info *info) {
if (id == 0x3ff) {
// special case for root
strcpy(info->name, "/");
strcpy(info->name, LSF_PATH_DELIMITER_STR);
info->type = LFS_TYPE_DIR;
return 0;
}
Expand Down Expand Up @@ -1178,8 +1182,8 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
while (true) {
nextname:
// skip slashes
name += strspn(name, "/");
lfs_size_t namelen = strcspn(name, "/");
name += strspn(name, LSF_PATH_DELIMITER_STR);
lfs_size_t namelen = strcspn(name, LSF_PATH_DELIMITER_STR);

// skip '.' and root '..'
if ((namelen == 1 && memcmp(name, ".", 1) == 0) ||
Expand All @@ -1193,8 +1197,8 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
lfs_size_t sufflen;
int depth = 1;
while (true) {
suffix += strspn(suffix, "/");
sufflen = strcspn(suffix, "/");
suffix += strspn(suffix, LSF_PATH_DELIMITER_STR);
sufflen = strcspn(suffix, LSF_PATH_DELIMITER_STR);
if (sufflen == 0) {
break;
}
Expand Down Expand Up @@ -1241,7 +1245,7 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
LFS_MKTAG(0x780, 0, 0),
LFS_MKTAG(LFS_TYPE_NAME, 0, namelen),
// are we last name?
(strchr(name, '/') == NULL) ? id : NULL,
(strchr(name, LSF_PATH_DELIMITER) == NULL) ? id : NULL,
lfs_dir_find_match, &(struct lfs_dir_find_match){
lfs, name, namelen});
if (tag < 0) {
Expand Down
8 changes: 7 additions & 1 deletion lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C"
// Software library version
// Major (top-nibble), incremented on backwards incompatible changes
// Minor (bottom-nibble), incremented on feature additions
#define LFS_VERSION 0x00020004
#define LFS_VERSION 0x00020005
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))

Expand Down Expand Up @@ -67,6 +67,12 @@ typedef uint32_t lfs_block_t;
#define LFS_ATTR_MAX 1022
#endif

// Path delimiter used to separate path tokens
// Default : POSIX like slash
#ifndef LSF_PATH_DELIMITER
#define LSF_PATH_DELIMITER '/'
#endif

// Possible error codes, these are negative to allow
// valid positive return values
enum lfs_error {
Expand Down