~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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Copyright (c) 2008 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
 *
 * Original author: Paul McCullagh (H&G2JCtL)
 * Continued development: Barry Leslie
 *
 * 2007-06-07
 *
 * CORE SYSTEM:
 * A basic directory.
 *
 */

#include "CSConfig.h"

#include <string.h>

#include "CSStrUtil.h"
#include "CSPath.h"
#include "CSDirectory.h"
#include "CSGlobal.h"

/*
 * ---------------------------------------------------------------
 * CORE SYSTEM DIRECTORY
 */

void CSDirectory::print(CSOutputStream *out)
{
	char	buffer[500];
	char	number[50];
	bool	is_dir;
	off64_t	size;
	CSTime	mod_time;
	char	*str_time;

	while (next()) {
		info(&is_dir, &size, &mod_time); 
		if (is_dir)
			cs_strcpy(500, buffer, "D");
		else
			cs_strcpy(500, buffer, "f");
		snprintf(number, 50, "%8llu ", (unsigned long long) size);
		cs_strcat(500, buffer, number);
		str_time = mod_time.getCString();
		cs_strcat(500, buffer, str_time);
		cs_strcat(500, buffer, " ");
		cs_strcat(500, buffer, name());
		out->printLine(buffer);
	}
}

void CSDirectory::deleteEntry()
{
	char path[PATH_MAX];

	enter_();
	
	getEntryPath(path, PATH_MAX);
	
	CSPath *cs_path = CSPath::newPath(path);
	push_(cs_path);
	cs_path->removeFile();
	release_(cs_path);

	exit_();
}

const char *CSDirectory::name()
{
	return entryName();
}

bool CSDirectory::isFile()
{
	return entryIsFile();
}

off64_t CSDirectory::getSize()
{
	char path[PATH_MAX];

	getEntryPath(path, PATH_MAX);
	
	return CSPath::getSize(path);
}

void CSDirectory::info(bool *is_dir, off64_t *size, CSTime *mod_time)
{
	char path[PATH_MAX];

	getEntryPath(path, PATH_MAX);
	
	CSPath::info(path, is_dir, size, mod_time);
}

bool CSDirectory::exists()
{
	CSPath *path;
	bool yup;

	enter_();
	path = CSPath::newPath(RETAIN(sd_path));
	push_(path);
	yup = path->exists();
	release_(path);
	return_(yup);
}

CSDirectory *CSDirectory::newDirectory(CSString *path)
{
	CSDirectory *dir;

	if (!(dir = new CSDirectory())) {
		path->release();
		CSException::throwOSError(CS_CONTEXT, ENOMEM);
	}
	dir->sd_path = path;
	return dir;
}

CSDirectory *CSDirectory::newDirectory(CSPath *path)
{
	CSDirectory *dir;
	enter_();
	
	push_(path);
	dir = newDirectory(RETAIN(path->getString()));
	release_(path);
	return_(dir);
}

CSDirectory *CSDirectory::newDirectory(const char *path)
{
	return newDirectory(CSString::newString(path));
}