29# include <sys/ioctl.h>
76 if ((entry1->
type & S_IFMT) < (entry2->
type & S_IFMT)) {
79 if ((entry1->
type & S_IFMT) > (entry2->
type & S_IFMT)) {
114 "Failed to open dir (%s): %s\n",
115 errno ? strerror(errno) :
"unknown error",
120 ListBase dirbase = {
nullptr,
nullptr};
123 bool has_current =
false, has_parent =
false;
127 dirname_with_slash,
dirname,
sizeof(dirname_with_slash) - 1);
129 if ((dirname_with_slash_len > 0) &&
132 dirname_with_slash[dirname_with_slash_len++] =
SEP;
133 dirname_with_slash[dirname_with_slash_len] =
'\0';
136 while ((fname =
readdir(dir)) !=
nullptr) {
138 if (dlink !=
nullptr) {
157 if (dlink !=
nullptr) {
166 if (dlink !=
nullptr) {
174 if (dir_ctx->
files) {
182 dir_ctx->
files =
nullptr;
186 if (dir_ctx->
files ==
nullptr) {
191 fprintf(stderr,
"Couldn't get memory for dir: %s\n",
dirname);
200 file->relname = dlink->
name;
202 if (
BLI_stat(file->path, &file->s) != -1) {
203 file->type = file->s.st_mode;
208 file->type |= S_IFDIR;
215 qsort(dir_ctx->
files,
232 dir_ctx.
files =
nullptr;
237 *r_filelist = dir_ctx.
files;
258 double size =
double(st ? st->st_size : st_size_fallback);
282 const char *types[8] = {
"---",
"--x",
"-w-",
"-wx",
"r--",
"r-x",
"rw-",
"rwx"};
290 const int mode = st->st_mode;
296 if (((mode & S_ISGID) == S_ISGID) && (r_mode2[2] ==
'-')) {
300 if (mode & (S_ISUID | S_ISGID)) {
301 if (r_mode1[2] ==
'x') {
308 if (r_mode2[2] ==
'x') {
313 if (mode & S_ISVTX) {
314 if (r_mode3[2] ==
'x') {
332 const passwd *pwuser = getpwuid(st->st_uid);
349 bool *r_is_yesterday)
353 int yesterday_year = 0;
354 int yesterday_yday = 0;
356 if (r_is_today || r_is_yesterday) {
358 const time_t ts_now =
time(
nullptr);
359 tm *today = localtime(&ts_now);
361 today_year = today->tm_year;
362 today_yday = today->tm_yday;
366 yesterday_year = today->tm_year;
367 yesterday_yday = today->tm_yday;
372 if (r_is_yesterday) {
373 *r_is_yesterday =
false;
377 const time_t ts_mtime = ts;
378 const tm *tm = localtime(st ? &st->st_mtime : &ts_mtime);
379 const time_t zero = 0;
383 tm = localtime(&zero);
393 compact ?
"%d/%m/%y" :
"%d %b %Y",
397 if (r_is_today && (tm->tm_year == today_year) && (tm->tm_yday == today_yday)) {
400 else if (r_is_yesterday && (tm->tm_year == yesterday_year) && (tm->tm_yday == yesterday_yday)) {
401 *r_is_yesterday =
true;
418 const uint nrentries)
422 *dest_filelist =
static_cast<direntry *
>(
423 MEM_mallocN(
sizeof(**dest_filelist) *
size_t(nrentries), __func__));
424 for (i = 0; i < nrentries; i++) {
425 const direntry *src = &src_filelist[i];
426 direntry *dst = &(*dest_filelist)[i];
444 for (i = 0; i < nrentries; i++) {
448 if (filelist !=
nullptr) {
static int direntry_cmp(direntry *entry1, direntry *entry2)
void BLI_filelist_entry_owner_to_string(const struct stat *st, const bool, char r_owner[FILELIST_DIRENTRY_OWNER_LEN])
void BLI_filelist_duplicate(direntry **dest_filelist, direntry *const src_filelist, const uint nrentries)
void BLI_filelist_entry_datetime_to_string(const struct stat *st, const int64_t ts, const bool compact, char r_time[FILELIST_DIRENTRY_TIME_LEN], char r_date[FILELIST_DIRENTRY_DATE_LEN], bool *r_is_today, bool *r_is_yesterday)
static void bli_builddir(BuildDirCtx *dir_ctx, const char *dirname)
void BLI_filelist_entry_free(direntry *entry)
void BLI_filelist_entry_duplicate(direntry *dst, const direntry *src)
void BLI_filelist_entry_size_to_string(const struct stat *st, const uint64_t st_size_fallback, const bool compact, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
uint BLI_filelist_dir_contents(const char *dirname, direntry **r_filelist)
void BLI_filelist_free(direntry *filelist, const uint nrentries)
void BLI_filelist_entry_mode_to_string(const struct stat *st, const bool, char r_mode1[FILELIST_DIRENTRY_MODE_LEN], char r_mode2[FILELIST_DIRENTRY_MODE_LEN], char r_mode3[FILELIST_DIRENTRY_MODE_LEN])
File and directory operations.
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()
Some types for dealing with directories.
#define FILELIST_DIRENTRY_SIZE_LEN
#define FILELIST_DIRENTRY_MODE_LEN
#define FILELIST_DIRENTRY_OWNER_LEN
#define FILELIST_DIRENTRY_DATE_LEN
#define FILELIST_DIRENTRY_TIME_LEN
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_freelist(struct ListBase *listbase) ATTR_NONNULL(1)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
#define FILENAME_IS_CURRENT(_n)
#define FILENAME_IS_CURRPAR(_n)
BLI_INLINE bool BLI_path_slash_is_native_compat(const char ch)
#define FILENAME_IS_PARENT(_n)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
#define STRNCPY(dst, src)
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 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)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
int char char int int int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
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
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define BLI_string_joinN(...)
Compatibility-like things for windows.
struct dirent * readdir(DIR *dp)
const char * dirname(char *path)
DIR * opendir(const char *path)
typedef double(DMatrix)[4][4]
These structs are the foundation for all linked lists in the library system.
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
unsigned __int64 uint64_t