2004-11-14 08:29:32 +00:00
|
|
|
// $Id$
|
|
|
|
//
|
2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2004-03-04 11:41:43 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2004-07-13 13:54:09 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-07-01 20:37:09 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2004-07-13 13:54:09 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
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];
|
|
|
|
|
|
|
|
/* 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-04 00:56:22 +00:00
|
|
|
#endif /* c++ */
|
|
|
|
|
|
|
|
#endif /* double-inclusion protection */
|
2004-01-04 06:48:40 +00:00
|
|
|
|