23 #include <sys/types.h>
40 # include <sys/ioctl.h>
55 #include "../imbuf/IMB_imbuf.h"
88 if ((entry1->
type & S_IFMT) < (entry2->
type & S_IFMT)) {
91 if ((entry1->
type & S_IFMT) > (entry2->
type & S_IFMT)) {
128 const struct dirent *fname;
129 bool has_current =
false, has_parent =
false;
169 if (dir_ctx->
files) {
186 if (dir_ctx->
files) {
201 file->type |= S_IFDIR;
209 printf(
"Couldn't get memory for dir\n");
214 if (dir_ctx->
files) {
215 qsort(dir_ctx->
files,
222 printf(
"%s empty directory\n",
dirname);
228 printf(
"%s non-existent directory\n",
dirname);
248 *r_filelist = dir_ctx.
files;
253 *r_filelist =
MEM_mallocN(
sizeof(**r_filelist), __func__);
265 const bool UNUSED(compact),
273 double size = (
double)(st ? st->st_size : sz);
285 const bool UNUSED(compact),
290 const char *
types[8] = {
"---",
"--x",
"-w-",
"-wx",
"r--",
"r-x",
"rw-",
"rwx"};
297 const int mode = st->st_mode;
303 if (((mode & S_ISGID) == S_ISGID) && (r_mode2[2] ==
'-')) {
307 if (mode & (S_ISUID | S_ISGID)) {
308 if (r_mode1[2] ==
'x') {
315 if (r_mode2[2] ==
'x') {
320 if (mode & S_ISVTX) {
321 if (r_mode3[2] ==
'x') {
335 const bool UNUSED(compact),
339 strcpy(r_owner,
"unknown");
341 struct passwd *pwuser = getpwuid(st->st_uid);
364 bool *r_is_yesterday)
368 int yesterday_year = 0;
369 int yesterday_yday = 0;
371 if (r_is_today || r_is_yesterday) {
374 struct tm *today = localtime(&ts_now);
376 today_year = today->tm_year;
377 today_yday = today->tm_yday;
381 yesterday_year = today->tm_year;
382 yesterday_yday = today->tm_yday;
387 if (r_is_yesterday) {
388 *r_is_yesterday =
false;
392 const time_t ts_mtime = ts;
393 const struct tm *tm = localtime(st ? &st->st_mtime : &ts_mtime);
394 const time_t zero = 0;
398 tm = localtime(&zero);
408 compact ?
"%d/%m/%y" :
"%d %b %Y",
412 if (r_is_today && (tm->tm_year == today_year) && (tm->tm_yday == today_yday)) {
415 else if (r_is_yesterday && (tm->tm_year == yesterday_year) && (tm->tm_yday == yesterday_yday)) {
416 *r_is_yesterday =
true;
438 struct direntry *
const src_filelist,
439 const unsigned int nrentries)
443 *dest_filelist =
MEM_mallocN(
sizeof(**dest_filelist) * (
size_t)(nrentries), __func__);
444 for (i = 0; i < nrentries; i++) {
445 struct direntry *
const src = &src_filelist[i];
446 struct direntry *dst = &(*dest_filelist)[i];
470 for (i = 0; i < nrentries; i++) {
474 if (filelist !=
NULL) {
void BLI_filelist_entry_size_to_string(const struct stat *st, const uint64_t sz, const bool UNUSED(compact), char r_size[FILELIST_DIRENTRY_SIZE_LEN])
static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
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)
void BLI_filelist_entry_mode_to_string(const struct stat *st, const bool UNUSED(compact), char r_mode1[FILELIST_DIRENTRY_MODE_LEN], char r_mode2[FILELIST_DIRENTRY_MODE_LEN], char r_mode3[FILELIST_DIRENTRY_MODE_LEN])
void BLI_filelist_free(struct direntry *filelist, const unsigned int nrentries)
unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist)
void BLI_filelist_entry_free(struct direntry *entry)
void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src)
void BLI_filelist_entry_owner_to_string(const struct stat *st, const bool UNUSED(compact), char r_owner[FILELIST_DIRENTRY_OWNER_LEN])
void BLI_filelist_duplicate(struct direntry **dest_filelist, struct direntry *const src_filelist, const unsigned int nrentries)
static int bli_compare(struct direntry *entry1, struct direntry *entry2)
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 *filename, 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)
#define FILENAME_IS_CURRENT(_n)
void BLI_join_dirfile(char *__restrict dst, const size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
#define FILENAME_IS_CURRPAR(_n)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL()
#define FILENAME_IS_PARENT(_n)
void BLI_str_format_byte_unit(char dst[15], long long int bytes, const bool base_10) ATTR_NONNULL()
int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Compatibility-like things for windows.
const char * dirname(char *path)
struct dirent * readdir(DIR *dp)
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)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
unsigned __int64 uint64_t