[Bf-blender-cvs] [eca22d0] master: Cleanup: move filelist out of storage

Campbell Barton noreply at git.blender.org
Sat Apr 4 08:21:30 CEST 2015


Commit: eca22d076cb8a90d02f0ce0424d4333e2b6c2773
Author: Campbell Barton
Date:   Sat Apr 4 17:15:33 2015 +1100
Branches: master
https://developer.blender.org/rBeca22d076cb8a90d02f0ce0424d4333e2b6c2773

Cleanup: move filelist out of storage

Depends on imbuf, problematic for tests

===================================================================

M	source/blender/blenlib/CMakeLists.txt
A	source/blender/blenlib/intern/BLI_filelist.c
M	source/blender/blenlib/intern/storage.c

===================================================================

diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index eceec2a..73bd486 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -44,6 +44,7 @@ set(SRC
 	intern/BLI_array.c
 	intern/BLI_dial.c
 	intern/BLI_dynstr.c
+	intern/BLI_filelist.c
 	intern/BLI_ghash.c
 	intern/BLI_heap.c
 	intern/BLI_kdopbvh.c
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/BLI_filelist.c
similarity index 57%
copy from source/blender/blenlib/intern/storage.c
copy to source/blender/blenlib/intern/BLI_filelist.c
index 46c5a11..f032b75 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -15,19 +15,10 @@
  * 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 *****
- * Reorganised mar-01 nzc
- * Some really low-level file thingies.
  */
 
-/** \file blender/blenlib/intern/storage.c
+/** \file blender/blenlib/intern/filelist.c
  *  \ingroup bli
  */
 
@@ -41,28 +32,6 @@
 
 #include <time.h>
 #include <sys/stat.h>
-
-#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__sun)
-   /* Other modern unix os's should probably use this also */
-#  include <sys/statvfs.h>
-#  define USE_STATFS_STATVFS
-#elif (defined(__sparc) || defined(__sparc__)) && !defined(__FreeBSD__) && !defined(__linux__)
-#  include <sys/statfs.h>
-   /* 4 argument version (not common) */
-#  define USE_STATFS_4ARGS
-#endif
-
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
-   /* For statfs */
-#  include <sys/param.h>
-#  include <sys/mount.h>
-#endif
-
-#if defined(__linux__) || defined(__hpux) || defined(__GNU__) || defined(__GLIBC__)
-#  include <sys/vfs.h>
-#endif
-
-#include <fcntl.h>
 #include <string.h>  /* strcpy etc.. */
 
 #ifdef WIN32
@@ -82,7 +51,6 @@
 #include "DNA_listBase.h"
 
 #include "BLI_listbase.h"
-#include "BLI_linklist.h"
 #include "BLI_string.h"
 #include "BLI_fileops.h"
 #include "BLI_fileops_types.h"
@@ -90,22 +58,6 @@
 
 #include "../imbuf/IMB_imbuf.h"
 
-/**
- * Copies the current working directory into *dir (max size maxncpy), and
- * returns a pointer to same.
- *
- * \note can return NULL when the size is not big enough
- */
-char *BLI_current_working_dir(char *dir, const size_t maxncpy)
-{
-	const char *pwd = getenv("PWD");
-	if (pwd) {
-		BLI_strncpy(dir, pwd, maxncpy);
-		return dir;
-	}
-
-	return getcwd(dir, maxncpy);
-}
 
 /*
  * Ordering function for sorting lists of files/directories. Returns -1 if
@@ -143,66 +95,6 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2)
 	return (BLI_natstrcmp(entry1->relname, entry2->relname));
 }
 
-/**
- * Returns the number of free bytes on the volume containing the specified pathname. */
-/* Not actually used anywhere.
- */
-double BLI_dir_free_space(const char *dir)
-{
-#ifdef WIN32
-	DWORD sectorspc, bytesps, freec, clusters;
-	char tmp[4];
-	
-	tmp[0] = '\\'; tmp[1] = 0; /* Just a failsafe */
-	if (dir[0] == '/' || dir[0] == '\\') {
-		tmp[0] = '\\';
-		tmp[1] = 0;
-	}
-	else if (dir[1] == ':') {
-		tmp[0] = dir[0];
-		tmp[1] = ':';
-		tmp[2] = '\\';
-		tmp[3] = 0;
-	}
-
-	GetDiskFreeSpace(tmp, &sectorspc, &bytesps, &freec, &clusters);
-
-	return (double) (freec * bytesps * sectorspc);
-#else
-
-#ifdef USE_STATFS_STATVFS
-	struct statvfs disk;
-#else
-	struct statfs disk;
-#endif
-
-	char name[FILE_MAXDIR], *slash;
-	int len = strlen(dir);
-	
-	if (len >= FILE_MAXDIR) /* path too long */
-		return -1;
-	
-	strcpy(name, dir);
-
-	if (len) {
-		slash = strrchr(name, '/');
-		if (slash) slash[1] = 0;
-	}
-	else {
-		strcpy(name, "/");
-	}
-
-#if  defined(USE_STATFS_STATVFS)
-	if (statvfs(name, &disk)) return -1;
-#elif defined(USE_STATFS_4ARGS)
-	if (statfs(name, &disk, sizeof(struct statfs), 0)) return -1;
-#else
-	if (statfs(name, &disk)) return -1;
-#endif
-
-	return ( ((double) disk.f_bsize) * ((double) disk.f_bfree));
-#endif
-}
 
 struct BuildDirCtx {
 	struct direntry *files; /* array[nrfiles] */
@@ -240,7 +132,7 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
 					dir_ctx->files = NULL;
 				}
 			}
-			
+
 			if (dir_ctx->files == NULL)
 				dir_ctx->files = (struct direntry *)MEM_mallocN(newnum * sizeof(struct direntry), __func__);
 
@@ -298,11 +190,11 @@ static void bli_adddirstrings(struct BuildDirCtx *dir_ctx)
 	off_t st_size;
 	int mode;
 #endif
-	
+
 	struct direntry *file;
 	struct tm *tm;
 	time_t zero = 0;
-	
+
 	for (num = 0, file = dir_ctx->files; num < dir_ctx->nrfiles; num++, file++) {
 
 
@@ -317,7 +209,7 @@ static void bli_adddirstrings(struct BuildDirCtx *dir_ctx)
 		BLI_strncpy(file->mode1, types[(mode & 0700) >> 6], sizeof(file->mode1));
 		BLI_strncpy(file->mode2, types[(mode & 0070) >> 3], sizeof(file->mode2));
 		BLI_strncpy(file->mode3, types[(mode & 0007)],      sizeof(file->mode3));
-		
+
 		if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2] == '-')) file->mode2[2] = 'l';
 
 		if (mode & (S_ISUID | S_ISGID)) {
@@ -464,214 +356,3 @@ void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries, void (
 		MEM_freeN(filelist);
 	}
 }
-
-
-/**
- * Returns the file size of an opened file descriptor.
- */
-size_t BLI_file_descriptor_size(int file)
-{
-	struct stat st;
-	if ((file < 0) || (fstat(file, &st) == -1))
-		return -1;
-	return st.st_size;
-}
-
-/**
- * Returns the size of a file.
- */
-size_t BLI_file_size(const char *path)
-{
-	BLI_stat_t stats;
-	if (BLI_stat(path, &stats) == -1)
-		return -1;
-	return stats.st_size;
-}
-
-/**
- * Returns the st_mode from statting the specified path name, or 0 if it couldn't be statted
- * (most likely doesn't exist or no access).
- */
-int BLI_exists(const char *name)
-{
-#if defined(WIN32) 
-	BLI_stat_t st;
-	wchar_t *tmp_16 = alloc_utf16_from_8(name, 1);
-	int len, res;
-	unsigned int old_error_mode;
-
-	len = wcslen(tmp_16);
-	/* in Windows #stat doesn't recognize dir ending on a slash
-	 * so we remove it here */
-	if (len > 3 && (tmp_16[len - 1] == L'\\' || tmp_16[len - 1] == L'/')) {
-		tmp_16[len - 1] = '\0';
-	}
-	/* two special cases where the trailing slash is needed:
-	 * 1. after the share part of a UNC path
-	 * 2. after the C:\ when the path is the volume only
-	 */
-	if ((len >= 3) && (tmp_16[0] ==  L'\\') && (tmp_16[1] ==  L'\\')) {
-		BLI_cleanup_unc_16(tmp_16);
-	}
-
-	if ((tmp_16[1] ==  L':') && (tmp_16[2] ==  L'\0')) {
-		tmp_16[2] = L'\\';
-		tmp_16[3] = L'\0';
-	}
-
-
-	/* change error mode so user does not get a "no disk in drive" popup
-	 * when looking for a file on an empty CD/DVD drive */
-	old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
-
-	res = BLI_wstat(tmp_16, &st);
-
-	SetErrorMode(old_error_mode);
-
-	free(tmp_16);
-	if (res == -1) return(0);
-#else
-	struct stat st;
-	BLI_assert(name);
-	if (stat(name, &st)) return(0);
-#endif
-	return(st.st_mode);
-}
-
-
-#ifdef WIN32
-int BLI_stat(const char *path, BLI_stat_t *buffer)
-{
-	int r;
-	UTF16_ENCODE(path);
-
-	r = BLI_wstat(path_16, buffer);
-
-	UTF16_UN_ENCODE(path);
-	return r;
-}
-
-int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer)
-{
-#if defined(_MSC_VER) || defined(__MINGW64__)
-	return _wstat64(path, buffer);
-#elif defined(__MINGW32__)
-	return _wstati64(path, buffer);
-#else
-	return _wstat(path, buffer);
-#endif
-}
-#else
-int BLI_stat(const char *path, struct stat *buffer)
-{
-	return stat(path, buffer);
-}
-#endif
-
-/**
- * Does the specified path point to a directory?
- * \note Would be better in fileops.c except that it needs stat.h so add here
- */
-bool BLI_is_dir(const char *file)
-{
-	return S_ISDIR(BLI_exists(file));
-}
-
-/**
- * Does the specified path point to a non-directory?
- */
-bool BLI_is_file(const char *path)
-{
-	const int mode = BLI_exists(path);
-	return (mode && !S_ISDIR(mode));
-}
-
-/**
- * Reads the contents of a text file and returns the lines in a linked list.
- */
-LinkNode *BLI_file_read_as_lines(const char *name)
-{
-	FILE *fp = BLI_fopen(name, "r");
-	LinkNode *lines = NULL;
-	char *buf;
-	size_t size;
-
-	if (!fp) return NULL;
-		
-	fseek(fp, 0, SEEK_END);
-	size = (size_t)ftell(fp);
-	fseek(fp, 0, SEEK_SET);
-
-	buf = MEM_mallocN(size, "file_as_lines");
-	if (buf) {
-		size_t i, last = 0;
-		
-		/*
-		 * size = because on win32 reading
-		 * all the bytes in the file will return
-		 * less bytes because of crnl changes.
-		 */
-		size = fread(buf, 1, size, fp);
-		for (i = 0; i <= size; i++) {
-			if (i == size || buf[i] == '\n') {
-				char *line = BLI_strdupn(&buf[last], i - last);
-
-				BLI_linklist_prepend(&lines, line);
-				/* faster to build singly-linked list in reverse order */
-				/* alternatively, could process buffer in reverse order so
-				 * list ends up right way round to start with */
-				last = i + 1;
-			}
-		}
-		
-		MEM_freeN(buf);
-	}
-	
-	fclose(fp);
-
-	/* get them the right way round */
-	BLI_linklist_reverse(&lines);
-	return lines;
-}
-
-/*
- * Frees memory from a previous call to BLI_file_read_as_lines.
- */
-void BLI_file_free_lines(LinkNode *lines)
-{
-	BLI_linklist_freeN(lines);
-}
-
-/** is file1 older then file2 */
-bool BLI_file_older(const char *file1, const char *file2)
-{
-#ifdef WIN32
-#ifndef __MINGW32__
-	struct _stat st1, st2;
-#else
-	struct _stati64 st1, st2;
-#endif
-
-	UTF16_ENCODE(file1);
-	UTF16_ENCODE(file2);
-	
-#ifndef __MINGW32__
-	if (_wstat(file1_16, &st1)) return false;
-	if (_wstat(file2_16, &st2)) return false;
-#else
-	if (_wstati64(file1_16, &st1)) return false;
-	if (_wstati64(file2_16, &st2)) return false;
-#endif
-
-
-	UTF16_UN_ENCODE(file2);
-	UTF16_UN_ENCODE(file1);
-#else
-	struct stat st1, st2;
-
-	if (stat(file1, &st1)) return false;
-	if (stat(file2, &st2)) return false;
-#endif
-	return (st1.st_mtime < st2.st_mtime);
-}
-
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/bl

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list