Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /branches/MS-Windows/src/files.h
Parent Directory
|
Revision Log
Revision 1410 -
(hide annotations)
(download)
(as text)
Fri Jun 21 15:48:19 2013 UTC (11 years, 8 months ago) by amb
Original Path: trunk/src/files.h
File MIME type: text/x-chdr
File size: 5727 byte(s)
Fri Jun 21 15:48:19 2013 UTC (11 years, 8 months ago) by amb
Original Path: trunk/src/files.h
File MIME type: text/x-chdr
File size: 5727 byte(s)
Rename the functions for unbuffered file access to make this clear.
1 | amb | 450 | /*************************************** |
2 | Header file for file function prototypes | ||
3 | |||
4 | Part of the Routino routing software. | ||
5 | ******************/ /****************** | ||
6 | amb | 1300 | This file Copyright 2008-2013 Andrew M. Bishop |
7 | amb | 450 | |
8 | This program is free software: you can redistribute it and/or modify | ||
9 | it under the terms of the GNU Affero General Public License as published by | ||
10 | the Free Software Foundation, either version 3 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU Affero General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Affero General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | ***************************************/ | ||
21 | |||
22 | |||
23 | #ifndef FILES_H | ||
24 | #define FILES_H /*+ To stop multiple inclusions. +*/ | ||
25 | |||
26 | amb | 888 | /* If your system does not have the pread() and pwrite() system calls then you |
27 | * will need to change this line to the value 0 so that seek() and | ||
28 | * read()/write() are used instead of pread()/pwrite(). */ | ||
29 | #define HAVE_PREAD_PWRITE 1 | ||
30 | |||
31 | |||
32 | amb | 450 | #include <unistd.h> |
33 | #include <sys/types.h> | ||
34 | |||
35 | amb | 1166 | #include "logging.h" |
36 | amb | 450 | |
37 | amb | 1166 | |
38 | amb | 680 | /* Functions in files.c */ |
39 | amb | 450 | |
40 | char *FileName(const char *dirname,const char *prefix, const char *name); | ||
41 | |||
42 | void *MapFile(const char *filename); | ||
43 | amb | 507 | void *MapFileWriteable(const char *filename); |
44 | amb | 1399 | |
45 | amb | 1122 | void *UnmapFile(const void *address); |
46 | amb | 450 | |
47 | amb | 1410 | int OpenFileUnbufferedNew(const char *filename); |
48 | int OpenFileUnbufferedAppend(const char *filename); | ||
49 | amb | 1399 | |
50 | amb | 1401 | int OpenFileBufferedNew(const char *filename); |
51 | int OpenFileBufferedAppend(const char *filename); | ||
52 | |||
53 | amb | 1410 | int ReOpenFileUnbuffered(const char *filename); |
54 | int ReOpenFileUnbufferedWriteable(const char *filename); | ||
55 | amb | 450 | |
56 | amb | 1404 | int ReOpenFileBuffered(const char *filename); |
57 | |||
58 | amb | 1401 | int WriteFileBuffered(int fd,const void *address,size_t length); |
59 | int ReadFileBuffered(int fd,void *address,size_t length); | ||
60 | |||
61 | amb | 1410 | int SeekFileUnbuffered(int fd,off_t position); |
62 | amb | 1407 | |
63 | int SeekFileBuffered(int fd,off_t position); | ||
64 | amb | 1406 | int SkipFileBuffered(int fd,off_t skip); |
65 | amb | 1404 | |
66 | amb | 1410 | int CloseFileUnbuffered(int fd); |
67 | amb | 1401 | int CloseFileBuffered(int fd); |
68 | amb | 1399 | |
69 | off_t SizeFile(const char *filename); | ||
70 | int ExistsFile(const char *filename); | ||
71 | |||
72 | int DeleteFile(const char *filename); | ||
73 | |||
74 | int RenameFile(const char *oldfilename,const char *newfilename); | ||
75 | |||
76 | /* Functions in files.h */ | ||
77 | |||
78 | amb | 1410 | static inline int WriteFileUnbuffered(int fd,const void *address,size_t length); |
79 | static inline int ReadFileUnbuffered(int fd,void *address,size_t length); | ||
80 | amb | 450 | |
81 | amb | 1410 | static inline int SeekWriteFileUnbuffered(int fd,const void *address,size_t length,off_t position); |
82 | static inline int SeekReadFileUnbuffered(int fd,void *address,size_t length,off_t position); | ||
83 | amb | 887 | |
84 | amb | 450 | |
85 | /* Inline the frequently called functions */ | ||
86 | |||
87 | /*++++++++++++++++++++++++++++++++++++++ | ||
88 | amb | 680 | Write data to a file descriptor. |
89 | amb | 450 | |
90 | amb | 1410 | int WriteFileUnbuffered Returns 0 if OK or something else in case of an error. |
91 | amb | 450 | |
92 | int fd The file descriptor to write to. | ||
93 | |||
94 | amb | 680 | const void *address The address of the data to be written. |
95 | amb | 450 | |
96 | size_t length The length of data to write. | ||
97 | ++++++++++++++++++++++++++++++++++++++*/ | ||
98 | |||
99 | amb | 1410 | static inline int WriteFileUnbuffered(int fd,const void *address,size_t length) |
100 | amb | 450 | { |
101 | amb | 1166 | logassert(fd!=-1,"File descriptor is in error - report a bug"); |
102 | amb | 612 | |
103 | amb | 450 | /* Write the data */ |
104 | |||
105 | amb | 1300 | if(write(fd,address,length)!=(ssize_t)length) |
106 | amb | 450 | return(-1); |
107 | |||
108 | return(0); | ||
109 | } | ||
110 | |||
111 | |||
112 | /*++++++++++++++++++++++++++++++++++++++ | ||
113 | amb | 680 | Read data from a file descriptor. |
114 | amb | 450 | |
115 | amb | 1410 | int ReadFileUnbuffered Returns 0 if OK or something else in case of an error. |
116 | amb | 450 | |
117 | int fd The file descriptor to read from. | ||
118 | |||
119 | amb | 680 | void *address The address the data is to be read into. |
120 | amb | 450 | |
121 | size_t length The length of data to read. | ||
122 | ++++++++++++++++++++++++++++++++++++++*/ | ||
123 | |||
124 | amb | 1410 | static inline int ReadFileUnbuffered(int fd,void *address,size_t length) |
125 | amb | 450 | { |
126 | amb | 1166 | logassert(fd!=-1,"File descriptor is in error - report a bug"); |
127 | amb | 450 | |
128 | amb | 680 | /* Read the data */ |
129 | |||
130 | amb | 1300 | if(read(fd,address,length)!=(ssize_t)length) |
131 | amb | 450 | return(-1); |
132 | |||
133 | return(0); | ||
134 | } | ||
135 | |||
136 | |||
137 | /*++++++++++++++++++++++++++++++++++++++ | ||
138 | amb | 887 | Write data to a file descriptor after seeking to a position. |
139 | |||
140 | amb | 1410 | int SeekWriteFileUnbuffered Returns 0 if OK or something else in case of an error. |
141 | amb | 887 | |
142 | int fd The file descriptor to write to. | ||
143 | |||
144 | const void *address The address of the data to be written. | ||
145 | |||
146 | size_t length The length of data to write. | ||
147 | |||
148 | off_t position The position to seek to. | ||
149 | ++++++++++++++++++++++++++++++++++++++*/ | ||
150 | |||
151 | amb | 1410 | static inline int SeekWriteFileUnbuffered(int fd,const void *address,size_t length,off_t position) |
152 | amb | 887 | { |
153 | amb | 1166 | logassert(fd!=-1,"File descriptor is in error - report a bug"); |
154 | amb | 887 | |
155 | amb | 888 | /* Seek and write the data */ |
156 | amb | 887 | |
157 | amb | 888 | #if HAVE_PREAD_PWRITE |
158 | |||
159 | amb | 1300 | if(pwrite(fd,address,length,position)!=(ssize_t)length) |
160 | amb | 887 | return(-1); |
161 | |||
162 | amb | 888 | #else |
163 | |||
164 | if(lseek(fd,position,SEEK_SET)!=position) | ||
165 | return(-1); | ||
166 | |||
167 | if(write(fd,address,length)!=length) | ||
168 | return(-1); | ||
169 | |||
170 | #endif | ||
171 | |||
172 | amb | 887 | return(0); |
173 | } | ||
174 | |||
175 | |||
176 | /*++++++++++++++++++++++++++++++++++++++ | ||
177 | Read data from a file descriptor after seeking to a position. | ||
178 | |||
179 | amb | 1410 | int SeekReadFileUnbuffered Returns 0 if OK or something else in case of an error. |
180 | amb | 887 | |
181 | int fd The file descriptor to read from. | ||
182 | |||
183 | void *address The address the data is to be read into. | ||
184 | |||
185 | size_t length The length of data to read. | ||
186 | |||
187 | off_t position The position to seek to. | ||
188 | ++++++++++++++++++++++++++++++++++++++*/ | ||
189 | |||
190 | amb | 1410 | static inline int SeekReadFileUnbuffered(int fd,void *address,size_t length,off_t position) |
191 | amb | 887 | { |
192 | amb | 1166 | logassert(fd!=-1,"File descriptor is in error - report a bug"); |
193 | amb | 887 | |
194 | amb | 888 | /* Seek and read the data */ |
195 | amb | 887 | |
196 | amb | 888 | #if HAVE_PREAD_PWRITE |
197 | |||
198 | amb | 1300 | if(pread(fd,address,length,position)!=(ssize_t)length) |
199 | amb | 887 | return(-1); |
200 | |||
201 | amb | 888 | #else |
202 | |||
203 | if(lseek(fd,position,SEEK_SET)!=position) | ||
204 | return(-1); | ||
205 | |||
206 | if(read(fd,address,length)!=length) | ||
207 | return(-1); | ||
208 | |||
209 | #endif | ||
210 | |||
211 | amb | 887 | return(0); |
212 | } | ||
213 | |||
214 | |||
215 | amb | 450 | #endif /* FILES_H */ |
Properties
Name | Value |
---|---|
cvs:description | A new header file for files.c functions and includes some inline functions. |