12 #include <sys/types.h>
16 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__HAIKU__)
18 # include <sys/statvfs.h>
19 # define USE_STATFS_STATVFS
22 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
23 defined(__DragonFly__)
25 # include <sys/mount.h>
26 # include <sys/param.h>
29 #if defined(__linux__) || defined(__hpux) || defined(__GNU__) || defined(__GLIBC__)
40 # include <ShObjIdl.h>
46 # include <sys/ioctl.h>
62 wchar_t path[MAX_PATH];
63 if (_wgetcwd(path, MAX_PATH)) {
73 if (srclen != maxncpy) {
74 memcpy(dir, pwd, srclen + 1);
79 return getcwd(dir, maxncpy);
86 DWORD sectorspc, bytesps, freec, clusters;
91 if (
ELEM(dir[0],
'/',
'\\')) {
95 else if (dir[1] ==
':') {
102 GetDiskFreeSpace(tmp, §orspc, &bytesps, &freec, &clusters);
104 return (
double)(freec * bytesps * sectorspc);
107 # ifdef USE_STATFS_STATVFS
114 int len = strlen(dir);
124 slash = strrchr(name,
'/');
133 # if defined(USE_STATFS_STATVFS)
134 if (statvfs(name, &disk)) {
137 # elif defined(USE_STATFS_4ARGS)
138 if (statfs(name, &disk,
sizeof(
struct statfs), 0)) {
142 if (statfs(name, &disk)) {
147 return (((
double)disk.f_bsize) * ((
double)disk.f_bfree));
154 return _ftelli64(stream);
156 return ftell(stream);
163 return _fseeki64(stream,
offset, whence);
165 return fseek(stream,
offset, whence);
172 return _lseeki64(fd,
offset, whence);
174 return lseek(fd,
offset, whence);
193 return stats.st_size;
212 DWORD attr = GetFileAttributesW(wline);
213 if (attr & FILE_ATTRIBUTE_READONLY) {
216 if (attr & FILE_ATTRIBUTE_HIDDEN) {
219 if (attr & FILE_ATTRIBUTE_SYSTEM) {
222 if (attr & FILE_ATTRIBUTE_ARCHIVE) {
225 if (attr & FILE_ATTRIBUTE_COMPRESSED) {
228 if (attr & FILE_ATTRIBUTE_ENCRYPTED) {
231 if (attr & FILE_ATTRIBUTE_TEMPORARY) {
234 if (attr & FILE_ATTRIBUTE_SPARSE_FILE) {
237 if (attr & FILE_ATTRIBUTE_OFFLINE || attr & FILE_ATTRIBUTE_RECALL_ON_OPEN ||
238 attr & FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS) {
241 if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
271 HRESULT hr = CoInitializeEx(
NULL, COINIT_MULTITHREADED);
276 IShellLinkW *Shortcut =
NULL;
277 hr = CoCreateInstance(
278 &CLSID_ShellLink,
NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID *)&Shortcut);
280 bool success =
false;
282 IPersistFile *PersistFile;
283 hr = Shortcut->lpVtbl->QueryInterface(Shortcut, &IID_IPersistFile, (LPVOID *)&PersistFile);
287 hr = PersistFile->lpVtbl->Load(PersistFile, path_utf16, STGM_READ);
289 hr = Shortcut->lpVtbl->Resolve(Shortcut, 0, SLR_NO_UI | SLR_UPDATE);
292 hr = Shortcut->lpVtbl->GetPath(Shortcut, target_utf16,
FILE_MAXDIR,
NULL, 0);
297 PersistFile->lpVtbl->Release(PersistFile);
301 Shortcut->lpVtbl->Release(Shortcut);
305 return (success && r_targetpath[0]);
321 len = wcslen(tmp_16);
325 tmp_16[
len - 1] =
'\0';
331 if ((
len >= 3) && (tmp_16[0] ==
L'\\') && (tmp_16[1] ==
L'\\')) {
332 BLI_path_normalize_unc_16(tmp_16);
335 if ((tmp_16[1] ==
L':') && (tmp_16[2] ==
L'\0')) {
340 res = BLI_wstat(tmp_16, &
st);
349 if (stat(path, &
st)) {
359 # if defined(_MSC_VER)
360 return _fstat64(fd,
buffer);
362 return _fstat(fd,
buffer);
371 r = BLI_wstat(path_16,
buffer);
379 # if defined(_MSC_VER)
380 return _wstat64(path,
buffer);
382 return _wstat(path,
buffer);
393 return stat(path,
buffer);
405 return (mode && !
S_ISDIR(mode));
412 bool read_size_exact,
435 void *mem =
MEM_mallocN(filelen + pad_bytes, __func__);
440 const long int filelen_read = fread(mem, 1, filelen, fp);
441 if ((filelen_read < 0) || ferror(fp)) {
446 if (read_size_exact) {
447 if (filelen_read != filelen) {
453 if (filelen_read < filelen) {
461 *r_size = filelen_read;
489 bool trim_trailing_space,
495 char *mem_end = mem + *r_size;
496 if (pad_bytes != 0) {
499 for (
char *p = mem, *p_next; p != mem_end; p = p_next) {
500 p_next = memchr(p,
'\n', mem_end - p);
501 if (p_next !=
NULL) {
502 if (trim_trailing_space) {
503 for (
char *p_trim = p_next - 1; p_trim > p &&
ELEM(*p_trim,
' ',
'\t'); p_trim--) {
548 for (i = 0; i <=
size; i++) {
549 if (i ==
size || buf[i] ==
'\n') {
578 return (st1.st_mtime < st2.st_mtime);
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)
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) ATTR_WARN_UNUSED_RESULT
size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, size_t maxncpy) ATTR_NONNULL(1
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)
ccl_global float * buffer
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
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)
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)
bool BLI_file_alias_target(const char *filepath, char r_targetpath[])
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)