2007-03-16 04:12:22 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
* *
|
2009-07-17 14:54:25 -05:00
|
|
|
* Copyright (C) 2007,2008 Øyvind Harboe *
|
2008-07-25 01:54:17 -05:00
|
|
|
* oyvind.harboe@zylin.com *
|
|
|
|
* *
|
2008-09-20 05:50:53 -05:00
|
|
|
* Copyright (C) 2008 by Spencer Oliver *
|
|
|
|
* spen@spen-soft.co.uk *
|
|
|
|
* *
|
2007-03-16 04:12:22 -05:00
|
|
|
* 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., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#ifndef FILEIO_H
|
|
|
|
#define FILEIO_H
|
|
|
|
|
2009-05-12 03:35:17 -05:00
|
|
|
#include "types.h"
|
2007-03-16 04:12:22 -05:00
|
|
|
|
2009-05-12 03:35:17 -05:00
|
|
|
#define FILEIO_MAX_ERROR_STRING (128)
|
2007-03-16 04:12:22 -05:00
|
|
|
|
2007-05-29 06:23:42 -05:00
|
|
|
enum fileio_type
|
2007-03-16 04:12:22 -05:00
|
|
|
{
|
2007-05-29 06:23:42 -05:00
|
|
|
FILEIO_TEXT,
|
|
|
|
FILEIO_BINARY,
|
2007-03-16 04:12:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
enum fileio_access
|
|
|
|
{
|
2009-11-08 00:37:39 -06:00
|
|
|
FILEIO_NONE, /* open without any access (invalid mode) */
|
2007-03-16 04:12:22 -05:00
|
|
|
FILEIO_READ, /* open for reading, position at beginning */
|
|
|
|
FILEIO_WRITE, /* open for writing, position at beginning */
|
|
|
|
FILEIO_READWRITE, /* open for writing, position at beginning, allow reading */
|
|
|
|
FILEIO_APPEND, /* open for writing, position at end */
|
|
|
|
FILEIO_APPENDREAD, /* open for writing, position at end, allow reading */
|
|
|
|
};
|
|
|
|
|
2009-11-13 05:08:29 -06:00
|
|
|
struct fileio {
|
2009-11-13 16:22:21 -06:00
|
|
|
const char *url;
|
|
|
|
ssize_t size;
|
2007-05-29 06:23:42 -05:00
|
|
|
enum fileio_type type;
|
2007-03-16 04:12:22 -05:00
|
|
|
enum fileio_access access;
|
|
|
|
FILE *file;
|
2009-11-13 05:08:29 -06:00
|
|
|
};
|
2007-03-16 04:12:22 -05:00
|
|
|
|
2009-11-13 05:08:29 -06:00
|
|
|
int fileio_open(struct fileio *fileio,
|
2009-11-09 04:47:00 -06:00
|
|
|
const char *url, enum fileio_access access, enum fileio_type type);
|
2009-11-13 05:08:29 -06:00
|
|
|
int fileio_close(struct fileio *fileio);
|
2009-11-09 04:47:00 -06:00
|
|
|
|
2009-11-13 16:44:53 -06:00
|
|
|
int fileio_seek(struct fileio *fileio, size_t position);
|
|
|
|
int fileio_fgets(struct fileio *fileio, size_t size, void *buffer);
|
2009-11-09 04:47:00 -06:00
|
|
|
|
2009-11-13 05:08:29 -06:00
|
|
|
int fileio_read(struct fileio *fileio,
|
2009-11-13 16:44:53 -06:00
|
|
|
size_t size, void *buffer, size_t *size_read);
|
2009-11-13 05:08:29 -06:00
|
|
|
int fileio_write(struct fileio *fileio,
|
2009-11-13 16:44:53 -06:00
|
|
|
size_t size, const void *buffer, size_t *size_written);
|
2009-11-09 04:47:00 -06:00
|
|
|
|
2009-11-13 05:08:29 -06:00
|
|
|
int fileio_read_u32(struct fileio *fileio, uint32_t *data);
|
|
|
|
int fileio_write_u32(struct fileio *fileio, uint32_t data);
|
2008-12-13 06:44:39 -06:00
|
|
|
|
2007-03-16 04:12:22 -05:00
|
|
|
#define ERROR_FILEIO_LOCATION_UNKNOWN (-1200)
|
|
|
|
#define ERROR_FILEIO_NOT_FOUND (-1201)
|
|
|
|
#define ERROR_FILEIO_OPERATION_FAILED (-1202)
|
|
|
|
#define ERROR_FILEIO_ACCESS_NOT_SUPPORTED (-1203)
|
|
|
|
#define ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN (-1204)
|
|
|
|
#define ERROR_FILEIO_OPERATION_NOT_SUPPORTED (-1205)
|
|
|
|
|
|
|
|
#endif /* FILEIO_H */
|