Skip to content

Commit

Permalink
improve for qnx
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Jan 11, 2025
1 parent 78ecaab commit 7dec37e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/platforms/pc/fs_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ static ret_t fs_os_dir_read(fs_dir_t* dir, fs_item_t* item) {
memset(item, 0x00, sizeof(fs_item_t));
if (ent != NULL) {
#ifdef QNX
/*FIXME*/
item->is_reg_file = 1;
struct stat st;
char filename[MAX_PATH + 1] = {0};
tk_snprintf(filename, sizeof(filename) - 1, "%s/%s", dir->dirname, ent->d_name);

if (stat(filename, &st) == 0) {
item->is_dir = (st.st_mode & S_IFDIR) != 0;
item->is_link = (st.st_mode & S_IFLNK) != 0;
item->is_reg_file = (st.st_mode & S_IFREG) != 0;
} else {
item->is_reg_file = 1;
}
#else
uint8_t type = ent->d_type;
item->is_dir = (type & DT_DIR) != 0;
Expand Down
9 changes: 7 additions & 2 deletions src/tkc/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ret_t fs_dir_read(fs_dir_t* dir, fs_item_t* item) {

ret_t fs_dir_close(fs_dir_t* dir) {
return_value_if_fail(dir != NULL && dir->vt != NULL && dir->vt->close != NULL, RET_BAD_PARAMS);

TKMEM_FREE(dir->dirname);
return dir->vt->close(dir);
}

Expand Down Expand Up @@ -175,9 +175,14 @@ ret_t fs_file_rename(fs_t* fs, const char* name, const char* new_name) {
}

fs_dir_t* fs_open_dir(fs_t* fs, const char* name) {
fs_dir_t* dir = NULL;
return_value_if_fail(fs != NULL && fs->open_dir != NULL && name != NULL, NULL);

return fs->open_dir(fs, name);
dir = fs->open_dir(fs, name);
return_value_if_fail(dir != NULL, NULL);
dir->dirname = tk_strdup(name);

return dir;
}

ret_t fs_remove_dir(fs_t* fs, const char* name) {
Expand Down
1 change: 1 addition & 0 deletions src/tkc/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ typedef struct _fs_dir_vtable_t {
struct _fs_dir_t {
const fs_dir_vtable_t* vt;
void* data;
char* dirname;
};

/**
Expand Down

0 comments on commit 7dec37e

Please sign in to comment.