Michael Bruck: fixed warnings
[fw/openocd] / src / helper / fileio.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef FILEIO_H
21 #define FILEIO_H
22
23 #define FILEIO_MAX_ERROR_STRING         (128)
24
25 #include "types.h"
26
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <errno.h>
33 #include <ctype.h>
34
35 enum fileio_type
36 {
37         FILEIO_TEXT,
38         FILEIO_BINARY,
39 };
40
41
42 enum fileio_access
43 {
44         FILEIO_READ,            /* open for reading, position at beginning */
45         FILEIO_WRITE,           /* open for writing, position at beginning */
46         FILEIO_READWRITE,       /* open for writing, position at beginning, allow reading */
47         FILEIO_APPEND,          /* open for writing, position at end */
48         FILEIO_APPENDREAD,      /* open for writing, position at end, allow reading */
49 };
50
51 typedef struct fileio_s
52 {
53         char *url;
54         long long size;
55         enum fileio_type type;
56         enum fileio_access access;
57         FILE *file;
58 } fileio_t;
59
60 extern int fileio_write(fileio_t *fileio, u32 size, u8 *buffer, u32 *size_written);
61 extern int fileio_read(fileio_t *fileio, u32 size, u8 *buffer, u32 *size_read);
62 extern int fileio_fgets(fileio_t *fileio, u32 size, char *buffer);
63 extern int fileio_seek(fileio_t *fileio, u32 position);
64 extern int fileio_close(fileio_t *fileio);
65 extern int fileio_open(fileio_t *fileio, char *url, enum fileio_access access, enum fileio_type type);
66 extern int fileio_read_u32(fileio_t *fileio, u32 *data);
67 extern int fileio_write_u32(fileio_t *fileio, u32 data);
68         
69 #define ERROR_FILEIO_LOCATION_UNKNOWN   (-1200)
70 #define ERROR_FILEIO_NOT_FOUND                  (-1201)
71 #define ERROR_FILEIO_OPERATION_FAILED           (-1202)
72 #define ERROR_FILEIO_ACCESS_NOT_SUPPORTED       (-1203)
73 #define ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN      (-1204)
74 #define ERROR_FILEIO_OPERATION_NOT_SUPPORTED    (-1205)
75
76 #endif /* FILEIO_H */