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)) {
115 "Failed to open dir (%s): %s\n",
116 errno ? strerror(errno) :
"unknown error",
121 ListBase dirbase = {
nullptr,
nullptr};
124 bool has_current =
false, has_parent =
false;
128 dirname_with_slash,
dirname,
sizeof(dirname_with_slash) - 1);
130 if ((dirname_with_slash_len > 0) &&
133 dirname_with_slash[dirname_with_slash_len++] =
SEP;
134 dirname_with_slash[dirname_with_slash_len] =
'\0';
137 while ((fname =
readdir(dir)) !=
nullptr) {
139 if (dlink !=
nullptr) {
158 if (dlink !=
nullptr) {
167 if (dlink !=
nullptr) {
175 if (dir_ctx->
files) {
183 dir_ctx->
files =
nullptr;
187 if (dir_ctx->
files ==
nullptr) {
192 fprintf(stderr,
"Couldn't get memory for dir: %s\n",
dirname);
204 file->
type = file->
s.st_mode;
209 file->
type |= S_IFDIR;
216 qsort(dir_ctx->
files,
233 dir_ctx.
files =
nullptr;
238 *r_filelist = dir_ctx.
files;
259 double size = double(st ? st->st_size : st_size_fallback);
283 const char *
types[8] = {
"---",
"--x",
"-w-",
"-wx",
"r--",
"r-x",
"rw-",
"rwx"};
291 const int mode = st->st_mode;
297 if (((mode & S_ISGID) == S_ISGID) && (r_mode2[2] ==
'-')) {
301 if (mode & (S_ISUID | S_ISGID)) {
302 if (r_mode1[2] ==
'x') {
309 if (r_mode2[2] ==
'x') {
314 if (mode & S_ISVTX) {
315 if (r_mode3[2] ==
'x') {
333 const passwd *pwuser = getpwuid(st->st_uid);
350 bool *r_is_yesterday)
354 int yesterday_year = 0;
355 int yesterday_yday = 0;
357 if (r_is_today || r_is_yesterday) {
359 const time_t ts_now = time(
nullptr);
360 tm *today = localtime(&ts_now);
362 today_year = today->tm_year;
363 today_yday = today->tm_yday;
367 yesterday_year = today->tm_year;
368 yesterday_yday = today->tm_yday;
373 if (r_is_yesterday) {
374 *r_is_yesterday =
false;
378 const time_t ts_mtime = ts;
379 const tm *tm = localtime(st ? &st->st_mtime : &ts_mtime);
380 const time_t zero = 0;
384 tm = localtime(&zero);
394 compact ?
"%d/%m/%y" :
"%d %b %Y",
398 if (r_is_today && (tm->tm_year == today_year) && (tm->tm_yday == today_yday)) {
401 else if (r_is_yesterday && (tm->tm_year == yesterday_year) && (tm->tm_yday == yesterday_yday)) {
402 *r_is_yesterday =
true;
419 const uint nrentries)
424 for (
i = 0;
i < nrentries;
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_freelist(ListBase *listbase) ATTR_NONNULL(1)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
#define FILENAME_IS_CURRENT(_n)
#define FILENAME_IS_CURRPAR(_n)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
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
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)
char * STRNCPY(char(&dst)[N], const char *src)
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)
These structs are the foundation for all linked lists in the library system.
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void * MEM_mallocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_dupallocN(const void *vmemh)
void MEM_freeN(void *vmemh)