aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llapr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llapr.cpp')
-rw-r--r--linden/indra/llcommon/llapr.cpp174
1 files changed, 166 insertions, 8 deletions
diff --git a/linden/indra/llcommon/llapr.cpp b/linden/indra/llcommon/llapr.cpp
index 665ee75..550a8d8 100644
--- a/linden/indra/llcommon/llapr.cpp
+++ b/linden/indra/llcommon/llapr.cpp
@@ -122,11 +122,13 @@ void ll_apr_assert_status(apr_status_t status)
122 llassert(ll_apr_warn_status(status) == false); 122 llassert(ll_apr_warn_status(status) == false);
123} 123}
124 124
125apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep) 125// File I/O
126apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool)
126{ 127{
127 apr_file_t* apr_file; 128 apr_file_t* apr_file;
128 apr_status_t s; 129 apr_status_t s;
129 s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, gAPRPoolp); 130 if (pool == NULL) pool = gAPRPoolp;
131 s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, pool);
130 if (s != APR_SUCCESS) 132 if (s != APR_SUCCESS)
131 { 133 {
132 if (sizep) 134 if (sizep)
@@ -142,6 +144,7 @@ apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* s
142 apr_off_t offset = 0; 144 apr_off_t offset = 0;
143 if (apr_file_seek(apr_file, APR_END, &offset) == APR_SUCCESS) 145 if (apr_file_seek(apr_file, APR_END, &offset) == APR_SUCCESS)
144 { 146 {
147 llassert_always(offset <= 0x7fffffff);
145 file_size = (S32)offset; 148 file_size = (S32)offset;
146 offset = 0; 149 offset = 0;
147 apr_file_seek(apr_file, APR_SET, &offset); 150 apr_file_seek(apr_file, APR_SET, &offset);
@@ -151,6 +154,18 @@ apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* s
151 154
152 return apr_file; 155 return apr_file;
153} 156}
157apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep)
158{
159 return ll_apr_file_open(filename, flags, sizep, NULL);
160}
161apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, apr_pool_t* pool)
162{
163 return ll_apr_file_open(filename, flags, NULL, pool);
164}
165apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags)
166{
167 return ll_apr_file_open(filename, flags, NULL, NULL);
168}
154 169
155S32 ll_apr_file_read(apr_file_t* apr_file, void *buf, S32 nbytes) 170S32 ll_apr_file_read(apr_file_t* apr_file, void *buf, S32 nbytes)
156{ 171{
@@ -162,10 +177,37 @@ S32 ll_apr_file_read(apr_file_t* apr_file, void *buf, S32 nbytes)
162 } 177 }
163 else 178 else
164 { 179 {
180 llassert_always(sz <= 0x7fffffff);
165 return (S32)sz; 181 return (S32)sz;
166 } 182 }
167} 183}
168 184
185S32 ll_apr_file_read_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes)
186{
187 if (pool == NULL) pool = gAPRPoolp;
188 apr_file_t* filep = ll_apr_file_open(filename, APR_READ|APR_BINARY, pool);
189 if (!filep)
190 {
191 return 0;
192 }
193 S32 off;
194 if (offset < 0)
195 off = ll_apr_file_seek(filep, APR_END, 0);
196 else
197 off = ll_apr_file_seek(filep, APR_SET, offset);
198 S32 bytes_read;
199 if (off < 0)
200 {
201 bytes_read = 0;
202 }
203 else
204 {
205 bytes_read = ll_apr_file_read(filep, buf, nbytes );
206 }
207 apr_file_close(filep);
208
209 return bytes_read;
210}
169 211
170S32 ll_apr_file_write(apr_file_t* apr_file, const void *buf, S32 nbytes) 212S32 ll_apr_file_write(apr_file_t* apr_file, const void *buf, S32 nbytes)
171{ 213{
@@ -177,28 +219,73 @@ S32 ll_apr_file_write(apr_file_t* apr_file, const void *buf, S32 nbytes)
177 } 219 }
178 else 220 else
179 { 221 {
222 llassert_always(sz <= 0x7fffffff);
180 return (S32)sz; 223 return (S32)sz;
181 } 224 }
182} 225}
183 226
227S32 ll_apr_file_write_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes)
228{
229 if (pool == NULL) pool = gAPRPoolp;
230 apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
231 if (offset < 0)
232 {
233 flags |= APR_APPEND;
234 offset = 0;
235 }
236 apr_file_t* filep = ll_apr_file_open(filename, flags, pool);
237 if (!filep)
238 {
239 return 0;
240 }
241 if (offset > 0)
242 {
243 offset = ll_apr_file_seek(filep, APR_SET, offset);
244 }
245 S32 bytes_written;
246 if (offset < 0)
247 {
248 bytes_written = 0;
249 }
250 else
251 {
252 bytes_written = ll_apr_file_write(filep, buf, nbytes );
253 }
254 apr_file_close(filep);
255
256 return bytes_written;
257}
258
184S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset) 259S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset)
185{ 260{
186 apr_off_t apr_offset = offset; 261 apr_status_t s;
187 apr_status_t s = apr_file_seek(apr_file, where, &apr_offset); 262 apr_off_t apr_offset;
263 if (offset >= 0)
264 {
265 apr_offset = (apr_off_t)offset;
266 s = apr_file_seek(apr_file, where, &apr_offset);
267 }
268 else
269 {
270 apr_offset = 0;
271 s = apr_file_seek(apr_file, APR_END, &apr_offset);
272 }
188 if (s != APR_SUCCESS) 273 if (s != APR_SUCCESS)
189 { 274 {
190 return -1; 275 return -1;
191 } 276 }
192 else 277 else
193 { 278 {
279 llassert_always(apr_offset <= 0x7fffffff);
194 return (S32)apr_offset; 280 return (S32)apr_offset;
195 } 281 }
196} 282}
197 283
198bool ll_apr_file_remove(const LLString& filename) 284bool ll_apr_file_remove(const LLString& filename, apr_pool_t* pool)
199{ 285{
200 apr_status_t s; 286 apr_status_t s;
201 s = apr_file_remove(filename.c_str(), gAPRPoolp); 287 if (pool == NULL) pool = gAPRPoolp;
288 s = apr_file_remove(filename.c_str(), pool);
202 if (s != APR_SUCCESS) 289 if (s != APR_SUCCESS)
203 { 290 {
204 llwarns << "ll_apr_file_remove failed on file: " << filename << llendl; 291 llwarns << "ll_apr_file_remove failed on file: " << filename << llendl;
@@ -207,10 +294,11 @@ bool ll_apr_file_remove(const LLString& filename)
207 return true; 294 return true;
208} 295}
209 296
210bool ll_apr_file_rename(const LLString& filename, const LLString& newname) 297bool ll_apr_file_rename(const LLString& filename, const LLString& newname, apr_pool_t* pool)
211{ 298{
212 apr_status_t s; 299 apr_status_t s;
213 s = apr_file_rename(filename.c_str(), newname.c_str(), gAPRPoolp); 300 if (pool == NULL) pool = gAPRPoolp;
301 s = apr_file_rename(filename.c_str(), newname.c_str(), pool);
214 if (s != APR_SUCCESS) 302 if (s != APR_SUCCESS)
215 { 303 {
216 llwarns << "ll_apr_file_rename failed on file: " << filename << llendl; 304 llwarns << "ll_apr_file_rename failed on file: " << filename << llendl;
@@ -218,3 +306,73 @@ bool ll_apr_file_rename(const LLString& filename, const LLString& newname)
218 } 306 }
219 return true; 307 return true;
220} 308}
309
310bool ll_apr_file_exists(const LLString& filename, apr_pool_t* pool)
311{
312 apr_file_t* apr_file;
313 apr_status_t s;
314 if (pool == NULL) pool = gAPRPoolp;
315 s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool);
316 if (s != APR_SUCCESS || !apr_file)
317 {
318 return false;
319 }
320 else
321 {
322 apr_file_close(apr_file);
323 return true;
324 }
325}
326
327S32 ll_apr_file_size(const LLString& filename, apr_pool_t* pool)
328{
329 apr_file_t* apr_file;
330 apr_finfo_t info;
331 apr_status_t s;
332 if (pool == NULL) pool = gAPRPoolp;
333 s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool);
334 if (s != APR_SUCCESS || !apr_file)
335 {
336 return 0;
337 }
338 else
339 {
340 apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file);
341 apr_file_close(apr_file);
342 if (s == APR_SUCCESS)
343 {
344 return (S32)info.size;
345 }
346 else
347 {
348 return 0;
349 }
350 }
351}
352
353bool ll_apr_dir_make(const LLString& dirname, apr_pool_t* pool)
354{
355 apr_status_t s;
356 if (pool == NULL) pool = gAPRPoolp;
357 s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, pool);
358 if (s != APR_SUCCESS)
359 {
360 llwarns << "ll_apr_file_remove failed on file: " << dirname << llendl;
361 return false;
362 }
363 return true;
364}
365
366bool ll_apr_dir_remove(const LLString& dirname, apr_pool_t* pool)
367{
368 apr_status_t s;
369 if (pool == NULL) pool = gAPRPoolp;
370 s = apr_file_remove(dirname.c_str(), pool);
371 if (s != APR_SUCCESS)
372 {
373 llwarns << "ll_apr_file_remove failed on file: " << dirname << llendl;
374 return false;
375 }
376 return true;
377}
378