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_
|
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
2004-03-04 11:41:43 +00:00
|
|
|
|
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;
|
|
|
|
|
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;
|
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*);
|
2005-06-27 16:31:49 +00:00
|
|
|
extern int boinc_touch_file(const char *path);
|
2004-12-04 00:56:22 +00:00
|
|
|
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*);
|
2005-02-16 23:17:43 +00:00
|
|
|
extern void relative_to_absolute(const char* relname, char* path);
|
2004-12-04 00:56:22 +00:00
|
|
|
extern int boinc_make_dirs(char*, char*);
|
|
|
|
extern char boinc_failed_file[256];
|
2006-01-18 23:04:05 +00:00
|
|
|
extern int is_file(const char* path);
|
|
|
|
extern int is_dir(const char* path);
|
2006-01-18 22:12:55 +00:00
|
|
|
extern int boinc_truncate(const char*, double);
|
2006-01-18 23:04:05 +00:00
|
|
|
extern int boinc_file_exists(const char* path);
|
2004-12-04 00:56:22 +00:00
|
|
|
|
|
|
|
#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 {
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
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
|
|
|
|
2005-03-05 23:12:31 +00:00
|
|
|
struct FILE_LOCK {
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
2005-03-05 23:12:31 +00:00
|
|
|
HANDLE handle;
|
|
|
|
#else
|
|
|
|
int fd;
|
|
|
|
#endif
|
|
|
|
int lock(const char* filename);
|
|
|
|
int unlock(const char* filename);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|