1
/* $Id: file.hpp 2394 2008-12-23 17:27:53Z bennylp $ */
3
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJPP_FILE_HPP__
21
#define __PJPP_FILE_HPP__
23
#include <pj/file_io.h>
24
#include <pj/file_access.h>
25
#include <pj++/types.hpp>
26
#include <pj++/pool.hpp>
35
// Check file existance.
37
static bool file_exists(const char *filename)
39
return pj_file_exists(filename) != 0;
45
static pj_off_t file_size(const char *filename)
47
return pj_file_size(filename);
53
static pj_status_t file_delete(const char *filename)
55
return pj_file_delete(filename);
61
static pj_status_t file_move(const char *oldname, const char *newname)
63
return pj_file_move(oldname, newname);
69
static pj_status_t file_stat(const char *filename, pj_file_stat *buf)
71
return pj_file_getstat(filename, buf);
79
class Pj_File : public Pj_Object
83
// Offset type to be used in setpos.
87
PJ_SEEK_SET = PJ_SEEK_SET,
88
PJ_SEEK_CUR = PJ_SEEK_CUR,
89
PJ_SEEK_END = PJ_SEEK_END,
93
// Default constructor.
101
// Construct and open a file.
103
Pj_File(Pj_Pool *pool, const char *filename,
104
unsigned access = PJ_O_RDONLY)
107
open(pool, filename, access);
111
// Destructor closes the file.
121
pj_status_t open(Pj_Pool *pool, const char *filename,
122
unsigned access = PJ_O_RDONLY )
125
return pj_file_open(pool->pool_(), filename, access, &hnd_);
142
pj_ssize_t write(const void *buff, pj_size_t size)
144
pj_ssize_t bytes = size;
145
if (pj_file_write(hnd_, buff, &bytes) != PJ_SUCCESS)
153
pj_ssize_t read(void *buf, pj_size_t size)
155
pj_ssize_t bytes = size;
156
if (pj_file_read(hnd_, buf, &bytes) != PJ_SUCCESS)
162
// Set file position.
164
pj_status_t setpos(pj_off_t offset, Offset_Type whence)
166
return pj_file_setpos(hnd_, offset,
167
(enum pj_file_seek_type)whence);
171
// Get file position.
176
if (pj_file_getpos(hnd_, &pos) != PJ_SUCCESS)
187
#endif /* __PJPP_FILE_HPP__ */