17#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__HAIKU__)
19# include <sys/statvfs.h>
20# define USE_STATFS_STATVFS
23#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
24 defined(__DragonFly__)
26# include <sys/mount.h>
27# include <sys/param.h>
30#if defined(__linux__) || defined(__hpux) || defined(__GNU__) || defined(__GLIBC__)
47# include <sys/ioctl.h>
62#if !defined(__APPLE__)
75 return _wchdir(wdir) == 0;
77 int result = chdir(dir);
88 wchar_t path[MAX_PATH];
89 if (_wgetcwd(path, MAX_PATH)) {
99 if (srclen != maxncpy) {
100 memcpy(dir, pwd, srclen + 1);
105 return getcwd(dir, maxncpy);
113 DWORD sectorspc, bytesps, freec, clusters;
118 if (
ELEM(dir[0],
'/',
'\\')) {
122 else if (dir[1] ==
':') {
129 GetDiskFreeSpace(tmp, §orspc, &bytesps, &freec, &clusters);
131 return double(freec * bytesps * sectorspc);
134# ifdef USE_STATFS_STATVFS
141 int len = strlen(dir);
161# if defined(USE_STATFS_STATVFS)
165# elif defined(USE_STATFS_4ARGS)
166 if (statfs(
dirname, &disk,
sizeof(
struct statfs), 0)) {
182 return _ftelli64(stream);
184 return ftell(stream);
191 return _fseeki64(stream, offset, whence);
193 return fseek(stream, offset, whence);
200 return _lseeki64(fd, offset, whence);
202 return lseek(fd, offset, whence);
209 if ((file < 0) || (
BLI_fstat(file, &st) == -1)) {
221 return stats.st_size;
241 DWORD attr = GetFileAttributesW(wline);
242 if (attr == INVALID_FILE_ATTRIBUTES) {
244 "BLI_file_attributes should only be called on existing files.");
248 if (attr & FILE_ATTRIBUTE_READONLY) {
251 if (attr & FILE_ATTRIBUTE_HIDDEN) {
254 if (attr & FILE_ATTRIBUTE_SYSTEM) {
257 if (attr & FILE_ATTRIBUTE_ARCHIVE) {
260 if (attr & FILE_ATTRIBUTE_COMPRESSED) {
263 if (attr & FILE_ATTRIBUTE_ENCRYPTED) {
266 if (attr & FILE_ATTRIBUTE_TEMPORARY) {
269 if (attr & FILE_ATTRIBUTE_SPARSE_FILE) {
272 if (attr & FILE_ATTRIBUTE_OFFLINE || attr & FILE_ATTRIBUTE_RECALL_ON_OPEN ||
273 attr & FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS)
277 if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
307 HRESULT hr = CoInitializeEx(
NULL, COINIT_MULTITHREADED);
312 IShellLinkW *Shortcut =
NULL;
313 hr = CoCreateInstance(
314 CLSID_ShellLink,
NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID *)&Shortcut);
316 bool success =
false;
318 IPersistFile *PersistFile;
319 hr = Shortcut->QueryInterface(IID_IPersistFile, (LPVOID *)&PersistFile);
323 hr = PersistFile->Load(path_utf16, STGM_READ);
325 hr = Shortcut->Resolve(0, SLR_NO_UI | SLR_UPDATE | SLR_NOSEARCH);
333 PersistFile->Release();
341 return (success && r_targetpath[0]);
357 len = wcslen(tmp_16);
361 tmp_16[
len - 1] =
'\0';
367 if ((
len >= 3) && (tmp_16[0] ==
L'\\') && (tmp_16[1] ==
L'\\')) {
368 BLI_path_normalize_unc_16(tmp_16);
371 if ((tmp_16[1] ==
L':') && (tmp_16[2] ==
L'\0')) {
376 res = BLI_wstat(tmp_16, &st);
385 if (stat(path, &st)) {
395# if defined(_MSC_VER)
396 return _fstat64(fd, buffer);
398 return _fstat(fd, buffer);
407 r = BLI_wstat(path_16, buffer);
413int BLI_wstat(
const wchar_t *path,
BLI_stat_t *buffer)
415# if defined(_MSC_VER)
416 return _wstat64(path, buffer);
418 return _wstat(path, buffer);
424 return fstat(fd, buffer);
429 return stat(path, buffer);
441 return (mode && !
S_ISDIR(mode));
448 bool read_size_exact,
471 void *mem =
MEM_mallocN(filelen + pad_bytes, __func__);
472 if (mem ==
nullptr) {
476 const long int filelen_read = fread(mem, 1, filelen, fp);
477 if ((filelen_read < 0) || ferror(fp)) {
482 if (read_size_exact) {
483 if (filelen_read != filelen) {
489 if (filelen_read < filelen) {
491 if (mem ==
nullptr) {
497 *r_size = filelen_read;
525 bool trim_trailing_space,
530 if (mem !=
nullptr) {
531 char *mem_end = mem + *r_size;
532 if (pad_bytes != 0) {
535 for (
char *p = mem, *p_next; p != mem_end; p = p_next) {
536 p_next =
static_cast<char *
>(memchr(p,
'\n', mem_end - p));
537 if (p_next !=
nullptr) {
538 if (trim_trailing_space) {
539 for (
char *p_trim = p_next - 1; p_trim > p &&
ELEM(*p_trim,
' ',
'\t'); p_trim--) {
574 buf = MEM_cnew_array<char>(size,
"file_as_lines");
583 size = fread(buf, 1, size, fp);
584 for (i = 0; i <=
size; i++) {
585 if (i == size || buf[i] ==
'\n') {
614 return (st1.st_mtime < st2.st_mtime);
#define BLI_assert_msg(a, msg)
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
@ FILE_ATTR_REPARSE_POINT
void BLI_kdtree_nd_ free(KDTree *tree)
void BLI_linklist_freeN(LinkNode *list)
void void void void BLI_linklist_append(LinkNodePair *list_pair, void *ptr) ATTR_NONNULL(1)
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
int BLI_thread_is_main(void)
Compatibility-like things for windows.
const char * dirname(char *path)
typedef double(DMatrix)[4][4]
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
bool BLI_change_working_dir(const char *dir)
eFileAttributes BLI_file_attributes(const char *path)
int BLI_exists(const char *path)
bool BLI_file_older(const char *file1, const char *file2)
void BLI_file_free_lines(LinkNode *lines)
int BLI_fstat(int fd, struct stat *buffer)
LinkNode * BLI_file_read_as_lines(const char *filepath)
int BLI_stat(const char *path, struct stat *buffer)
size_t BLI_file_descriptor_size(int file)
void * BLI_file_read_binary_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
int64_t BLI_lseek(int fd, int64_t offset, int whence)
double BLI_dir_free_space(const char *dir)
size_t BLI_file_size(const char *path)
bool BLI_file_alias_target(const char *filepath, char r_targetpath[])
bool BLI_is_dir(const char *path)
int BLI_fseek(FILE *stream, int64_t offset, int whence)
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
void * BLI_file_read_text_as_mem_with_newline_as_nil(const char *filepath, bool trim_trailing_space, size_t pad_bytes, size_t *r_size)
char * BLI_current_working_dir(char *dir, const size_t maxncpy)
void * BLI_file_read_data_as_mem_from_handle(FILE *fp, bool read_size_exact, size_t pad_bytes, size_t *r_size)
bool BLI_is_file(const char *path)
int64_t BLI_ftell(FILE *stream)
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16)
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
#define UTF16_ENCODE(in8str)
#define UTF16_UN_ENCODE(in8str)