29# include <sys/ioctl.h>
78 if ((entry1->
type & S_IFMT) < (entry2->
type & S_IFMT)) {
81 if ((entry1->
type & S_IFMT) > (entry2->
type & S_IFMT)) {
115 if (dir ==
nullptr) [[unlikely]] {
117 "Failed to open dir (%s): %s\n",
118 errno ? strerror(errno) :
"unknown error",
123 ListBaseT<dirlink> dirbase = {
nullptr,
nullptr};
126 bool has_current =
false, has_parent =
false;
130 dirname_with_slash,
dirname,
sizeof(dirname_with_slash) - 1);
132 if ((dirname_with_slash_len > 0) &&
135 dirname_with_slash[dirname_with_slash_len++] =
SEP;
136 dirname_with_slash[dirname_with_slash_len] =
'\0';
139 while ((fname =
readdir(dir)) !=
nullptr) {
141 if (dlink !=
nullptr) {
160 if (dlink !=
nullptr) {
169 if (dlink !=
nullptr) {
177 if (dir_ctx->
files) {
184 MEM_delete(dir_ctx->
files);
185 dir_ctx->
files =
nullptr;
189 if (dir_ctx->
files ==
nullptr) {
193 if (dir_ctx->
files ==
nullptr) [[unlikely]] {
194 fprintf(stderr,
"Couldn't get memory for dir: %s\n",
dirname);
198 dirlink *dlink = dirbase.first();
206 file->
type = file->
s.st_mode;
211 file->
type |= S_IFDIR;
218 qsort(dir_ctx->
files,
221 reinterpret_cast<int (*)(
const void *,
const void *)
>(
direntry_cmp));
235 dir_ctx.
files =
nullptr;
240 *r_filelist = dir_ctx.
files;
261 double size = double(st ? st->st_size : st_size_fallback);
285 const char *types[8] = {
"---",
"--x",
"-w-",
"-wx",
"r--",
"r-x",
"rw-",
"rwx"};
293 const int mode = st->st_mode;
299 if (((mode & S_ISGID) == S_ISGID) && (r_mode2[2] ==
'-')) {
303 if (mode & (S_ISUID | S_ISGID)) {
304 if (r_mode1[2] ==
'x') {
311 if (r_mode2[2] ==
'x') {
316 if (mode & S_ISVTX) {
317 if (r_mode3[2] ==
'x') {
335 const passwd *pwuser = getpwuid(st->st_uid);
353 dst->
path = MEM_dupalloc(src->
path);
359 const uint nrentries)
364 for (i = 0; i < nrentries; i++) {
365 const direntry *src = &src_filelist[i];
366 direntry *dst = &(*dest_filelist)[i];
377 MEM_delete(entry->
path);
384 for (i = 0; i < nrentries; i++) {
388 if (filelist !=
nullptr) {
389 MEM_delete(filelist);
File and directory operations.
Some types for dealing with directories.
#define FILELIST_DIRENTRY_SIZE_LEN
#define FILELIST_DIRENTRY_MODE_LEN
#define FILELIST_DIRENTRY_OWNER_LEN
#define FILENAME_IS_CURRENT(_n)
#define FILENAME_IS_CURRPAR(_n)
#define FILENAME_IS_PARENT(_n)
#define BLI_string_joinN(...)
Compatibility-like things for windows.
struct dirent * readdir(DIR *dp)
const char * dirname(char *path)
DIR * opendir(const char *path)
These structs are the foundation for all linked lists in the library system.
Read Blender memory allocation and freeing.
#define MEM_realloc_uninitialized(vmemh, len)
void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], long long int bytes, bool base_10) ATTR_NONNULL(1)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BLI_filelist_duplicate(struct direntry **dest_filelist, struct direntry *const src_filelist, unsigned int nrentries)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * STRNCPY(char(&dst)[N], const char *src)
int char char int int int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist)
void BLI_filelist_entry_mode_to_string(const struct stat *st, bool compact, char r_mode1[FILELIST_DIRENTRY_MODE_LEN], char r_mode2[FILELIST_DIRENTRY_MODE_LEN], char r_mode3[FILELIST_DIRENTRY_MODE_LEN])
BLI_INLINE bool BLI_path_slash_is_native_compat(const char ch)
void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src)
void BLI_str_format_byte_unit_compact(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE], long long int bytes, bool base_10) ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void BLI_freelist(ListBase *listbase) ATTR_NONNULL(1)
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_access(const char *filepath, int mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static void bli_builddir(BuildDirCtx *dir_ctx, const char *dirname)
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
static int direntry_cmp(direntry *entry1, direntry *entry2)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
void BLI_filelist_entry_free(struct direntry *entry)
void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void BLI_filelist_entry_owner_to_string(const struct stat *st, bool compact, char r_owner[FILELIST_DIRENTRY_OWNER_LEN])
void BLI_filelist_entry_size_to_string(const struct stat *st, uint64_t st_size_fallback, bool compact, char r_size[FILELIST_DIRENTRY_SIZE_LEN])