]> git.sur5r.net Git - openocd/blob - src/helper/fileio.h
- fixed endianness helper macros (thanks to obilix and wiml for finding and fixing...
[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 enum fileio_location
42 {
43         FILEIO_LOCAL,
44 /*
45  * Possible future enhancements:
46  * FILEIO_NFS,
47  * FILEIO_BOOTP,
48  * FILEIO_[XYZ]MODEM,
49  * FILEIO_HTTP,
50  * FILEIO_FTP,
51  */
52 };
53
54 enum fileio_access
55 {
56         FILEIO_READ,            /* open for reading, position at beginning */
57         FILEIO_WRITE,           /* open for writing, position at beginning */
58         FILEIO_READWRITE,       /* open for writing, position at beginning, allow reading */
59         FILEIO_APPEND,          /* open for writing, position at end */
60         FILEIO_APPENDREAD,      /* open for writing, position at end, allow reading */
61 };
62
63 typedef struct fileio_s
64 {
65         char *url;
66         char error_str[FILEIO_MAX_ERROR_STRING];
67         long long size;
68         enum fileio_type type;
69         enum fileio_location location;
70         enum fileio_access access;
71         void *location_private;
72 } fileio_t;
73
74 typedef struct fileio_local_s
75 {
76         FILE *file;
77         struct stat file_stat;
78 } fileio_local_t;
79
80 extern int fileio_write(fileio_t *fileio, u32 size, u8 *buffer, u32 *size_written);
81 extern int fileio_read(fileio_t *fileio, u32 size, u8 *buffer, u32 *size_read);
82 extern int fileio_seek(fileio_t *fileio, u32 position);
83 extern int fileio_close(fileio_t *fileio);
84 extern int fileio_open(fileio_t *fileio, char *url, enum fileio_access access, enum fileio_type type);
85 extern int fileio_read_u32(fileio_t *fileio, u32 *data);
86 extern int fileio_write_u32(fileio_t *fileio, u32 data);
87         
88 #define ERROR_FILEIO_LOCATION_UNKNOWN   (-1200)
89 #define ERROR_FILEIO_NOT_FOUND                  (-1201)
90 #define ERROR_FILEIO_OPERATION_FAILED           (-1202)
91 #define ERROR_FILEIO_ACCESS_NOT_SUPPORTED       (-1203)
92 #define ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN      (-1204)
93 #define ERROR_FILEIO_OPERATION_NOT_SUPPORTED    (-1205)
94
95 #endif /* FILEIO_H */