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 *
|
2016-05-16 15:41:00 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2007-03-16 04:12:22 -05:00
|
|
|
***************************************************************************/
|
2012-01-30 08:31:21 -06:00
|
|
|
|
2015-09-21 14:07:46 -05:00
|
|
|
#ifndef OPENOCD_HELPER_FILEIO_H
|
|
|
|
#define OPENOCD_HELPER_FILEIO_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
|
|
|
|
2012-01-30 08:31:21 -06:00
|
|
|
enum fileio_type {
|
2007-05-29 06:23:42 -05:00
|
|
|
FILEIO_TEXT,
|
|
|
|
FILEIO_BINARY,
|
2007-03-16 04:12:22 -05:00
|
|
|
};
|
|
|
|
|
2012-01-30 08:31:21 -06: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 */
|
|
|
|
};
|
|
|
|
|
2015-10-04 10:18:40 -05:00
|
|
|
struct fileio;
|
2007-03-16 04:12:22 -05:00
|
|
|
|
2015-10-04 10:18:40 -05:00
|
|
|
int fileio_open(struct fileio **fileio, const char *url,
|
|
|
|
enum fileio_access access_type, 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);
|
2015-10-02 10:35:15 -05:00
|
|
|
int fileio_size(struct fileio *fileio, size_t *size);
|
2008-12-13 06:44:39 -06:00
|
|
|
|
2012-01-30 08:31:21 -06: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)
|
2007-03-16 04:12:22 -05:00
|
|
|
#define ERROR_FILEIO_OPERATION_NOT_SUPPORTED (-1205)
|
|
|
|
|
2015-09-21 14:07:46 -05:00
|
|
|
#endif /* OPENOCD_HELPER_FILEIO_H */
|