Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_blenlib.h2
-rw-r--r--source/blender/blenlib/BLI_edgehash.h2
-rw-r--r--source/blender/blenlib/BLI_fileops.h58
-rw-r--r--source/blender/blenlib/BLI_fileops_types.h (renamed from source/blender/blenlib/BLI_storage_types.h)9
-rw-r--r--source/blender/blenlib/BLI_mempool.h2
-rw-r--r--source/blender/blenlib/BLI_scanfill.h2
-rw-r--r--source/blender/blenlib/BLI_storage.h71
-rw-r--r--source/blender/blenlib/CMakeLists.txt3
-rw-r--r--source/blender/blenlib/intern/fileops.c47
-rw-r--r--source/blender/blenlib/intern/path_util.c12
-rw-r--r--source/blender/blenlib/intern/storage.c31
11 files changed, 102 insertions, 137 deletions
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h
index a5c0e03c09e..356709d5ccd 100644
--- a/source/blender/blenlib/BLI_blenlib.h
+++ b/source/blender/blenlib/BLI_blenlib.h
@@ -76,8 +76,6 @@ extern "C" {
#include "BLI_path_util.h"
-#include "BLI_storage.h"
-
#include "BLI_fileops.h"
#include "BLI_rect.h"
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h
index fba13035f02..23ffdbae59b 100644
--- a/source/blender/blenlib/BLI_edgehash.h
+++ b/source/blender/blenlib/BLI_edgehash.h
@@ -30,7 +30,7 @@
#ifndef BLI_EDGEHASH_H
#define BLI_EDGEHASH_H
-/** \file BLI_storage.h
+/** \file BLI_edgehash.h
* \ingroup bli
* \author Daniel Dunbar
* \brief A general unordered 2-int pair hash table ADT.
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 354931e306a..ebe231e2973 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -29,10 +29,7 @@
/** \file BLI_fileops.h
* \ingroup bli
- * \author Daniel Dunbar
- * \brief More low-level fileops from Daniel Dunbar. Two functions were also
- * defined in storage.c. These are the old fop_ prefixes. There is
- * definitely some redundancy here!
+ * \brief File and directory operations.
* */
#ifndef BLI_FILEOPS_H
@@ -42,17 +39,48 @@
extern "C" {
#endif
-void BLI_recurdir_fileops(const char *dirname);
-int BLI_link(const char *file, const char *to);
-int BLI_is_writable(const char *filename);
-
-int BLI_copy_fileops(const char *file, const char *to);
-int BLI_rename(const char *from, const char *to);
-int BLI_gzip(const char *from, const char *to);
-char *BLI_ungzip_to_mem(const char *from_file, int *size_r);
-int BLI_delete(const char *file, int dir, int recursive);
-int BLI_move(const char *file, const char *to);
-int BLI_touch(const char *file);
+#include "BLI_fileops_types.h"
+
+/* for size_t (needed on windows) */
+#include <stddef.h>
+
+/* Common */
+
+int BLI_exists(const char *path);
+int BLI_copy(const char *path, const char *to);
+int BLI_rename(const char *from, const char *to);
+int BLI_delete(const char *path, int dir, int recursive);
+int BLI_move(const char *path, const char *to);
+int BLI_create_symlink(const char *path, const char *to);
+
+/* Directories */
+
+struct direntry;
+
+int BLI_is_dir(const char *path);
+void BLI_dir_create_recursive(const char *dir);
+double BLI_dir_free_space(const char *dir);
+char *BLI_current_working_dir(char *dir, const int maxlen);
+
+unsigned int BLI_dir_contents(const char *dir, struct direntry **filelist);
+
+/* Files */
+
+int BLI_file_is_writable(const char *file);
+int BLI_file_touch(const char *file);
+
+int BLI_file_gzip(const char *from, const char *to);
+char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r);
+
+size_t BLI_file_descriptor_size(int file);
+size_t BLI_file_size(const char *file);
+
+ /* compare if one was last modified before the other */
+int BLI_file_older(const char *file1, const char *file2);
+
+ /* read ascii file as lines, empty list if reading fails */
+struct LinkNode *BLI_file_read_as_lines(const char *file);
+void BLI_file_free_lines(struct LinkNode *lines);
#ifdef __cplusplus
}
diff --git a/source/blender/blenlib/BLI_storage_types.h b/source/blender/blenlib/BLI_fileops_types.h
index 07c0ceffeb5..58dcf1a5441 100644
--- a/source/blender/blenlib/BLI_storage_types.h
+++ b/source/blender/blenlib/BLI_fileops_types.h
@@ -26,10 +26,11 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef BLI_STORAGE_TYPES_H
-#define BLI_STORAGE_TYPES_H
-/** \file BLI_storage_types.h
+#ifndef BLI_FILEOPS_TYPES_H
+#define BLI_FILEOPS_TYPES_H
+
+/** \file BLI_fileops_types.h
* \ingroup bli
* \brief Some types for dealing with directories.
*/
@@ -75,5 +76,5 @@ struct dirlink
char *name;
};
-#endif /* BLI_STORAGE_TYPES_H */
+#endif /* BLI_FILEOPS_TYPES_H */
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 4ea48929efb..56df71b5582 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -29,7 +29,7 @@
#ifndef BLI_MEMPOOL_H
#define BLI_MEMPOOL_H
-/** \file BLI_storage.h
+/** \file BLI_mempool.h
* \ingroup bli
* \author Geoffrey Bantle
* \brief Simple fast memory allocator.
diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h
index c5acf7b7f70..3cc6ebcc7da 100644
--- a/source/blender/blenlib/BLI_scanfill.h
+++ b/source/blender/blenlib/BLI_scanfill.h
@@ -30,7 +30,7 @@
#ifndef BLI_SCANFILL_H
#define BLI_SCANFILL_H
-/** \file BLI_storage.h
+/** \file BLI_scanfill.h
* \ingroup bli
* \since March 2001
* \author nzc
diff --git a/source/blender/blenlib/BLI_storage.h b/source/blender/blenlib/BLI_storage.h
deleted file mode 100644
index 13c78b711a8..00000000000
--- a/source/blender/blenlib/BLI_storage.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef BLI_STORAGE_H
-#define BLI_STORAGE_H
-
-/** \file BLI_storage.h
- * \ingroup bli
- */
-
-/* for size_t (needed on windows) */
-#include <stddef.h>
-
-struct direntry;
-
-size_t BLI_filesize(int file);
-size_t BLI_filepathsize(const char *path);
-double BLI_diskfree(const char *dir);
-char *BLI_getwdN(char *dir, const int maxncpy);
-
-unsigned int BLI_getdir(const char *dirname, struct direntry **filelist);
-
- /* test if file or directory exists */
-int BLI_exists(const char *name);
- /* test if there is a directory at the specified path */
-int BLI_is_dir(const char *file);
-
-/**
- * Read a file as ASCII lines. An empty list is
- * returned if the file cannot be opened or read.
- *
- * @attention The returned list should be free'd with
- * BLI_free_file_lines.
- *
- * @param name The name of the file to read.
- * @retval A list of strings representing the file lines.
- */
-
-struct LinkNode *BLI_read_file_as_lines(const char *name);
-void BLI_free_file_lines(struct LinkNode *lines);
-
- /* Compare if one was last modified before the other */
-int BLI_file_older(const char *file1, const char *file2);
-
-#endif /* BLI_STORAGE_H */
-
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index ea9f72c19c3..49d849bdf14 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -99,6 +99,7 @@ set(SRC
BLI_edgehash.h
BLI_editVert.h
BLI_fileops.h
+ BLI_fileops_types.h
BLI_fnmatch.h
BLI_ghash.h
BLI_graph.h
@@ -125,8 +126,6 @@ set(SRC
BLI_rand.h
BLI_rect.h
BLI_scanfill.h
- BLI_storage.h
- BLI_storage_types.h
BLI_string.h
BLI_string_utf8.h
BLI_threads.h
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 3a2efbd6feb..fef102d8267 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -65,7 +65,8 @@
return -1 if zlib fails, -2 if the originating file does not exist
note: will remove the "from" file
*/
-int BLI_gzip(const char *from, const char *to) {
+int BLI_file_gzip(const char *from, const char *to)
+{
char buffer[10240];
int file;
int readsize = 0;
@@ -109,7 +110,7 @@ int BLI_gzip(const char *from, const char *to) {
/* gzip the file in from_file and write it to memery to_mem, at most size bytes.
return the unziped size
*/
-char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
+char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r)
{
gzFile gzfile;
int readsize, size, alloc_size=0;
@@ -150,7 +151,7 @@ char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
/* return 1 when file can be written */
-int BLI_is_writable(const char *filename)
+int BLI_file_is_writable(const char *filename)
{
int file;
@@ -178,7 +179,7 @@ int BLI_is_writable(const char *filename)
}
}
-int BLI_touch(const char *file)
+int BLI_file_touch(const char *file)
{
FILE *f = fopen(file,"r+b");
if (f != NULL) {
@@ -199,7 +200,8 @@ int BLI_touch(const char *file)
static char str[MAXPATHLEN+12];
-int BLI_delete(const char *file, int dir, int recursive) {
+int BLI_delete(const char *file, int dir, int recursive)
+{
int err;
if (recursive) {
@@ -216,7 +218,8 @@ int BLI_delete(const char *file, int dir, int recursive) {
return err;
}
-int BLI_move(const char *file, const char *to) {
+int BLI_move(const char *file, const char *to)
+{
int err;
// windows doesn't support moveing to a directory
@@ -241,7 +244,8 @@ int BLI_move(const char *file, const char *to) {
}
-int BLI_copy_fileops(const char *file, const char *to) {
+int BLI_copy(const char *file, const char *to)
+{
int err;
// windows doesn't support copying to a directory
@@ -266,14 +270,16 @@ int BLI_copy_fileops(const char *file, const char *to) {
return err;
}
-int BLI_link(const char *file, const char *to) {
+int BLI_create_symlink(const char *file, const char *to)
+{
callLocalErrorCallBack("Linking files is unsupported on Windows");
(void)file;
(void)to;
return 1;
}
-void BLI_recurdir_fileops(const char *dirname) {
+void BLI_dir_create_recursive(const char *dirname)
+{
char *lslash;
char tmp[MAXPATHLEN];
@@ -295,7 +301,7 @@ void BLI_recurdir_fileops(const char *dirname) {
if (lslash) {
/* Split about the last slash and recurse */
*lslash = 0;
- BLI_recurdir_fileops(tmp);
+ BLI_dir_create_recursive(tmp);
}
if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */
@@ -303,7 +309,8 @@ void BLI_recurdir_fileops(const char *dirname) {
callLocalErrorCallBack("Unable to create directory\n");
}
-int BLI_rename(const char *from, const char *to) {
+int BLI_rename(const char *from, const char *to)
+{
if (!BLI_exists(from)) return 0;
/* make sure the filenames are different (case insensitive) before removing */
@@ -343,25 +350,29 @@ int BLI_delete(const char *file, int dir, int recursive)
return -1;
}
-int BLI_move(const char *file, const char *to) {
+int BLI_move(const char *file, const char *to)
+{
BLI_snprintf(str, sizeof(str), "/bin/mv -f \"%s\" \"%s\"", file, to);
return system(str);
}
-int BLI_copy_fileops(const char *file, const char *to) {
+int BLI_copy(const char *file, const char *to)
+{
BLI_snprintf(str, sizeof(str), "/bin/cp -rf \"%s\" \"%s\"", file, to);
return system(str);
}
-int BLI_link(const char *file, const char *to) {
+int BLI_create_symlink(const char *file, const char *to)
+{
BLI_snprintf(str, sizeof(str), "/bin/ln -f \"%s\" \"%s\"", file, to);
return system(str);
}
-void BLI_recurdir_fileops(const char *dirname) {
+void BLI_dir_create_recursive(const char *dirname)
+{
char *lslash;
char tmp[MAXPATHLEN];
@@ -373,13 +384,14 @@ void BLI_recurdir_fileops(const char *dirname) {
if (lslash) {
/* Split about the last slash and recurse */
*lslash = 0;
- BLI_recurdir_fileops(tmp);
+ BLI_dir_create_recursive(tmp);
}
mkdir(dirname, 0777);
}
-int BLI_rename(const char *from, const char *to) {
+int BLI_rename(const char *from, const char *to)
+{
if (!BLI_exists(from)) return 0;
if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1;
@@ -388,3 +400,4 @@ int BLI_rename(const char *from, const char *to) {
}
#endif
+
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 91e813a0350..d9176c5f162 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -46,8 +46,6 @@
#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
-#include "BLI_storage.h"
-#include "BLI_storage_types.h"
#include "BLI_utildefines.h"
#include "BKE_utildefines.h"
@@ -740,7 +738,7 @@ int BLI_path_cwd(char *path)
if (wasrelative==1) {
char cwd[FILE_MAXDIR + FILE_MAXFILE]= "";
- BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */
+ BLI_current_working_dir(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */
if (cwd[0] == '\0') {
printf( "Could not get the current working directory - $PWD for an unknown reason.");
@@ -986,7 +984,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
}
/* try CWD/release/folder_name */
- if(BLI_getwdN(cwd, sizeof(cwd))) {
+ if(BLI_current_working_dir(cwd, sizeof(cwd))) {
if(test_path(targetpath, cwd, "release", relfolder)) {
return 1;
}
@@ -1117,7 +1115,7 @@ char *BLI_get_folder_create(int folder_id, const char *subfolder)
if (!path) {
path = BLI_get_user_folder_notest(folder_id, subfolder);
- if (path) BLI_recurdir_fileops(path);
+ if (path) BLI_dir_create_recursive(path);
}
return path;
@@ -1250,7 +1248,7 @@ void BLI_make_existing_file(const char *name)
/* test exist */
if (BLI_exists(di) == 0) {
- BLI_recurdir_fileops(di);
+ BLI_dir_create_recursive(di);
}
}
@@ -1732,7 +1730,7 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name
BLI_strncpy(fullname, name, maxlen);
if (name[0] == '.') {
char wdir[FILE_MAX]= "";
- BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */
+ BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */
// not needed but avoids annoying /./ in name
if(name[1]==SEP)
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 8b383f5fd11..b3caeb71822 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -88,10 +88,9 @@
#include "DNA_listBase.h"
+#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_linklist.h"
-#include "BLI_storage.h"
-#include "BLI_storage_types.h"
#include "BLI_string.h"
#include "BKE_utildefines.h"
@@ -104,7 +103,7 @@ static struct ListBase dirbase_={NULL, NULL};
static struct ListBase *dirbase = &dirbase_;
/* can return NULL when the size is not big enough */
-char *BLI_getwdN(char *dir, const int maxncpy)
+char *BLI_current_working_dir(char *dir, const int maxncpy)
{
const char *pwd= getenv("PWD");
if (pwd){
@@ -116,7 +115,7 @@ char *BLI_getwdN(char *dir, const int maxncpy)
}
-int BLI_compare(struct direntry *entry1, struct direntry *entry2)
+static int bli_compare(struct direntry *entry1, struct direntry *entry2)
{
/* type is equal to stat.st_mode */
@@ -143,7 +142,7 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2)
}
-double BLI_diskfree(const char *dir)
+double BLI_dir_free_space(const char *dir)
{
#ifdef WIN32
DWORD sectorspc, bytesps, freec, clusters;
@@ -198,7 +197,7 @@ double BLI_diskfree(const char *dir)
#endif
}
-void BLI_builddir(const char *dirname, const char *relname)
+static void bli_builddir(const char *dirname, const char *relname)
{
struct dirent *fname;
struct dirlink *dlink;
@@ -273,7 +272,7 @@ void BLI_builddir(const char *dirname, const char *relname)
}
BLI_freelist(dirbase);
- if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))BLI_compare);
+ if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))bli_compare);
} else {
printf("%s empty directory\n",dirname);
}
@@ -284,7 +283,7 @@ void BLI_builddir(const char *dirname, const char *relname)
}
}
-void BLI_adddirstrings(void)
+static void bli_adddirstrings(void)
{
char datum[100];
char buf[512];
@@ -392,7 +391,7 @@ void BLI_adddirstrings(void)
}
}
-unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
+unsigned int BLI_dir_contents(const char *dirname, struct direntry **filelist)
{
// reset global variables
// memory stored in files is free()'d in
@@ -401,8 +400,8 @@ unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
actnum = totnum = 0;
files = NULL;
- BLI_builddir(dirname,"");
- BLI_adddirstrings();
+ bli_builddir(dirname,"");
+ bli_adddirstrings();
if (files) {
*(filelist) = files;
@@ -416,7 +415,7 @@ unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
}
-size_t BLI_filesize(int file)
+size_t BLI_file_descriptor_size(int file)
{
struct stat buf;
@@ -425,14 +424,14 @@ size_t BLI_filesize(int file)
return (buf.st_size);
}
-size_t BLI_filepathsize(const char *path)
+size_t BLI_file_size(const char *path)
{
int size, file = open(path, O_BINARY|O_RDONLY);
if (file == -1)
return -1;
- size = BLI_filesize(file);
+ size = BLI_file_descriptor_size(file);
close(file);
return size;
}
@@ -474,7 +473,7 @@ int BLI_is_dir(const char *file)
return S_ISDIR(BLI_exists(file));
}
-LinkNode *BLI_read_file_as_lines(const char *name)
+LinkNode *BLI_file_read_as_lines(const char *name)
{
FILE *fp= fopen(name, "r");
LinkNode *lines= NULL;
@@ -515,7 +514,7 @@ LinkNode *BLI_read_file_as_lines(const char *name)
return lines;
}
-void BLI_free_file_lines(LinkNode *lines)
+void BLI_file_free_lines(LinkNode *lines)
{
BLI_linklist_free(lines, (void(*)(void*)) MEM_freeN);
}