~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright (C) 2010 PrimeBase Technologies GmbH, Germany
 *
 * PrimeBase Media Stream for MySQL
 *
 * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * Author: Barry Leslie
 *
 * 2010-02-05
 *
 * CORE SYSTEM:
 * Basic system specific file I/O classes.
 * The classes in this header are defined in CSSys_unix.cc and  CSSys_win.cc
 *
 */

#pragma once
#ifndef __CSSYSFILE_H__
#define __CSSYSFILE_H__

#ifdef OS_WINDOWS
#define INVALID_DIR_HANDLE (INVALID_HANDLE_VALUE)
#define INVALID_FILE_HANDLE (INVALID_HANDLE_VALUE)
#else
#include <dirent.h>
#define INVALID_DIR_HANDLE (NULL)
#define INVALID_FILE_HANDLE (-1)
#endif

#include "CSString.h"
#include "CSException.h"
#include "CSTime.h"

class CSSysDir {
public:
	CSSysDir(): 
		sd_path(NULL),
		sd_filter(NULL),
		sd_dir(INVALID_DIR_HANDLE){}
	
	~CSSysDir();
	
	void open();
	void close();
	bool next();

	bool entryIsFile();
	const char *entryName();
	void getEntryPath(char *path, size_t size);
	
	CSString *sd_path;
	
private:
	CSStringBuffer *sd_filter;
#ifdef OS_WINDOWS
	WIN32_FIND_DATAA sd_entry;
	HANDLE sd_dir;
#else
	struct dirent sd_entry;
	DIR *sd_dir;
#endif
};


class CSSysFile {
public:

	static bool isDirNotFound(CSException *e);
	static bool isFileNotFound(CSException *e);
	static bool isDirExists(CSException *e);

CSSysFile(): sf_path(NULL), sf_fh(INVALID_FILE_HANDLE){}

	~CSSysFile(){ sf_close();}
	
	bool fs_isOpen() { return ( sf_fh != INVALID_FILE_HANDLE);}
	
	void sf_open(const char *path, bool readonly, bool create);
	void sf_close();
	
	size_t sf_pread(void *data, size_t size, off64_t offset);
	void sf_pwrite(const void *data, size_t size, off64_t offset);
	
	off64_t sf_getEOF();
	void sf_setEOF(off64_t offset);
	
	void sf_sync();
	
	void sf_lock(bool shared);
	void sf_unlock();
	
private:
	CSString *sf_path;
#ifdef OS_WINDOWS
	HANDLE	sf_fh;
#else
	int		sf_fh;
#endif
	
};

class CSSys {
	public:
	static bool sys_exists(const char *path);
	static void sys_makeDir(const char *path);
	static void sys_removeDir(const char *path);
	static void sys_removeFile(const char *path);
	static void sys_rename(const char *old_path, const char *new_path);
	static void sys_stat(const char *path, bool *is_dir, off64_t *size, CSTime *mod_time);
	static bool sys_isLink(const char *path);
	static void sys_getcwd(char *path, size_t size);
	static void sys_setcwd(const char *path);
	static uint32_t sys_getpid();
	static bool sys_isAlive(uint32_t pid);
};

#endif