28 #include <sys/types.h>
32 #if defined(__NetBSD__) || defined(__DragonFly__) || defined(__HAIKU__)
34 # include <sys/statvfs.h>
35 # define USE_STATFS_STATVFS
38 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
39 defined(__DragonFly__)
41 # include <sys/mount.h>
42 # include <sys/param.h>
45 #if defined(__linux__) || defined(__hpux) || defined(__GNU__) || defined(__GLIBC__)
56 # include <ShObjIdl.h>
62 # include <sys/ioctl.h>
84 wchar_t path[MAX_PATH];
85 if (_wgetcwd(path, MAX_PATH)) {
95 if (srclen != maxncpy) {
96 memcpy(dir, pwd, srclen + 1);
101 return getcwd(dir, maxncpy);
112 DWORD sectorspc, bytesps, freec, clusters;
117 if (
ELEM(dir[0],
'/',
'\\')) {
121 else if (dir[1] ==
':') {
128 GetDiskFreeSpace(tmp, §orspc, &bytesps, &freec, &clusters);
130 return (
double)(freec * bytesps * sectorspc);
133 # ifdef USE_STATFS_STATVFS
140 int len = strlen(dir);
150 slash = strrchr(name,
'/');
159 # if defined(USE_STATFS_STATVFS)
160 if (statvfs(name, &disk)) {
163 # elif defined(USE_STATFS_4ARGS)
164 if (statfs(name, &disk,
sizeof(
struct statfs), 0)) {
168 if (statfs(name, &disk)) {
173 return (((
double)disk.f_bsize) * ((
double)disk.f_bfree));
180 return _ftelli64(stream);
182 return ftell(stream);
189 return _fseeki64(stream, offset, whence);
191 return fseek(stream, offset, whence);
198 return _lseeki64(fd, offset, whence);
200 return lseek(fd, offset, whence);
225 return stats.st_size;
244 DWORD attr = GetFileAttributesW(wline);
245 if (attr & FILE_ATTRIBUTE_READONLY) {
248 if (attr & FILE_ATTRIBUTE_HIDDEN) {
251 if (attr & FILE_ATTRIBUTE_SYSTEM) {
254 if (attr & FILE_ATTRIBUTE_ARCHIVE) {
257 if (attr & FILE_ATTRIBUTE_COMPRESSED) {
260 if (attr & FILE_ATTRIBUTE_ENCRYPTED) {
263 if (attr & FILE_ATTRIBUTE_TEMPORARY) {
266 if (attr & FILE_ATTRIBUTE_SPARSE_FILE) {
269 if (attr & FILE_ATTRIBUTE_OFFLINE) {
272 if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
302 HRESULT hr = CoInitializeEx(
NULL, COINIT_MULTITHREADED);
307 IShellLinkW *Shortcut =
NULL;
308 hr = CoCreateInstance(
309 &CLSID_ShellLink,
NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (
LPVOID *)&Shortcut);
311 bool success =
false;
313 IPersistFile *PersistFile;
314 hr = Shortcut->lpVtbl->QueryInterface(Shortcut, &IID_IPersistFile, (
LPVOID *)&PersistFile);
318 hr = PersistFile->lpVtbl->Load(PersistFile, path_utf16, STGM_READ);
320 hr = Shortcut->lpVtbl->Resolve(Shortcut, 0, SLR_NO_UI | SLR_UPDATE);
323 hr = Shortcut->lpVtbl->GetPath(Shortcut, target_utf16,
FILE_MAXDIR,
NULL, 0);
328 PersistFile->lpVtbl->Release(PersistFile);
332 Shortcut->lpVtbl->Release(Shortcut);
336 return (success && r_targetpath[0]);
356 len = wcslen(tmp_16);
360 tmp_16[
len - 1] =
'\0';
366 if ((
len >= 3) && (tmp_16[0] ==
L'\\') && (tmp_16[1] ==
L'\\')) {
367 BLI_path_normalize_unc_16(tmp_16);
370 if ((tmp_16[1] ==
L':') && (tmp_16[2] ==
L'\0')) {
375 res = BLI_wstat(tmp_16, &st);
384 if (stat(path, &st)) {
394 # if defined(_MSC_VER)
395 return _fstat64(fd,
buffer);
397 return _fstat(fd,
buffer);
406 r = BLI_wstat(path_16,
buffer);
414 # if defined(_MSC_VER)
415 return _wstat64(path,
buffer);
417 return _wstat(path,
buffer);
428 return stat(path,
buffer);
447 return (mode && !
S_ISDIR(mode));
454 bool read_size_exact,
477 void *mem =
MEM_mallocN(filelen + pad_bytes, __func__);
482 const long int filelen_read = fread(mem, 1, filelen, fp);
483 if ((filelen_read < 0) || ferror(fp)) {
488 if (read_size_exact) {
489 if (filelen_read != filelen) {
495 if (filelen_read < filelen) {
503 *r_size = filelen_read;
558 bool trim_trailing_space,
564 char *mem_end = mem + *r_size;
565 if (pad_bytes != 0) {
568 for (
char *p = mem, *p_next; p != mem_end; p = p_next) {
569 p_next = memchr(p,
'\n', mem_end - p);
570 if (p_next !=
NULL) {
571 if (trim_trailing_space) {
572 for (
char *p_trim = p_next - 1; p_trim > p &&
ELEM(*p_trim,
' ',
'\t'); p_trim--) {
620 for (i = 0; i <=
size; i++) {
621 if (i ==
size || buf[i] ==
'\n') {
648 struct _stat st1, st2;
653 if (_wstat(file1_16, &st1)) {
656 if (_wstat(file2_16, &st2)) {
663 struct stat st1, st2;
665 if (stat(file1, &st1)) {
668 if (stat(file2, &st2)) {
672 return (st1.st_mtime < st2.st_mtime);
File and directory operations.
@ FILE_ATTR_REPARSE_POINT
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
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)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check(const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
const char * BLI_getenv(const char *env) ATTR_NONNULL(1)
char * BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Compatibility-like things for windows.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
eFileAttributes BLI_file_attributes(const char *path)
int BLI_exists(const char *path)
void * BLI_file_read_binary_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
bool BLI_file_older(const char *file1, const char *file2)
void BLI_file_free_lines(LinkNode *lines)
bool BLI_is_dir(const char *file)
int BLI_fstat(int fd, struct stat *buffer)
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
bool BLI_file_alias_target(const char *filepath, char r_targetpath[FILE_MAXDIR])
int BLI_stat(const char *path, struct stat *buffer)
size_t BLI_file_descriptor_size(int file)
int64_t BLI_lseek(int fd, int64_t offset, int whence)
char * BLI_current_working_dir(char *dir, const size_t maxncpy)
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)
double BLI_dir_free_space(const char *dir)
size_t BLI_file_size(const char *path)
LinkNode * BLI_file_read_as_lines(const char *filepath)
int BLI_fseek(FILE *stream, int64_t offset, int whence)
static void * file_read_data_as_mem_impl(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)