Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/storage.c
| Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | if (statfs(name, &disk)) { | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| # endif | # endif | ||||
| return (((double)disk.f_bsize) * ((double)disk.f_bfree)); | return (((double)disk.f_bsize) * ((double)disk.f_bfree)); | ||||
| #endif | #endif | ||||
| } | } | ||||
| int64_t BLI_ftell(FILE *stream) | |||||
| { | |||||
| #if WIN32 | |||||
| return _ftelli64(stream); | |||||
| #else | |||||
| return ftell(stream); | |||||
| #endif | |||||
| } | |||||
| int BLI_fseek(FILE *stream, int64_t offset, int whence) | |||||
| { | |||||
| #if WIN32 | |||||
| return _fseeki64(stream, offset, whence); | |||||
| #else | |||||
| return fseek(stream, offset, whence); | |||||
| #endif | |||||
| } | |||||
| int64_t BLI_lseek(int fd, int64_t offset, int whence) | |||||
| { | |||||
| #if WIN32 | |||||
| return _lseeki64(fd, offset, whence); | |||||
| #else | |||||
| return lseek(fd, offset, whence); | |||||
| #endif | |||||
| } | |||||
| /** | /** | ||||
| * Returns the file size of an opened file descriptor. | * Returns the file size of an opened file descriptor. | ||||
| */ | */ | ||||
| size_t BLI_file_descriptor_size(int file) | size_t BLI_file_descriptor_size(int file) | ||||
| { | { | ||||
| BLI_stat_t st; | BLI_stat_t st; | ||||
| if ((file < 0) || (BLI_fstat(file, &st) == -1)) { | if ((file < 0) || (BLI_fstat(file, &st) == -1)) { | ||||
| return -1; | return -1; | ||||
| ▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_stat_t st; | BLI_stat_t st; | ||||
| if (BLI_fstat(fileno(fp), &st) == -1) { | if (BLI_fstat(fileno(fp), &st) == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (S_ISDIR(st.st_mode)) { | if (S_ISDIR(st.st_mode)) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (fseek(fp, 0L, SEEK_END) == -1) { | if (BLI_fseek(fp, 0L, SEEK_END) == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Don't use the 'st_size' because it may be the symlink. */ | /* Don't use the 'st_size' because it may be the symlink. */ | ||||
| const long int filelen = ftell(fp); | const long int filelen = BLI_ftell(fp); | ||||
| if (filelen == -1) { | if (filelen == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (fseek(fp, 0L, SEEK_SET) == -1) { | if (BLI_fseek(fp, 0L, SEEK_SET) == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| void *mem = MEM_mallocN(filelen + pad_bytes, __func__); | void *mem = MEM_mallocN(filelen + pad_bytes, __func__); | ||||
| if (mem == NULL) { | if (mem == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | LinkNode *BLI_file_read_as_lines(const char *name) | ||||
| LinkNodePair lines = {NULL, NULL}; | LinkNodePair lines = {NULL, NULL}; | ||||
| char *buf; | char *buf; | ||||
| size_t size; | size_t size; | ||||
| if (!fp) { | if (!fp) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| fseek(fp, 0, SEEK_END); | BLI_fseek(fp, 0, SEEK_END); | ||||
| size = (size_t)ftell(fp); | size = (size_t)BLI_ftell(fp); | ||||
| fseek(fp, 0, SEEK_SET); | BLI_fseek(fp, 0, SEEK_SET); | ||||
| if (UNLIKELY(size == (size_t)-1)) { | if (UNLIKELY(size == (size_t)-1)) { | ||||
| fclose(fp); | fclose(fp); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| buf = MEM_mallocN(size, "file_as_lines"); | buf = MEM_mallocN(size, "file_as_lines"); | ||||
| if (buf) { | if (buf) { | ||||
| ▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines | |||||