2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software 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 Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2003-07-01 20:37:09 +00:00
|
|
|
|
2003-12-24 21:50:41 +00:00
|
|
|
#ifndef _FILESYS_
|
|
|
|
#define _FILESYS_
|
|
|
|
|
2004-12-06 16:03:13 +00:00
|
|
|
/* to allow prototypes using 'bool' in ANSI-C. Note that gcc defines
|
|
|
|
bool as an INT, and MS VC++ up to version 4.2 also does. However
|
|
|
|
more recent versions of MS VC++ define bool as CHAR. */
|
2004-12-04 00:56:22 +00:00
|
|
|
#if (!defined __cplusplus) && (!defined bool)
|
2004-12-06 16:03:13 +00:00
|
|
|
#if ((defined(_MSC_VER)) && (_MSC_VER > 1020))
|
|
|
|
#define bool char
|
|
|
|
#else
|
|
|
|
#define bool int
|
|
|
|
#endif /* defined(_MSC_VER) && (_MSC_VER > 1020) */
|
|
|
|
#endif /* (!defined __cplusplus) && (!defined bool) */
|
2004-12-04 00:56:22 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
2004-12-08 07:38:22 +00:00
|
|
|
typedef struct _DIR_DESC {
|
2004-03-04 11:41:43 +00:00
|
|
|
char path[256];
|
|
|
|
bool first;
|
|
|
|
void* handle;
|
2004-12-08 07:38:22 +00:00
|
|
|
} DIR_DESC;
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
typedef DIR_DESC *DIRREF;
|
|
|
|
#define PATH_SEPARATOR "\\"
|
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dirent.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#ifdef __cplusplus
|
2003-06-24 00:17:36 +00:00
|
|
|
#include <string>
|
2004-12-04 00:56:22 +00:00
|
|
|
#endif
|
2004-01-08 00:27:59 +00:00
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
typedef DIR *DIRREF;
|
2002-08-24 00:41:25 +00:00
|
|
|
#define PATH_SEPARATOR "/"
|
2004-03-04 11:41:43 +00:00
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#endif /* !WIN32 */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2002-07-30 23:44:22 +00:00
|
|
|
#endif
|
2004-12-04 00:56:22 +00:00
|
|
|
extern int boinc_delete_file(const char*);
|
|
|
|
extern int clean_out_dir(const char*);
|
|
|
|
extern FILE* boinc_fopen(const char* path, const char* mode);
|
|
|
|
extern int boinc_copy(const char* orig, const char* newf);
|
|
|
|
extern int boinc_rename(const char* old, const char* newf);
|
|
|
|
extern int boinc_mkdir(const char*);
|
|
|
|
extern int boinc_rmdir(const char*);
|
|
|
|
extern int lock_file(char*);
|
|
|
|
extern void relative_to_absolute(char* relname, char* path);
|
|
|
|
extern int boinc_make_dirs(char*, char*);
|
|
|
|
extern char boinc_failed_file[256];
|
2005-01-19 17:53:27 +00:00
|
|
|
int is_dir(const char* path);
|
2004-12-04 00:56:22 +00:00
|
|
|
|
|
|
|
/* we suitably defined 'bool' as 'int' in ANSI-C */
|
|
|
|
extern bool boinc_file_exists(const char* path);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* C++ specific prototypes/defines follow here */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern int file_size(const char*, double&);
|
|
|
|
extern int dir_size(const char* dirpath, double&);
|
|
|
|
extern int get_filesystem_info(double& total, double& free);
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-01-08 00:27:59 +00:00
|
|
|
// TODO TODO TODO
|
|
|
|
// remove this code - the DirScanner class does the same thing.
|
|
|
|
// But need to rewrite a couple of places that use it
|
|
|
|
//
|
2003-11-08 00:56:55 +00:00
|
|
|
extern DIRREF dir_open(const char*);
|
2003-03-11 00:49:07 +00:00
|
|
|
extern int dir_scan(char*, DIRREF, int);
|
2004-06-30 18:17:21 +00:00
|
|
|
int dir_scan(std::string&, DIRREF);
|
2002-08-09 21:43:19 +00:00
|
|
|
extern void dir_close(DIRREF);
|
2004-01-08 00:27:59 +00:00
|
|
|
|
2003-06-24 00:17:36 +00:00
|
|
|
|
|
|
|
class DirScanner {
|
|
|
|
#ifdef _WIN32
|
2004-10-19 06:29:26 +00:00
|
|
|
std::string dir;
|
2003-06-24 00:17:36 +00:00
|
|
|
bool first;
|
|
|
|
void* handle;
|
2004-10-19 06:29:26 +00:00
|
|
|
#else
|
2003-06-24 00:17:36 +00:00
|
|
|
DIR* dirp;
|
|
|
|
#endif
|
|
|
|
public:
|
2004-06-30 18:17:21 +00:00
|
|
|
DirScanner(std::string const& path);
|
2003-06-24 00:17:36 +00:00
|
|
|
~DirScanner();
|
2004-06-30 18:17:21 +00:00
|
|
|
bool scan(std::string& name); // return true if file returned
|
2003-06-24 00:17:36 +00:00
|
|
|
};
|
2003-12-24 21:50:41 +00:00
|
|
|
|
2004-12-10 19:17:32 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
// search PATH, find the directory that a program is in, if any
|
|
|
|
//
|
|
|
|
extern int get_file_dir(char* filename, char* dir);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#endif /* c++ */
|
|
|
|
|
|
|
|
#endif /* double-inclusion protection */
|
2004-01-04 06:48:40 +00:00
|
|
|
|